Reword the copyright notices to match what's suggested in GPLv3.
[automake/plouj.git] / automake.in
blobfbc97b025e1e3afba339dec6dff1187448c64c95
1 #!@PERL@ -w
2 # -*- perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
6     if 0;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
10 # 2003, 2004, 2005, 2006, 2007  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 3, or (at your option)
15 # any later version.
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, see <http://www.gnu.org/licenses/>.
25 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
26 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
27 # Alexandre Duret-Lutz <adl@gnu.org>.
29 package Language;
31 BEGIN
33   my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
34   unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
36   # Override SHELL.  This is required on DJGPP so that system() uses
37   # bash, not COMMAND.COM which doesn't quote arguments properly.
38   # Other systems aren't expected to use $SHELL when Automake
39   # runs, but it should be safe to drop the `if DJGPP' guard if
40   # it turns up other systems need the same thing.  After all,
41   # if SHELL is used, ./configure's SHELL is always better than
42   # the user's SHELL (which may be something like tcsh).
43   $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJGPP'};
46 use Automake::Struct;
47 struct (# Short name of the language (c, f77...).
48         'name' => "\$",
49         # Nice name of the language (C, Fortran 77...).
50         'Name' => "\$",
52         # List of configure variables which must be defined.
53         'config_vars' => '@',
55         'ansi'    => "\$",
56         # `pure' is `1' or `'.  A `pure' language is one where, if
57         # all the files in a directory are of that language, then we
58         # do not require the C compiler or any code to call it.
59         'pure'   => "\$",
61         'autodep' => "\$",
63         # Name of the compiling variable (COMPILE).
64         'compiler'  => "\$",
65         # Content of the compiling variable.
66         'compile'  => "\$",
67         # Flag to require compilation without linking (-c).
68         'compile_flag' => "\$",
69         'extensions' => '@',
70         # A subroutine to compute a list of possible extensions of
71         # the product given the input extensions.
72         # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
73         'output_extensions' => "\$",
74         # A list of flag variables used in 'compile'.
75         # (defaults to [])
76         'flags' => "@",
78         # Any tag to pass to libtool while compiling.
79         'libtool_tag' => "\$",
81         # The file to use when generating rules for this language.
82         # The default is 'depend2'.
83         'rule_file' => "\$",
85         # Name of the linking variable (LINK).
86         'linker' => "\$",
87         # Content of the linking variable.
88         'link' => "\$",
90         # Name of the linker variable (LD).
91         'lder' => "\$",
92         # Content of the linker variable ($(CC)).
93         'ld' => "\$",
95         # Flag to specify the output file (-o).
96         'output_flag' => "\$",
97         '_finish' => "\$",
99         # This is a subroutine which is called whenever we finally
100         # determine the context in which a source file will be
101         # compiled.
102         '_target_hook' => "\$",
104         # If TRUE, nodist_ sources will be compiled using specific rules
105         # (i.e. not inference rules).  The default is FALSE.
106         'nodist_specific' => "\$");
109 sub finish ($)
111   my ($self) = @_;
112   if (defined $self->_finish)
113     {
114       &{$self->_finish} ();
115     }
118 sub target_hook ($$$$%)
120     my ($self) = @_;
121     if (defined $self->_target_hook)
122     {
123         &{$self->_target_hook} (@_);
124     }
127 package Automake;
129 use strict;
130 use Automake::Config;
131 use Automake::General;
132 use Automake::XFile;
133 use Automake::Channels;
134 use Automake::ChannelDefs;
135 use Automake::Configure_ac;
136 use Automake::FileUtils;
137 use Automake::Location;
138 use Automake::Condition qw/TRUE FALSE/;
139 use Automake::DisjConditions;
140 use Automake::Options;
141 use Automake::Version;
142 use Automake::Variable;
143 use Automake::VarDef;
144 use Automake::Rule;
145 use Automake::RuleDef;
146 use Automake::Wrap 'makefile_wrap';
147 use File::Basename;
148 use File::Spec;
149 use Carp;
151 ## ----------- ##
152 ## Constants.  ##
153 ## ----------- ##
155 # Some regular expressions.  One reason to put them here is that it
156 # makes indentation work better in Emacs.
158 # Writing singled-quoted-$-terminated regexes is a pain because
159 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
160 # by a closing quote.  Letting perl-mode think the quote is not closed
161 # leads to all sort of misindentations.  On the other hand, defining
162 # regexes as double-quoted strings is far less readable.  So usually
163 # we will write:
165 #  $REGEX = '^regex_value' . "\$";
167 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
168 my $WHITE_PATTERN = '^\s*' . "\$";
169 my $COMMENT_PATTERN = '^#';
170 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
171 # A rule has three parts: a list of targets, a list of dependencies,
172 # and optionally actions.
173 my $RULE_PATTERN =
174   "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
176 # Only recognize leading spaces, not leading tabs.  If we recognize
177 # leading tabs here then we need to make the reader smarter, because
178 # otherwise it will think rules like `foo=bar; \' are errors.
179 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
180 # This pattern recognizes a Gnits version id and sets $1 if the
181 # release is an alpha release.  We also allow a suffix which can be
182 # used to extend the version number with a "fork" identifier.
183 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
185 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
186 my $ELSE_PATTERN =
187   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
188 my $ENDIF_PATTERN =
189   '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
190 my $PATH_PATTERN = '(\w|[+/.-])+';
191 # This will pass through anything not of the prescribed form.
192 my $INCLUDE_PATTERN = ('^include\s+'
193                        . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
194                        . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
195                        . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
197 # Match `-d' as a command-line argument in a string.
198 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
199 # Directories installed during 'install-exec' phase.
200 my $EXEC_DIR_PATTERN =
201   '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
203 # Values for AC_CANONICAL_*
204 use constant AC_CANONICAL_BUILD  => 1;
205 use constant AC_CANONICAL_HOST   => 2;
206 use constant AC_CANONICAL_TARGET => 3;
208 # Values indicating when something should be cleaned.
209 use constant MOSTLY_CLEAN     => 0;
210 use constant CLEAN            => 1;
211 use constant DIST_CLEAN       => 2;
212 use constant MAINTAINER_CLEAN => 3;
214 # Libtool files.
215 my @libtool_files = qw(ltmain.sh config.guess config.sub);
216 # ltconfig appears here for compatibility with old versions of libtool.
217 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
219 # Commonly found files we look for and automatically include in
220 # DISTFILES.
221 my @common_files =
222     (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
223         COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
224         ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
225         depcomp elisp-comp install-sh libversion.in mdate-sh missing
226         mkinstalldirs py-compile texinfo.tex ylwrap),
227      @libtool_files, @libtool_sometimes);
229 # Commonly used files we auto-include, but only sometimes.  This list
230 # is used for the --help output only.
231 my @common_sometimes =
232   qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
233      configure.ac configure.in stamp-vti);
235 # Standard directories from the GNU Coding Standards, and additional
236 # pkg* directories from Automake.  Stored in a hash for fast member check.
237 my %standard_prefix =
238     map { $_ => 1 } (qw(bin data dataroot dvi exec html include info
239                         lib libexec lisp localstate man man1 man2 man3
240                         man4 man5 man6 man7 man8 man9 oldinclude pdf
241                         pkgdatadir pkgincludedir pkglibdir pkglibexecdir
242                         ps sbin sharedstate sysconf));
244 # Copyright on generated Makefile.ins.
245 my $gen_copyright = "\
246 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
247 # 2003, 2004, 2005, 2006, 2007  Free Software Foundation, Inc.
248 # This Makefile.in is free software; the Free Software Foundation
249 # gives unlimited permission to copy and/or distribute it,
250 # with or without modifications, as long as this notice is preserved.
252 # This program is distributed in the hope that it will be useful,
253 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
254 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
255 # PARTICULAR PURPOSE.
258 # These constants are returned by the lang_*_rewrite functions.
259 # LANG_SUBDIR means that the resulting object file should be in a
260 # subdir if the source file is.  In this case the file name cannot
261 # have `..' components.
262 use constant LANG_IGNORE  => 0;
263 use constant LANG_PROCESS => 1;
264 use constant LANG_SUBDIR  => 2;
266 # These are used when keeping track of whether an object can be built
267 # by two different paths.
268 use constant COMPILE_LIBTOOL  => 1;
269 use constant COMPILE_ORDINARY => 2;
271 # We can't always associate a location to a variable or a rule,
272 # when it's defined by Automake.  We use INTERNAL in this case.
273 use constant INTERNAL => new Automake::Location;
276 ## ---------------------------------- ##
277 ## Variables related to the options.  ##
278 ## ---------------------------------- ##
280 # TRUE if we should always generate Makefile.in.
281 my $force_generation = 1;
283 # From the Perl manual.
284 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
286 # TRUE if missing standard files should be installed.
287 my $add_missing = 0;
289 # TRUE if we should copy missing files; otherwise symlink if possible.
290 my $copy_missing = 0;
292 # TRUE if we should always update files that we know about.
293 my $force_missing = 0;
296 ## ---------------------------------------- ##
297 ## Variables filled during files scanning.  ##
298 ## ---------------------------------------- ##
300 # Name of the configure.ac file.
301 my $configure_ac;
303 # Files found by scanning configure.ac for LIBOBJS.
304 my %libsources = ();
306 # Names used in AC_CONFIG_HEADER call.
307 my @config_headers = ();
309 # Names used in AC_CONFIG_LINKS call.
310 my @config_links = ();
312 # Directory where output files go.  Actually, output files are
313 # relative to this directory.
314 my $output_directory;
316 # List of Makefile.am's to process, and their corresponding outputs.
317 my @input_files = ();
318 my %output_files = ();
320 # Complete list of Makefile.am's that exist.
321 my @configure_input_files = ();
323 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
324 # and their outputs.
325 my @other_input_files = ();
326 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
327 # The keys are the files created by these macros.
328 my %ac_config_files_location = ();
330 # Directory to search for configure-required files.  This
331 # will be computed by &locate_aux_dir and can be set using
332 # AC_CONFIG_AUX_DIR in configure.ac.
333 # $CONFIG_AUX_DIR is the `raw' directory, valid only in the source-tree.
334 my $config_aux_dir = '';
335 my $config_aux_dir_set_in_configure_ac = 0;
336 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
337 # in Makefiles.
338 my $am_config_aux_dir = '';
340 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
341 # in configure.ac.
342 my $config_libobj_dir = '';
344 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
345 my $seen_gettext = 0;
346 # Whether AM_GNU_GETTEXT([external]) is used.
347 my $seen_gettext_external = 0;
348 # Where AM_GNU_GETTEXT appears.
349 my $ac_gettext_location;
350 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
351 my $seen_gettext_intl = 0;
353 # Lists of tags supported by Libtool.
354 my %libtool_tags = ();
355 # 1 if Libtool uses LT_SUPPORTED_TAG.  If it does, then it also
356 # uses AC_REQUIRE_AUX_FILE.
357 my $libtool_new_api = 0;
359 # Most important AC_CANONICAL_* macro seen so far.
360 my $seen_canonical = 0;
361 # Location of that macro.
362 my $canonical_location;
364 # Where AM_MAINTAINER_MODE appears.
365 my $seen_maint_mode;
367 # Actual version we've seen.
368 my $package_version = '';
370 # Where version is defined.
371 my $package_version_location;
373 # TRUE if we've seen AM_ENABLE_MULTILIB.
374 my $seen_multilib = 0;
376 # TRUE if we've seen AM_PROG_CC_C_O
377 my $seen_cc_c_o = 0;
379 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
380 my %required_aux_file = ();
382 # Where AM_INIT_AUTOMAKE is called;
383 my $seen_init_automake = 0;
385 # TRUE if we've seen AM_AUTOMAKE_VERSION.
386 my $seen_automake_version = 0;
388 # Hash table of discovered configure substitutions.  Keys are names,
389 # values are `FILE:LINE' strings which are used by error message
390 # generation.
391 my %configure_vars = ();
393 # Ignored configure substitutions (i.e., variables not to be output in
394 # Makefile.in)
395 my %ignored_configure_vars = ();
397 # Files included by $configure_ac.
398 my @configure_deps = ();
400 # Greatest timestamp of configure's dependencies.
401 my $configure_deps_greatest_timestamp = 0;
403 # Hash table of AM_CONDITIONAL variables seen in configure.
404 my %configure_cond = ();
406 # This maps extensions onto language names.
407 my %extension_map = ();
409 # List of the DIST_COMMON files we discovered while reading
410 # configure.in
411 my $configure_dist_common = '';
413 # This maps languages names onto objects.
414 my %languages = ();
415 # Maps each linker variable onto a language object.
416 my %link_languages = ();
418 # maps extensions to needed source flags.
419 my %sourceflags = ();
421 # List of targets we must always output.
422 # FIXME: Complete, and remove falsely required targets.
423 my %required_targets =
424   (
425    'all'          => 1,
426    'dvi'          => 1,
427    'pdf'          => 1,
428    'ps'           => 1,
429    'info'         => 1,
430    'install-info' => 1,
431    'install'      => 1,
432    'install-data' => 1,
433    'install-exec' => 1,
434    'uninstall'    => 1,
436    # FIXME: Not required, temporary hacks.
437    # Well, actually they are sort of required: the -recursive
438    # targets will run them anyway...
439    'dvi-am'          => 1,
440    'pdf-am'          => 1,
441    'ps-am'           => 1,
442    'info-am'         => 1,
443    'install-data-am' => 1,
444    'install-exec-am' => 1,
445    'installcheck-am' => 1,
446    'uninstall-am' => 1,
448    'install-man' => 1,
449   );
451 # Set to 1 if this run will create the Makefile.in that distribute
452 # the files in config_aux_dir.
453 my $automake_will_process_aux_dir = 0;
455 # The name of the Makefile currently being processed.
456 my $am_file = 'BUG';
459 ################################################################
461 ## ------------------------------------------ ##
462 ## Variables reset by &initialize_per_input.  ##
463 ## ------------------------------------------ ##
465 # Basename and relative dir of the input file.
466 my $am_file_name;
467 my $am_relative_dir;
469 # Same but wrt Makefile.in.
470 my $in_file_name;
471 my $relative_dir;
473 # Relative path to the top directory.
474 my $topsrcdir;
476 # Greatest timestamp of the output's dependencies (excluding
477 # configure's dependencies).
478 my $output_deps_greatest_timestamp;
480 # These two variables are used when generating each Makefile.in.
481 # They hold the Makefile.in until it is ready to be printed.
482 my $output_rules;
483 my $output_vars;
484 my $output_trailer;
485 my $output_all;
486 my $output_header;
488 # This is the conditional stack, updated on if/else/endif, and
489 # used to build Condition objects.
490 my @cond_stack;
492 # This holds the set of included files.
493 my @include_stack;
495 # List of dependencies for the obvious targets.
496 my @all;
497 my @check;
498 my @check_tests;
500 # Keys in this hash table are files to delete.  The associated
501 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
502 my %clean_files;
504 # Keys in this hash table are object files or other files in
505 # subdirectories which need to be removed.  This only holds files
506 # which are created by compilations.  The value in the hash indicates
507 # when the file should be removed.
508 my %compile_clean_files;
510 # Keys in this hash table are directories where we expect to build a
511 # libtool object.  We use this information to decide what directories
512 # to delete.
513 my %libtool_clean_directories;
515 # Value of `$(SOURCES)', used by tags.am.
516 my @sources;
517 # Sources which go in the distribution.
518 my @dist_sources;
520 # This hash maps object file names onto their corresponding source
521 # file names.  This is used to ensure that each object is created
522 # by a single source file.
523 my %object_map;
525 # This hash maps object file names onto an integer value representing
526 # whether this object has been built via ordinary compilation or
527 # libtool compilation (the COMPILE_* constants).
528 my %object_compilation_map;
531 # This keeps track of the directories for which we've already
532 # created dirstamp code.  Keys are directories, values are stamp files.
533 # Several keys can share the same stamp files if they are equivalent
534 # (as are `.//foo' and `foo').
535 my %directory_map;
537 # All .P files.
538 my %dep_files;
540 # This is a list of all targets to run during "make dist".
541 my @dist_targets;
543 # Keep track of all programs declared in this Makefile, without
544 # $(EXEEXT).  @substitution@ are not listed.
545 my %known_programs;
547 # Keys in this hash are the basenames of files which must depend on
548 # ansi2knr.  Values are either the empty string, or the directory in
549 # which the ANSI source file appears; the directory must have a
550 # trailing `/'.
551 my %de_ansi_files;
553 # This is the name of the redirect `all' target to use.
554 my $all_target;
556 # This keeps track of which extensions we've seen (that we care
557 # about).
558 my %extension_seen;
560 # This is random scratch space for the language finish functions.
561 # Don't randomly overwrite it; examine other uses of keys first.
562 my %language_scratch;
564 # We keep track of which objects need special (per-executable)
565 # handling on a per-language basis.
566 my %lang_specific_files;
568 # This is set when `handle_dist' has finished.  Once this happens,
569 # we should no longer push on dist_common.
570 my $handle_dist_run;
572 # Used to store a set of linkers needed to generate the sources currently
573 # under consideration.
574 my %linkers_used;
576 # True if we need `LINK' defined.  This is a hack.
577 my $need_link;
579 # Was get_object_extension run?
580 # FIXME: This is a hack. a better switch should be found.
581 my $get_object_extension_was_run;
583 # Record each file processed by make_paragraphs.
584 my %transformed_files;
586 # Cache each file processed by make_paragraphs.
587 # (This is different from %transformed_files because
588 # %transformed_files is reset for each file while %am_file_cache
589 # it global to the run.)
590 my %am_file_cache;
592 ################################################################
594 # var_SUFFIXES_trigger ($TYPE, $VALUE)
595 # ------------------------------------
596 # This is called by Automake::Variable::define() when SUFFIXES
597 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
598 # The work here needs to be performed as a side-effect of the
599 # macro_define() call because SUFFIXES definitions impact
600 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
601 # the input am file.
602 sub var_SUFFIXES_trigger ($$)
604     my ($type, $value) = @_;
605     accept_extensions (split (' ', $value));
607 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
609 ################################################################
611 ## --------------------------------- ##
612 ## Forward subroutine declarations.  ##
613 ## --------------------------------- ##
614 sub register_language (%);
615 sub file_contents_internal ($$$%);
616 sub define_files_variable ($\@$$);
619 # &initialize_per_input ()
620 # ------------------------
621 # (Re)-Initialize per-Makefile.am variables.
622 sub initialize_per_input ()
624     reset_local_duplicates ();
626     $am_file_name = '';
627     $am_relative_dir = '';
629     $in_file_name = '';
630     $relative_dir = '';
632     $output_deps_greatest_timestamp = 0;
634     $output_rules = '';
635     $output_vars = '';
636     $output_trailer = '';
637     $output_all = '';
638     $output_header = '';
640     Automake::Options::reset;
641     Automake::Variable::reset;
642     Automake::Rule::reset;
644     @cond_stack = ();
646     @include_stack = ();
648     @all = ();
649     @check = ();
650     @check_tests = ();
652     %clean_files = ();
654     @sources = ();
655     @dist_sources = ();
657     %object_map = ();
658     %object_compilation_map = ();
660     %directory_map = ();
662     %dep_files = ();
664     @dist_targets = ();
666     %known_programs = ();
668     %de_ansi_files = ();
670     $all_target = '';
672     %extension_seen = ();
674     %language_scratch = ();
676     %lang_specific_files = ();
678     $handle_dist_run = 0;
680     $need_link = 0;
682     $get_object_extension_was_run = 0;
684     %compile_clean_files = ();
686     # We always include `.'.  This isn't strictly correct.
687     %libtool_clean_directories = ('.' => 1);
689     %transformed_files = ();
693 ################################################################
695 # Initialize our list of languages that are internally supported.
697 # C.
698 register_language ('name' => 'c',
699                    'Name' => 'C',
700                    'config_vars' => ['CC'],
701                    'ansi' => 1,
702                    'autodep' => '',
703                    'flags' => ['CFLAGS', 'CPPFLAGS'],
704                    'compiler' => 'COMPILE',
705                    'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
706                    'lder' => 'CCLD',
707                    'ld' => '$(CC)',
708                    'linker' => 'LINK',
709                    'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
710                    'compile_flag' => '-c',
711                    'libtool_tag' => 'CC',
712                    'extensions' => ['.c'],
713                    '_finish' => \&lang_c_finish);
715 # C++.
716 register_language ('name' => 'cxx',
717                    'Name' => 'C++',
718                    'config_vars' => ['CXX'],
719                    'linker' => 'CXXLINK',
720                    'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
721                    'autodep' => 'CXX',
722                    'flags' => ['CXXFLAGS', 'CPPFLAGS'],
723                    'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
724                    'compiler' => 'CXXCOMPILE',
725                    'compile_flag' => '-c',
726                    'output_flag' => '-o',
727                    'libtool_tag' => 'CXX',
728                    'lder' => 'CXXLD',
729                    'ld' => '$(CXX)',
730                    'pure' => 1,
731                    'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
733 # Objective C.
734 register_language ('name' => 'objc',
735                    'Name' => 'Objective C',
736                    'config_vars' => ['OBJC'],
737                    'linker' => 'OBJCLINK',
738                    'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
739                    'autodep' => 'OBJC',
740                    'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
741                    'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
742                    'compiler' => 'OBJCCOMPILE',
743                    'compile_flag' => '-c',
744                    'output_flag' => '-o',
745                    'lder' => 'OBJCLD',
746                    'ld' => '$(OBJC)',
747                    'pure' => 1,
748                    'extensions' => ['.m']);
750 # Unified Parallel C.
751 register_language ('name' => 'upc',
752                    'Name' => 'Unified Parallel C',
753                    'config_vars' => ['UPC'],
754                    'linker' => 'UPCLINK',
755                    'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
756                    'autodep' => 'UPC',
757                    'flags' => ['UPCFLAGS', 'CPPFLAGS'],
758                    'compile' => '$(UPC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_UPCFLAGS) $(UPCFLAGS)',
759                    'compiler' => 'UPCCOMPILE',
760                    'compile_flag' => '-c',
761                    'output_flag' => '-o',
762                    'lder' => 'UPCLD',
763                    'ld' => '$(UPC)',
764                    'pure' => 1,
765                    'extensions' => ['.upc']);
767 # Headers.
768 register_language ('name' => 'header',
769                    'Name' => 'Header',
770                    'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
771                                     '.hpp', '.inc'],
772                    # No output.
773                    'output_extensions' => sub { return () },
774                    # Nothing to do.
775                    '_finish' => sub { });
777 # Yacc (C & C++).
778 register_language ('name' => 'yacc',
779                    'Name' => 'Yacc',
780                    'config_vars' => ['YACC'],
781                    'flags' => ['YFLAGS'],
782                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
783                    'compiler' => 'YACCCOMPILE',
784                    'extensions' => ['.y'],
785                    'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
786                                                 return ($ext,) },
787                    'rule_file' => 'yacc',
788                    '_finish' => \&lang_yacc_finish,
789                    '_target_hook' => \&lang_yacc_target_hook,
790                    'nodist_specific' => 1);
791 register_language ('name' => 'yaccxx',
792                    'Name' => 'Yacc (C++)',
793                    'config_vars' => ['YACC'],
794                    'rule_file' => 'yacc',
795                    'flags' => ['YFLAGS'],
796                    'compiler' => 'YACCCOMPILE',
797                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
798                    'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
799                    'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
800                                                 return ($ext,) },
801                    '_finish' => \&lang_yacc_finish,
802                    '_target_hook' => \&lang_yacc_target_hook,
803                    'nodist_specific' => 1);
805 # Lex (C & C++).
806 register_language ('name' => 'lex',
807                    'Name' => 'Lex',
808                    'config_vars' => ['LEX'],
809                    'rule_file' => 'lex',
810                    'flags' => ['LFLAGS'],
811                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
812                    'compiler' => 'LEXCOMPILE',
813                    'extensions' => ['.l'],
814                    'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
815                                                 return ($ext,) },
816                    '_finish' => \&lang_lex_finish,
817                    '_target_hook' => \&lang_lex_target_hook,
818                    'nodist_specific' => 1);
819 register_language ('name' => 'lexxx',
820                    'Name' => 'Lex (C++)',
821                    'config_vars' => ['LEX'],
822                    'rule_file' => 'lex',
823                    'flags' => ['LFLAGS'],
824                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
825                    'compiler' => 'LEXCOMPILE',
826                    'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
827                    'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
828                                                 return ($ext,) },
829                    '_finish' => \&lang_lex_finish,
830                    '_target_hook' => \&lang_lex_target_hook,
831                    'nodist_specific' => 1);
833 # Assembler.
834 register_language ('name' => 'asm',
835                    'Name' => 'Assembler',
836                    'config_vars' => ['CCAS', 'CCASFLAGS'],
838                    'flags' => ['CCASFLAGS'],
839                    # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
840                    # or anything else required.  They can also set CCAS.
841                    # Or simply use Preprocessed Assembler.
842                    'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
843                    'compiler' => 'CCASCOMPILE',
844                    'compile_flag' => '-c',
845                    'output_flag' => '-o',
846                    'extensions' => ['.s'],
848                    # With assembly we still use the C linker.
849                    '_finish' => \&lang_c_finish);
851 # Preprocessed Assembler.
852 register_language ('name' => 'cppasm',
853                    'Name' => 'Preprocessed Assembler',
854                    'config_vars' => ['CCAS', 'CCASFLAGS'],
856                    'autodep' => 'CCAS',
857                    'flags' => ['CCASFLAGS', 'CPPFLAGS'],
858                    'compile' => '$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)',
859                    'compiler' => 'CPPASCOMPILE',
860                    'compile_flag' => '-c',
861                    'output_flag' => '-o',
862                    'extensions' => ['.S', '.sx'],
864                    # With assembly we still use the C linker.
865                    '_finish' => \&lang_c_finish);
867 # Fortran 77
868 register_language ('name' => 'f77',
869                    'Name' => 'Fortran 77',
870                    'config_vars' => ['F77'],
871                    'linker' => 'F77LINK',
872                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
873                    'flags' => ['FFLAGS'],
874                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
875                    'compiler' => 'F77COMPILE',
876                    'compile_flag' => '-c',
877                    'output_flag' => '-o',
878                    'libtool_tag' => 'F77',
879                    'lder' => 'F77LD',
880                    'ld' => '$(F77)',
881                    'pure' => 1,
882                    'extensions' => ['.f', '.for']);
884 # Fortran
885 register_language ('name' => 'fc',
886                    'Name' => 'Fortran',
887                    'config_vars' => ['FC'],
888                    'linker' => 'FCLINK',
889                    'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
890                    'flags' => ['FCFLAGS'],
891                    'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
892                    'compiler' => 'FCCOMPILE',
893                    'compile_flag' => '-c',
894                    'output_flag' => '-o',
895                    'lder' => 'FCLD',
896                    'ld' => '$(FC)',
897                    'pure' => 1,
898                    'extensions' => ['.f90', '.f95']);
900 # Preprocessed Fortran
901 register_language ('name' => 'ppfc',
902                    'Name' => 'Preprocessed Fortran',
903                    'config_vars' => ['FC'],
904                    'linker' => 'FCLINK',
905                    'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
906                    'lder' => 'FCLD',
907                    'ld' => '$(FC)',
908                    'flags' => ['FCFLAGS', 'CPPFLAGS'],
909                    'compiler' => 'PPFCCOMPILE',
910                    'compile' => '$(FC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FCFLAGS) $(FCFLAGS)',
911                    'compile_flag' => '-c',
912                    'output_flag' => '-o',
913                    'libtool_tag' => 'FC',
914                    'pure' => 1,
915                    'extensions' => ['.F90','.F95']);
917 # Preprocessed Fortran 77
919 # The current support for preprocessing Fortran 77 just involves
920 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
921 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
922 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
923 # for `make' Version 3.76 Beta' (specifically, from info file
924 # `(make)Catalogue of Rules').
926 # A better approach would be to write an Autoconf test
927 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
928 # Fortran 77 compilers know how to do preprocessing.  The Autoconf
929 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
930 # preprocessing capabilities, and then fall back on cpp (if cpp were
931 # available).
932 register_language ('name' => 'ppf77',
933                    'Name' => 'Preprocessed Fortran 77',
934                    'config_vars' => ['F77'],
935                    'linker' => 'F77LINK',
936                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
937                    'lder' => 'F77LD',
938                    'ld' => '$(F77)',
939                    'flags' => ['FFLAGS', 'CPPFLAGS'],
940                    'compiler' => 'PPF77COMPILE',
941                    'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
942                    'compile_flag' => '-c',
943                    'output_flag' => '-o',
944                    'libtool_tag' => 'F77',
945                    'pure' => 1,
946                    'extensions' => ['.F']);
948 # Ratfor.
949 register_language ('name' => 'ratfor',
950                    'Name' => 'Ratfor',
951                    'config_vars' => ['F77'],
952                    'linker' => 'F77LINK',
953                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
954                    'lder' => 'F77LD',
955                    'ld' => '$(F77)',
956                    'flags' => ['RFLAGS', 'FFLAGS'],
957                    # FIXME also FFLAGS.
958                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
959                    'compiler' => 'RCOMPILE',
960                    'compile_flag' => '-c',
961                    'output_flag' => '-o',
962                    'libtool_tag' => 'F77',
963                    'pure' => 1,
964                    'extensions' => ['.r']);
966 # Java via gcj.
967 register_language ('name' => 'java',
968                    'Name' => 'Java',
969                    'config_vars' => ['GCJ'],
970                    'linker' => 'GCJLINK',
971                    'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
972                    'autodep' => 'GCJ',
973                    'flags' => ['GCJFLAGS'],
974                    'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
975                    'compiler' => 'GCJCOMPILE',
976                    'compile_flag' => '-c',
977                    'output_flag' => '-o',
978                    'libtool_tag' => 'GCJ',
979                    'lder' => 'GCJLD',
980                    'ld' => '$(GCJ)',
981                    'pure' => 1,
982                    'extensions' => ['.java', '.class', '.zip', '.jar']);
984 ################################################################
986 # Error reporting functions.
988 # err_am ($MESSAGE, [%OPTIONS])
989 # -----------------------------
990 # Uncategorized errors about the current Makefile.am.
991 sub err_am ($;%)
993   msg_am ('error', @_);
996 # err_ac ($MESSAGE, [%OPTIONS])
997 # -----------------------------
998 # Uncategorized errors about configure.ac.
999 sub err_ac ($;%)
1001   msg_ac ('error', @_);
1004 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1005 # ---------------------------------------
1006 # Messages about about the current Makefile.am.
1007 sub msg_am ($$;%)
1009   my ($channel, $msg, %opts) = @_;
1010   msg $channel, "${am_file}.am", $msg, %opts;
1013 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1014 # ---------------------------------------
1015 # Messages about about configure.ac.
1016 sub msg_ac ($$;%)
1018   my ($channel, $msg, %opts) = @_;
1019   msg $channel, $configure_ac, $msg, %opts;
1022 ################################################################
1024 # subst ($TEXT)
1025 # -------------
1026 # Return a configure-style substitution using the indicated text.
1027 # We do this to avoid having the substitutions directly in automake.in;
1028 # when we do that they are sometimes removed and this causes confusion
1029 # and bugs.
1030 sub subst ($)
1032     my ($text) = @_;
1033     return '@' . $text . '@';
1036 ################################################################
1039 # $BACKPATH
1040 # &backname ($REL-DIR)
1041 # --------------------
1042 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1043 # For instance `src/foo' => `../..'.
1044 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1045 sub backname ($)
1047     my ($file) = @_;
1048     my @res;
1049     foreach (split (/\//, $file))
1050     {
1051         next if $_ eq '.' || $_ eq '';
1052         if ($_ eq '..')
1053         {
1054             pop @res;
1055         }
1056         else
1057         {
1058             push (@res, '..');
1059         }
1060     }
1061     return join ('/', @res) || '.';
1064 ################################################################
1067 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
1068 sub handle_options
1070   my $var = var ('AUTOMAKE_OPTIONS');
1071   if ($var)
1072     {
1073       if ($var->has_conditional_contents)
1074         {
1075           msg_var ('unsupported', $var,
1076                    "`AUTOMAKE_OPTIONS' cannot have conditional contents");
1077         }
1078       foreach my $locvals ($var->value_as_list_recursive (cond_filter => TRUE,
1079                                                           location => 1))
1080         {
1081           my ($loc, $value) = @$locvals;
1082           return 1 if (process_option_list ($loc, $value))
1083         }
1084     }
1086   if ($strictness == GNITS)
1087     {
1088       set_option ('readme-alpha', INTERNAL);
1089       set_option ('std-options', INTERNAL);
1090       set_option ('check-news', INTERNAL);
1091     }
1093   return 0;
1096 # shadow_unconditionally ($varname, $where)
1097 # -----------------------------------------
1098 # Return a $(variable) that contains all possible values
1099 # $varname can take.
1100 # If the VAR wasn't defined conditionally, return $(VAR).
1101 # Otherwise we create a am__VAR_DIST variable which contains
1102 # all possible values, and return $(am__VAR_DIST).
1103 sub shadow_unconditionally ($$)
1105   my ($varname, $where) = @_;
1106   my $var = var $varname;
1107   if ($var->has_conditional_contents)
1108     {
1109       $varname = "am__${varname}_DIST";
1110       my @files = uniq ($var->value_as_list_recursive);
1111       define_pretty_variable ($varname, TRUE, $where, @files);
1112     }
1113   return "\$($varname)"
1116 # get_object_extension ($EXTENSION)
1117 # ---------------------------------
1118 # Prefix $EXTENSION with $U if ansi2knr is in use.
1119 sub get_object_extension ($)
1121     my ($extension) = @_;
1123     # Check for automatic de-ANSI-fication.
1124     $extension = '$U' . $extension
1125       if option 'ansi2knr';
1127     $get_object_extension_was_run = 1;
1129     return $extension;
1132 # check_user_variables (@LIST)
1133 # ----------------------------
1134 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
1135 # otherwise.
1136 sub check_user_variables (@)
1138   my @dont_override = @_;
1139   foreach my $flag (@dont_override)
1140     {
1141       my $var = var $flag;
1142       if ($var)
1143         {
1144           for my $cond ($var->conditions->conds)
1145             {
1146               if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1147                 {
1148                   msg_cond_var ('gnu', $cond, $flag,
1149                                 "`$flag' is a user variable, "
1150                                 . "you should not override it;\n"
1151                                 . "use `AM_$flag' instead.");
1152                 }
1153             }
1154         }
1155     }
1158 # Call finish function for each language that was used.
1159 sub handle_languages
1161     if (! option 'no-dependencies')
1162     {
1163         # Include auto-dep code.  Don't include it if DEP_FILES would
1164         # be empty.
1165         if (&saw_sources_p (0) && keys %dep_files)
1166         {
1167             # Set location of depcomp.
1168             &define_variable ('depcomp',
1169                               "\$(SHELL) $am_config_aux_dir/depcomp",
1170                               INTERNAL);
1171             &define_variable ('am__depfiles_maybe', 'depfiles', INTERNAL);
1173             require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1175             my @deplist = sort keys %dep_files;
1176             # Generate each `include' individually.  Irix 6 make will
1177             # not properly include several files resulting from a
1178             # variable expansion; generating many separate includes
1179             # seems safest.
1180             $output_rules .= "\n";
1181             foreach my $iter (@deplist)
1182             {
1183                 $output_rules .= (subst ('AMDEP_TRUE')
1184                                   . subst ('am__include')
1185                                   . ' '
1186                                   . subst ('am__quote')
1187                                   . $iter
1188                                   . subst ('am__quote')
1189                                   . "\n");
1190             }
1192             # Compute the set of directories to remove in distclean-depend.
1193             my @depdirs = uniq (map { dirname ($_) } @deplist);
1194             $output_rules .= &file_contents ('depend',
1195                                              new Automake::Location,
1196                                              DEPDIRS => "@depdirs");
1197         }
1198     }
1199     else
1200     {
1201         &define_variable ('depcomp', '', INTERNAL);
1202         &define_variable ('am__depfiles_maybe', '', INTERNAL);
1203     }
1205     my %done;
1207     # Is the c linker needed?
1208     my $needs_c = 0;
1209     foreach my $ext (sort keys %extension_seen)
1210     {
1211         next unless $extension_map{$ext};
1213         my $lang = $languages{$extension_map{$ext}};
1215         my $rule_file = $lang->rule_file || 'depend2';
1217         # Get information on $LANG.
1218         my $pfx = $lang->autodep;
1219         my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1221         my ($AMDEP, $FASTDEP) =
1222           (option 'no-dependencies' || $lang->autodep eq 'no')
1223           ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1225         my %transform = ('EXT'     => $ext,
1226                          'PFX'     => $pfx,
1227                          'FPFX'    => $fpfx,
1228                          'AMDEP'   => $AMDEP,
1229                          'FASTDEP' => $FASTDEP,
1230                          '-c'      => $lang->compile_flag || '',
1231                          # These are not used, but they need to be defined
1232                          # so &transform do not complain.
1233                          SUBDIROBJ     => 0,
1234                          'DERIVED-EXT' => 'BUG',
1235                          DIST_SOURCE   => 1,
1236                         );
1238         # Generate the appropriate rules for this extension.
1239         if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1240             || defined $lang->compile)
1241         {
1242             # Some C compilers don't support -c -o.  Use it only if really
1243             # needed.
1244             my $output_flag = $lang->output_flag || '';
1245             $output_flag = '-o'
1246               if (! $output_flag
1247                   && $lang->name eq 'c'
1248                   && option 'subdir-objects');
1250             # Compute a possible derived extension.
1251             # This is not used by depend2.am.
1252             my $der_ext = (&{$lang->output_extensions} ($ext))[0];
1254             # When we output an inference rule like `.c.o:' we
1255             # have two cases to consider: either subdir-objects
1256             # is used, or it is not.
1257             #
1258             # In the latter case the rule is used to build objects
1259             # in the current directory, and dependencies always
1260             # go into `./$(DEPDIR)/'.  We can hard-code this value.
1261             #
1262             # In the former case the rule can be used to build
1263             # objects in sub-directories too.  Dependencies should
1264             # go into the appropriate sub-directories, e.g.,
1265             # `sub/$(DEPDIR)/'.  The value of this directory
1266             # needs to be computed on-the-fly.
1267             #
1268             # DEPBASE holds the name of this directory, plus the
1269             # basename part of the object file (extensions Po, TPo,
1270             # Plo, TPlo will be added later as appropriate).  It is
1271             # either hardcoded, or a shell variable (`$depbase') that
1272             # will be computed by the rule.
1273             my $depbase =
1274               option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
1275             $output_rules .=
1276               file_contents ($rule_file,
1277                              new Automake::Location,
1278                              %transform,
1279                              GENERIC   => 1,
1281                              'DERIVED-EXT' => $der_ext,
1283                              DEPBASE   => $depbase,
1284                              BASE      => '$*',
1285                              SOURCE    => '$<',
1286                              SOURCEFLAG => $sourceflags{$ext} || '',
1287                              OBJ       => '$@',
1288                              OBJOBJ    => '$@',
1289                              LTOBJ     => '$@',
1291                              COMPILE   => '$(' . $lang->compiler . ')',
1292                              LTCOMPILE => '$(LT' . $lang->compiler . ')',
1293                              -o        => $output_flag,
1294                              SUBDIROBJ => !! option 'subdir-objects');
1295         }
1297         # Now include code for each specially handled object with this
1298         # language.
1299         my %seen_files = ();
1300         foreach my $file (@{$lang_specific_files{$lang->name}})
1301         {
1302             my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
1304             # We might see a given object twice, for instance if it is
1305             # used under different conditions.
1306             next if defined $seen_files{$obj};
1307             $seen_files{$obj} = 1;
1309             prog_error ("found " . $lang->name .
1310                         " in handle_languages, but compiler not defined")
1311               unless defined $lang->compile;
1313             my $obj_compile = $lang->compile;
1315             # Rewrite each occurrence of `AM_$flag' in the compile
1316             # rule into `${derived}_$flag' if it exists.
1317             for my $flag (@{$lang->flags})
1318               {
1319                 my $val = "${derived}_$flag";
1320                 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1321                   if set_seen ($val);
1322               }
1324             my $libtool_tag = '';
1325             if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1326               {
1327                 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1328               }
1330             my $ptltflags = "${derived}_LIBTOOLFLAGS";
1331             $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1333             my $obj_ltcompile =
1334               "\$(LIBTOOL) $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1335               . "--mode=compile $obj_compile";
1337             # We _need_ `-o' for per object rules.
1338             my $output_flag = $lang->output_flag || '-o';
1340             my $depbase = dirname ($obj);
1341             $depbase = ''
1342                 if $depbase eq '.';
1343             $depbase .= '/'
1344                 unless $depbase eq '';
1345             $depbase .= '$(DEPDIR)/' . basename ($obj);
1347             # Support for deansified files in subdirectories is ugly
1348             # enough to deserve an explanation.
1349             #
1350             # A Note about normal ansi2knr processing first.  On
1351             #
1352             #   AUTOMAKE_OPTIONS = ansi2knr
1353             #   bin_PROGRAMS = foo
1354             #   foo_SOURCES = foo.c
1355             #
1356             # we generate rules similar to:
1357             #
1358             #   foo: foo$U.o; link ...
1359             #   foo$U.o: foo$U.c; compile ...
1360             #   foo_.c: foo.c; ansi2knr ...
1361             #
1362             # this is fairly compact, and will call ansi2knr depending
1363             # on the value of $U (`' or `_').
1364             #
1365             # It's harder with subdir sources. On
1366             #
1367             #   AUTOMAKE_OPTIONS = ansi2knr
1368             #   bin_PROGRAMS = foo
1369             #   foo_SOURCES = sub/foo.c
1370             #
1371             # we have to create foo_.c in the current directory.
1372             # (Unless the user asks 'subdir-objects'.)  This is important
1373             # in case the same file (`foo.c') is compiled from other
1374             # directories with different cpp options: foo_.c would
1375             # be preprocessed for only one set of options if it were
1376             # put in the subdirectory.
1377             #
1378             # Because foo$U.o must be built from either foo_.c or
1379             # sub/foo.c we can't be as concise as in the first example.
1380             # Instead we output
1381             #
1382             #   foo: foo$U.o; link ...
1383             #   foo_.o: foo_.c; compile ...
1384             #   foo.o: sub/foo.c; compile ...
1385             #   foo_.c: foo.c; ansi2knr ...
1386             #
1387             # This is why we'll now transform $rule_file twice
1388             # if we detect this case.
1389             # A first time we output the compile rule with `$U'
1390             # replaced by `_' and the source directory removed,
1391             # and another time we simply remove `$U'.
1392             #
1393             # Note that at this point $source (as computed by
1394             # &handle_single_transform) is `sub/foo$U.c'.
1395             # This can be confusing: it can be used as-is when
1396             # subdir-objects is set, otherwise you have to know
1397             # it really means `foo_.c' or `sub/foo.c'.
1398             my $objdir = dirname ($obj);
1399             my $srcdir = dirname ($source);
1400             if ($lang->ansi && $obj =~ /\$U/)
1401               {
1402                 prog_error "`$obj' contains \$U, but `$source' doesn't."
1403                   if $source !~ /\$U/;
1405                 (my $source_ = $source) =~ s/\$U/_/g;
1406                 # Output an additional rule if _.c and .c are not in
1407                 # the same directory.  (_.c is always in $objdir.)
1408                 if ($objdir ne $srcdir)
1409                   {
1410                     (my $obj_ = $obj) =~ s/\$U/_/g;
1411                     (my $depbase_ = $depbase) =~ s/\$U/_/g;
1412                     $source_ = basename ($source_);
1414                     $output_rules .=
1415                       file_contents ($rule_file,
1416                                      new Automake::Location,
1417                                      %transform,
1418                                      GENERIC   => 0,
1420                                      DEPBASE   => $depbase_,
1421                                      BASE      => $obj_,
1422                                      SOURCE    => $source_,
1423                                      SOURCEFLAG => $sourceflags{$srcext} || '',
1424                                      OBJ       => "$obj_$myext",
1425                                      OBJOBJ    => "$obj_.obj",
1426                                      LTOBJ     => "$obj_.lo",
1428                                      COMPILE   => $obj_compile,
1429                                      LTCOMPILE => $obj_ltcompile,
1430                                      -o        => $output_flag,
1431                                      %file_transform);
1432                     $obj =~ s/\$U//g;
1433                     $depbase =~ s/\$U//g;
1434                     $source =~ s/\$U//g;
1435                   }
1436               }
1438             $output_rules .=
1439               file_contents ($rule_file,
1440                              new Automake::Location,
1441                              %transform,
1442                              GENERIC   => 0,
1444                              DEPBASE   => $depbase,
1445                              BASE      => $obj,
1446                              SOURCE    => $source,
1447                              SOURCEFLAG => $sourceflags{$srcext} || '',
1448                              # Use $myext and not `.o' here, in case
1449                              # we are actually building a new source
1450                              # file -- e.g. via yacc.
1451                              OBJ       => "$obj$myext",
1452                              OBJOBJ    => "$obj.obj",
1453                              LTOBJ     => "$obj.lo",
1455                              COMPILE   => $obj_compile,
1456                              LTCOMPILE => $obj_ltcompile,
1457                              -o        => $output_flag,
1458                              %file_transform);
1459         }
1461         # The rest of the loop is done once per language.
1462         next if defined $done{$lang};
1463         $done{$lang} = 1;
1465         # Load the language dependent Makefile chunks.
1466         my %lang = map { uc ($_) => 0 } keys %languages;
1467         $lang{uc ($lang->name)} = 1;
1468         $output_rules .= file_contents ('lang-compile',
1469                                         new Automake::Location,
1470                                         %transform, %lang);
1472         # If the source to a program consists entirely of code from a
1473         # `pure' language, for instance C++ or Fortran 77, then we
1474         # don't need the C compiler code.  However if we run into
1475         # something unusual then we do generate the C code.  There are
1476         # probably corner cases here that do not work properly.
1477         # People linking Java code to Fortran code deserve pain.
1478         $needs_c ||= ! $lang->pure;
1480         define_compiler_variable ($lang)
1481           if ($lang->compile);
1483         define_linker_variable ($lang)
1484           if ($lang->link);
1486         require_variables ("$am_file.am", $lang->Name . " source seen",
1487                            TRUE, @{$lang->config_vars});
1489         # Call the finisher.
1490         $lang->finish;
1492         # Flags listed in `->flags' are user variables (per GNU Standards),
1493         # they should not be overridden in the Makefile...
1494         my @dont_override = @{$lang->flags};
1495         # ... and so is LDFLAGS.
1496         push @dont_override, 'LDFLAGS' if $lang->link;
1498         check_user_variables @dont_override;
1499     }
1501     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1502     # suffix rule was learned), don't bother with the C stuff.  But if
1503     # anything else creeps in, then use it.
1504     $needs_c = 1
1505       if $need_link || suffix_rules_count > 1;
1507     if ($needs_c)
1508       {
1509         &define_compiler_variable ($languages{'c'})
1510           unless defined $done{$languages{'c'}};
1511         define_linker_variable ($languages{'c'});
1512       }
1516 # append_exeext { PREDICATE } $MACRO
1517 # ----------------------------------
1518 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
1519 # variable $MACRO if &PREDICATE($F) is true.  @substitutions@ are
1520 # ignored.
1522 # This is typically used on all filenames of *_PROGRAMS, and filenames
1523 # of TESTS that are programs.
1524 sub append_exeext (&$)
1526   my ($pred, $macro) = @_;
1528   transform_variable_recursively
1529     ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
1530      sub {
1531        my ($subvar, $val, $cond, $full_cond) = @_;
1532        # Append $(EXEEXT) unless the user did it already, or it's a
1533        # @substitution@.
1534        $val .= '$(EXEEXT)'
1535          if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
1536        return $val;
1537      });
1541 # Check to make sure a source defined in LIBOBJS is not explicitly
1542 # mentioned.  This is a separate function (as opposed to being inlined
1543 # in handle_source_transform) because it isn't always appropriate to
1544 # do this check.
1545 sub check_libobjs_sources
1547   my ($one_file, $unxformed) = @_;
1549   foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1550                       'dist_EXTRA_', 'nodist_EXTRA_')
1551     {
1552       my @files;
1553       my $varname = $prefix . $one_file . '_SOURCES';
1554       my $var = var ($varname);
1555       if ($var)
1556         {
1557           @files = $var->value_as_list_recursive;
1558         }
1559       elsif ($prefix eq '')
1560         {
1561           @files = ($unxformed . '.c');
1562         }
1563       else
1564         {
1565           next;
1566         }
1568       foreach my $file (@files)
1569         {
1570           err_var ($prefix . $one_file . '_SOURCES',
1571                    "automatically discovered file `$file' should not" .
1572                    " be explicitly mentioned")
1573             if defined $libsources{$file};
1574         }
1575     }
1579 # @OBJECTS
1580 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1581 # -----------------------------------------------------------------------------
1582 # Does much of the actual work for handle_source_transform.
1583 # Arguments are:
1584 #   $VAR is the name of the variable that the source filenames come from
1585 #   $TOPPARENT is the name of the _SOURCES variable which is being processed
1586 #   $DERIVED is the name of resulting executable or library
1587 #   $OBJ is the object extension (e.g., `$U.lo')
1588 #   $FILE the source file to transform
1589 #   %TRANSFORM contains extras arguments to pass to file_contents
1590 #     when producing explicit rules
1591 # Result is a list of the names of objects
1592 # %linkers_used will be updated with any linkers needed
1593 sub handle_single_transform ($$$$$%)
1595     my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1596     my @files = ($_file);
1597     my @result = ();
1598     my $nonansi_obj = $obj;
1599     $nonansi_obj =~ s/\$U//g;
1601     # Turn sources into objects.  We use a while loop like this
1602     # because we might add to @files in the loop.
1603     while (scalar @files > 0)
1604     {
1605         $_ = shift @files;
1607         # Configure substitutions in _SOURCES variables are errors.
1608         if (/^\@.*\@$/)
1609         {
1610           my $parent_msg = '';
1611           $parent_msg = "\nand is referred to from `$topparent'"
1612             if $topparent ne $var->name;
1613           err_var ($var,
1614                    "`" . $var->name . "' includes configure substitution `$_'"
1615                    . $parent_msg . ";\nconfigure " .
1616                    "substitutions are not allowed in _SOURCES variables");
1617           next;
1618         }
1620         # If the source file is in a subdirectory then the `.o' is put
1621         # into the current directory, unless the subdir-objects option
1622         # is in effect.
1624         # Split file name into base and extension.
1625         next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1626         my $full = $_;
1627         my $directory = $1 || '';
1628         my $base = $2;
1629         my $extension = $3;
1631         # We must generate a rule for the object if it requires its own flags.
1632         my $renamed = 0;
1633         my ($linker, $object);
1635         # This records whether we've seen a derived source file (e.g.
1636         # yacc output).
1637         my $derived_source = 0;
1639         # This holds the `aggregate context' of the file we are
1640         # currently examining.  If the file is compiled with
1641         # per-object flags, then it will be the name of the object.
1642         # Otherwise it will be `AM'.  This is used by the target hook
1643         # language function.
1644         my $aggregate = 'AM';
1646         $extension = &derive_suffix ($extension, $nonansi_obj);
1647         my $lang;
1648         if ($extension_map{$extension} &&
1649             ($lang = $languages{$extension_map{$extension}}))
1650         {
1651             # Found the language, so see what it says.
1652             &saw_extension ($extension);
1654             # Do we have per-executable flags for this executable?
1655             my $have_per_exec_flags = 0;
1656             my @peflags = @{$lang->flags};
1657             push @peflags, 'LIBTOOLFLAGS' if $nonansi_obj eq '.lo';
1658             foreach my $flag (@peflags)
1659               {
1660                 if (set_seen ("${derived}_$flag"))
1661                   {
1662                     $have_per_exec_flags = 1;
1663                     last;
1664                   }
1665               }
1667             # Note: computed subr call.  The language rewrite function
1668             # should return one of the LANG_* constants.  It could
1669             # also return a list whose first value is such a constant
1670             # and whose second value is a new source extension which
1671             # should be applied.  This means this particular language
1672             # generates another source file which we must then process
1673             # further.
1674             my $subr = \&{'lang_' . $lang->name . '_rewrite'};
1675             my ($r, $source_extension)
1676                 = &$subr ($directory, $base, $extension,
1677                           $nonansi_obj, $have_per_exec_flags, $var);
1678             # Skip this entry if we were asked not to process it.
1679             next if $r == LANG_IGNORE;
1681             # Now extract linker and other info.
1682             $linker = $lang->linker;
1684             my $this_obj_ext;
1685             if (defined $source_extension)
1686             {
1687                 $this_obj_ext = $source_extension;
1688                 $derived_source = 1;
1689             }
1690             elsif ($lang->ansi)
1691             {
1692                 $this_obj_ext = $obj;
1693             }
1694             else
1695             {
1696                 $this_obj_ext = $nonansi_obj;
1697             }
1698             $object = $base . $this_obj_ext;
1700             if ($have_per_exec_flags)
1701             {
1702                 # We have a per-executable flag in effect for this
1703                 # object.  In this case we rewrite the object's
1704                 # name to ensure it is unique.
1706                 # We choose the name `DERIVED_OBJECT' to ensure
1707                 # (1) uniqueness, and (2) continuity between
1708                 # invocations.  However, this will result in a
1709                 # name that is too long for losing systems, in
1710                 # some situations.  So we provide _SHORTNAME to
1711                 # override.
1713                 my $dname = $derived;
1714                 my $var = var ($derived . '_SHORTNAME');
1715                 if ($var)
1716                 {
1717                     # FIXME: should use the same Condition as
1718                     # the _SOURCES variable.  But this is really
1719                     # silly overkill -- nobody should have
1720                     # conditional shortnames.
1721                     $dname = $var->variable_value;
1722                 }
1723                 $object = $dname . '-' . $object;
1725                 prog_error ($lang->name . " flags defined without compiler")
1726                   if ! defined $lang->compile;
1728                 $renamed = 1;
1729             }
1731             # If rewrite said it was ok, put the object into a
1732             # subdir.
1733             if ($r == LANG_SUBDIR && $directory ne '')
1734             {
1735                 $object = $directory . '/' . $object;
1736             }
1738             # If the object file has been renamed (because per-target
1739             # flags are used) we cannot compile the file with an
1740             # inference rule: we need an explicit rule.
1741             #
1742             # If the source is in a subdirectory and the object is in
1743             # the current directory, we also need an explicit rule.
1744             #
1745             # If both source and object files are in a subdirectory
1746             # (this happens when the subdir-objects option is used),
1747             # then the inference will work.
1748             #
1749             # The latter case deserves a historical note.  When the
1750             # subdir-objects option was added on 1999-04-11 it was
1751             # thought that inferences rules would work for
1752             # subdirectory objects too.  Later, on 1999-11-22,
1753             # automake was changed to output explicit rules even for
1754             # subdir-objects.  Nobody remembers why, but this occurred
1755             # soon after the merge of the user-dep-gen-branch so it
1756             # might be related.  In late 2003 people complained about
1757             # the size of the generated Makefile.ins (libgcj, with
1758             # 2200+ subdir objects was reported to have a 9MB
1759             # Makefile), so we now rely on inference rules again.
1760             # Maybe we'll run across the same issue as in the past,
1761             # but at least this time we can document it.  However since
1762             # dependency tracking has evolved it is possible that
1763             # our old problem no longer exists.
1764             # Using inference rules for subdir-objects has been tested
1765             # with GNU make, Solaris make, Ultrix make, BSD make,
1766             # HP-UX make, and OSF1 make successfully.
1767             if ($renamed
1768                 || ($directory ne '' && ! option 'subdir-objects')
1769                 # We must also use specific rules for a nodist_ source
1770                 # if its language requests it.
1771                 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1772             {
1773                 my $obj_sans_ext = substr ($object, 0,
1774                                            - length ($this_obj_ext));
1775                 my $full_ansi = $full;
1776                 if ($lang->ansi && option 'ansi2knr')
1777                   {
1778                     $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
1779                     $obj_sans_ext .= '$U';
1780                   }
1782                 my @specifics = ($full_ansi, $obj_sans_ext,
1783                                  # Only use $this_obj_ext in the derived
1784                                  # source case because in the other case we
1785                                  # *don't* want $(OBJEXT) to appear here.
1786                                  ($derived_source ? $this_obj_ext : '.o'),
1787                                  $extension);
1789                 # If we renamed the object then we want to use the
1790                 # per-executable flag name.  But if this is simply a
1791                 # subdir build then we still want to use the AM_ flag
1792                 # name.
1793                 if ($renamed)
1794                   {
1795                     unshift @specifics, $derived;
1796                     $aggregate = $derived;
1797                   }
1798                 else
1799                   {
1800                     unshift @specifics, 'AM';
1801                   }
1803                 # Each item on this list is a reference to a list consisting
1804                 # of four values followed by additional transform flags for
1805                 # file_contents.   The four values are the derived flag prefix
1806                 # (e.g. for `foo_CFLAGS', it is `foo'), the name of the
1807                 # source file, the base name of the output file, and
1808                 # the extension for the object file.
1809                 push (@{$lang_specific_files{$lang->name}},
1810                       [@specifics, %transform]);
1811             }
1812         }
1813         elsif ($extension eq $nonansi_obj)
1814         {
1815             # This is probably the result of a direct suffix rule.
1816             # In this case we just accept the rewrite.
1817             $object = "$base$extension";
1818             $object = "$directory/$object" if $directory ne '';
1819             $linker = '';
1820         }
1821         else
1822         {
1823             # No error message here.  Used to have one, but it was
1824             # very unpopular.
1825             # FIXME: we could potentially do more processing here,
1826             # perhaps treating the new extension as though it were a
1827             # new source extension (as above).  This would require
1828             # more restructuring than is appropriate right now.
1829             next;
1830         }
1832         err_am "object `$object' created by `$full' and `$object_map{$object}'"
1833           if (defined $object_map{$object}
1834               && $object_map{$object} ne $full);
1836         my $comp_val = (($object =~ /\.lo$/)
1837                         ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1838         (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1839         if (defined $object_compilation_map{$comp_obj}
1840             && $object_compilation_map{$comp_obj} != 0
1841             # Only see the error once.
1842             && ($object_compilation_map{$comp_obj}
1843                 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1844             && $object_compilation_map{$comp_obj} != $comp_val)
1845           {
1846             err_am "object `$comp_obj' created both with libtool and without";
1847           }
1848         $object_compilation_map{$comp_obj} |= $comp_val;
1850         if (defined $lang)
1851         {
1852             # Let the language do some special magic if required.
1853             $lang->target_hook ($aggregate, $object, $full, %transform);
1854         }
1856         if ($derived_source)
1857           {
1858             prog_error ($lang->name . " has automatic dependency tracking")
1859               if $lang->autodep ne 'no';
1860             # Make sure this new source file is handled next.  That will
1861             # make it appear to be at the right place in the list.
1862             unshift (@files, $object);
1863             # Distribute derived sources unless the source they are
1864             # derived from is not.
1865             &push_dist_common ($object)
1866               unless ($topparent =~ /^(?:nobase_)?nodist_/);
1867             next;
1868           }
1870         $linkers_used{$linker} = 1;
1872         push (@result, $object);
1874         if (! defined $object_map{$object})
1875         {
1876             my @dep_list = ();
1877             $object_map{$object} = $full;
1879             # If resulting object is in subdir, we need to make
1880             # sure the subdir exists at build time.
1881             if ($object =~ /\//)
1882             {
1883                 # FIXME: check that $DIRECTORY is somewhere in the
1884                 # project
1886                 # For Java, the way we're handling it right now, a
1887                 # `..' component doesn't make sense.
1888                 if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
1889                   {
1890                     err_am "`$full' should not contain a `..' component";
1891                   }
1893                 # Make sure object is removed by `make mostlyclean'.
1894                 $compile_clean_files{$object} = MOSTLY_CLEAN;
1895                 # If we have a libtool object then we also must remove
1896                 # the ordinary .o.
1897                 if ($object =~ /\.lo$/)
1898                 {
1899                     (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
1900                     $compile_clean_files{$xobj} = MOSTLY_CLEAN;
1902                     # Remove any libtool object in this directory.
1903                     $libtool_clean_directories{$directory} = 1;
1904                 }
1906                 push (@dep_list, require_build_directory ($directory));
1908                 # If we're generating dependencies, we also want
1909                 # to make sure that the appropriate subdir of the
1910                 # .deps directory is created.
1911                 push (@dep_list,
1912                       require_build_directory ($directory . '/$(DEPDIR)'))
1913                   unless option 'no-dependencies';
1914             }
1916             &pretty_print_rule ($object . ':', "\t", @dep_list)
1917                 if scalar @dep_list > 0;
1918         }
1920         # Transform .o or $o file into .P file (for automatic
1921         # dependency code).
1922         if ($lang && $lang->autodep ne 'no')
1923         {
1924             my $depfile = $object;
1925             $depfile =~ s/\.([^.]*)$/.P$1/;
1926             $depfile =~ s/\$\(OBJEXT\)$/o/;
1927             $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
1928                          . basename ($depfile)} = 1;
1929         }
1930     }
1932     return @result;
1936 # $LINKER
1937 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
1938 #                              $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
1939 # ---------------------------------------------------------------------------
1940 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
1942 # Arguments are:
1943 #   $VAR is the name of the _SOURCES variable
1944 #   $OBJVAR is the name of the _OBJECTS variable if known (otherwise
1945 #     it will be generated and returned).
1946 #   $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
1947 #     work done to determine the linker will be).
1948 #   $ONE_FILE is the canonical (transformed) name of object to build
1949 #   $OBJ is the object extension (i.e. either `.o' or `.lo').
1950 #   $TOPPARENT is the _SOURCES variable being processed.
1951 #   $WHERE context into which this definition is done
1952 #   %TRANSFORM extra arguments to pass to file_contents when producing
1953 #     rules
1955 # Result is a pair ($LINKER, $OBJVAR):
1956 #    $LINKER is a boolean, true if a linker is needed to deal with the objects
1957 sub define_objects_from_sources ($$$$$$$%)
1959   my ($var, $objvar, $nodefine, $one_file,
1960       $obj, $topparent, $where, %transform) = @_;
1962   my $needlinker = "";
1964   transform_variable_recursively
1965     ($var, $objvar, 'am__objects', $nodefine, $where,
1966      # The transform code to run on each filename.
1967      sub {
1968        my ($subvar, $val, $cond, $full_cond) = @_;
1969        my @trans = handle_single_transform ($subvar, $topparent,
1970                                             $one_file, $obj, $val,
1971                                             %transform);
1972        $needlinker = "true" if @trans;
1973        return @trans;
1974      });
1976   return $needlinker;
1980 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
1981 # -----------------------------------------------------------------------------
1982 # Handle SOURCE->OBJECT transform for one program or library.
1983 # Arguments are:
1984 #   canonical (transformed) name of target to build
1985 #   actual target of object to build
1986 #   object extension (i.e., either `.o' or `$o')
1987 #   location of the source variable
1988 #   extra arguments to pass to file_contents when producing rules
1989 # Return the name of the linker variable that must be used.
1990 # Empty return means just use `LINK'.
1991 sub handle_source_transform ($$$$%)
1993     # one_file is canonical name.  unxformed is given name.  obj is
1994     # object extension.
1995     my ($one_file, $unxformed, $obj, $where, %transform) = @_;
1997     my $linker = '';
1999     # No point in continuing if _OBJECTS is defined.
2000     return if reject_var ($one_file . '_OBJECTS',
2001                           $one_file . '_OBJECTS should not be defined');
2003     my %used_pfx = ();
2004     my $needlinker;
2005     %linkers_used = ();
2006     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2007                         'dist_EXTRA_', 'nodist_EXTRA_')
2008     {
2009         my $varname = $prefix . $one_file . "_SOURCES";
2010         my $var = var $varname;
2011         next unless $var;
2013         # We are going to define _OBJECTS variables using the prefix.
2014         # Then we glom them all together.  So we can't use the null
2015         # prefix here as we need it later.
2016         my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2018         # Keep track of which prefixes we saw.
2019         $used_pfx{$xpfx} = 1
2020           unless $prefix =~ /EXTRA_/;
2022         push @sources, "\$($varname)";
2023         push @dist_sources, shadow_unconditionally ($varname, $where)
2024           unless (option ('no-dist') || $prefix =~ /^nodist_/);
2026         $needlinker |=
2027             define_objects_from_sources ($varname,
2028                                          $xpfx . $one_file . '_OBJECTS',
2029                                          $prefix =~ /EXTRA_/,
2030                                          $one_file, $obj, $varname, $where,
2031                                          DIST_SOURCE => ($prefix !~ /^nodist_/),
2032                                          %transform);
2033     }
2034     if ($needlinker)
2035     {
2036         $linker ||= &resolve_linker (%linkers_used);
2037     }
2039     my @keys = sort keys %used_pfx;
2040     if (scalar @keys == 0)
2041     {
2042         # The default source for libfoo.la is libfoo.c, but for
2043         # backward compatibility we first look at libfoo_la.c
2044         my $old_default_source = "$one_file.c";
2045         (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,.c,;
2046         if ($old_default_source ne $default_source
2047             && (rule $old_default_source
2048                 || rule '$(srcdir)/' . $old_default_source
2049                 || rule '${srcdir}/' . $old_default_source
2050                 || -f $old_default_source))
2051           {
2052             my $loc = $where->clone;
2053             $loc->pop_context;
2054             msg ('obsolete', $loc,
2055                  "the default source for `$unxformed' has been changed "
2056                  . "to `$default_source'.\n(Using `$old_default_source' for "
2057                  . "backward compatibility.)");
2058             $default_source = $old_default_source;
2059           }
2060         # If a rule exists to build this source with a $(srcdir)
2061         # prefix, use that prefix in our variables too.  This is for
2062         # the sake of BSD Make.
2063         if (rule '$(srcdir)/' . $default_source
2064             || rule '${srcdir}/' . $default_source)
2065           {
2066             $default_source = '$(srcdir)/' . $default_source;
2067           }
2069         &define_variable ($one_file . "_SOURCES", $default_source, $where);
2070         push (@sources, $default_source);
2071         push (@dist_sources, $default_source);
2073         %linkers_used = ();
2074         my (@result) =
2075           handle_single_transform ($one_file . '_SOURCES',
2076                                    $one_file . '_SOURCES',
2077                                    $one_file, $obj,
2078                                    $default_source, %transform);
2079         $linker ||= &resolve_linker (%linkers_used);
2080         define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2081     }
2082     else
2083     {
2084         @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2085         define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2086     }
2088     # If we want to use `LINK' we must make sure it is defined.
2089     if ($linker eq '')
2090     {
2091         $need_link = 1;
2092     }
2094     return $linker;
2098 # handle_lib_objects ($XNAME, $VAR)
2099 # ---------------------------------
2100 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2101 # Also, generate _DEPENDENCIES variable if appropriate.
2102 # Arguments are:
2103 #   transformed name of object being built, or empty string if no object
2104 #   name of _LDADD/_LIBADD-type variable to examine
2105 # Returns 1 if LIBOBJS seen, 0 otherwise.
2106 sub handle_lib_objects
2108   my ($xname, $varname) = @_;
2110   my $var = var ($varname);
2111   prog_error "handle_lib_objects: `$varname' undefined"
2112     unless $var;
2113   prog_error "handle_lib_objects: unexpected variable name `$varname'"
2114     unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2115   my $prefix = $1 || 'AM_';
2117   my $seen_libobjs = 0;
2118   my $flagvar = 0;
2120   transform_variable_recursively
2121     ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2122      ! $xname, INTERNAL,
2123      # Transformation function, run on each filename.
2124      sub {
2125        my ($subvar, $val, $cond, $full_cond) = @_;
2127        if ($val =~ /^-/)
2128          {
2129            # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2130            if ($val !~ /^-[lL]/ &&
2131                # Skip -dlopen and -dlpreopen; these are explicitly allowed
2132                # for Libtool libraries or programs.  (Actually we are a bit
2133                # laxe here since this code also applies to non-libtool
2134                # libraries or programs, for which -dlopen and -dlopreopen
2135                # are pure nonsense.  Diagnosing this doesn't seems very
2136                # important: the developer will quickly get complaints from
2137                # the linker.)
2138                $val !~ /^-dl(?:pre)?open$/ &&
2139                # Only get this error once.
2140                ! $flagvar)
2141              {
2142                $flagvar = 1;
2143                # FIXME: should display a stack of nested variables
2144                # as context when $var != $subvar.
2145                err_var ($var, "linker flags such as `$val' belong in "
2146                         . "`${prefix}LDFLAGS");
2147              }
2148            return ();
2149          }
2150        elsif ($val !~ /^\@.*\@$/)
2151          {
2152            # Assume we have a file of some sort, and output it into the
2153            # dependency variable.  Autoconf substitutions are not output;
2154            # rarely is a new dependency substituted into e.g. foo_LDADD
2155            # -- but bad things (e.g. -lX11) are routinely substituted.
2156            # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2157            # and handled specially below.
2158            return $val;
2159          }
2160        elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2161          {
2162            handle_LIBOBJS ($subvar, $cond, $1);
2163            $seen_libobjs = 1;
2164            return $val;
2165          }
2166        elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2167          {
2168            handle_ALLOCA ($subvar, $cond, $1);
2169            return $val;
2170          }
2171        else
2172          {
2173            return ();
2174          }
2175      });
2177   return $seen_libobjs;
2180 # handle_LIBOBJS_or_ALLOCA ($VAR)
2181 # -------------------------------
2182 # Definitions common to LIBOBJS and ALLOCA.
2183 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
2184 sub handle_LIBOBJS_or_ALLOCA ($)
2186   my ($var) = @_;
2188   my $dir = '';
2190   # If LIBOBJS files must be built in another directory we have
2191   # to define LIBOBJDIR and ensure the files get cleaned.
2192   # Otherwise LIBOBJDIR can be left undefined, and the cleaning
2193   # is achieved by `rm -f *.$(OBJEXT)' in compile.am.
2194   if ($config_libobj_dir
2195       && $relative_dir ne $config_libobj_dir)
2196     {
2197       if (option 'subdir-objects')
2198         {
2199           # In the top-level Makefile we do not use $(top_builddir), because
2200           # we are already there, and since the targets are built without
2201           # a $(top_builddir), it helps BSD Make to match them with
2202           # dependencies.
2203           $dir = "$config_libobj_dir/" if $config_libobj_dir ne '.';
2204           $dir = "$topsrcdir/$dir" if $relative_dir ne '.';
2205           define_variable ('LIBOBJDIR', "$dir", INTERNAL);
2206           $clean_files{"\$($var)"} = MOSTLY_CLEAN;
2207           # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
2208           # be created by libtool as a side-effect of creating LTLIBOBJS).
2209           $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
2210         }
2211       else
2212         {
2213           error ("`\$($var)' cannot be used outside `$config_libobj_dir' if"
2214                  . " `subdir-objects' is not set");
2215         }
2216     }
2218   return $dir;
2221 sub handle_LIBOBJS ($$$)
2223   my ($var, $cond, $lt) = @_;
2224   my $myobjext = $lt ? 'lo' : 'o';
2225   $lt ||= '';
2227   $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2228     if ! keys %libsources;
2230   my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
2232   foreach my $iter (keys %libsources)
2233     {
2234       if ($iter =~ /\.[cly]$/)
2235         {
2236           &saw_extension ($&);
2237           &saw_extension ('.c');
2238         }
2240       if ($iter =~ /\.h$/)
2241         {
2242           require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2243         }
2244       elsif ($iter ne 'alloca.c')
2245         {
2246           my $rewrite = $iter;
2247           $rewrite =~ s/\.c$/.P$myobjext/;
2248           $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
2249           $rewrite = "^" . quotemeta ($iter) . "\$";
2250           # Only require the file if it is not a built source.
2251           my $bs = var ('BUILT_SOURCES');
2252           if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2253             {
2254               require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2255             }
2256         }
2257     }
2260 sub handle_ALLOCA ($$$)
2262   my ($var, $cond, $lt) = @_;
2263   my $myobjext = $lt ? 'lo' : 'o';
2264   $lt ||= '';
2265   my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
2267   $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2268   $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
2269   require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2270   &saw_extension ('.c');
2273 # Canonicalize the input parameter
2274 sub canonicalize
2276     my ($string) = @_;
2277     $string =~ tr/A-Za-z0-9_\@/_/c;
2278     return $string;
2281 # Canonicalize a name, and check to make sure the non-canonical name
2282 # is never used.  Returns canonical name.  Arguments are name and a
2283 # list of suffixes to check for.
2284 sub check_canonical_spelling
2286   my ($name, @suffixes) = @_;
2288   my $xname = &canonicalize ($name);
2289   if ($xname ne $name)
2290     {
2291       foreach my $xt (@suffixes)
2292         {
2293           reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
2294         }
2295     }
2297   return $xname;
2301 # handle_compile ()
2302 # -----------------
2303 # Set up the compile suite.
2304 sub handle_compile ()
2306     return
2307       unless $get_object_extension_was_run;
2309     # Boilerplate.
2310     my $default_includes = '';
2311     if (! option 'nostdinc')
2312       {
2313         my @incs = ('-I.', subst ('am__isrc'));
2315         my $var = var 'CONFIG_HEADER';
2316         if ($var)
2317           {
2318             foreach my $hdr (split (' ', $var->variable_value))
2319               {
2320                 push @incs, '-I' . dirname ($hdr);
2321               }
2322           }
2323         # We want `-I. -I$(srcdir)', but the latter -I is redundant
2324         # and unaesthetic in non-VPATH builds.  We use `-I.@am__isrc@`
2325         # instead.  It will be replaced by '-I.' or '-I. -I$(srcdir)'.
2326         # Items in CONFIG_HEADER are never in $(srcdir) so it is safe
2327         # to just put @am__isrc@ right after `-I.', without a space.
2328         ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
2329       }
2331     my (@mostly_rms, @dist_rms);
2332     foreach my $item (sort keys %compile_clean_files)
2333     {
2334         if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2335         {
2336             push (@mostly_rms, "\t-rm -f $item");
2337         }
2338         elsif ($compile_clean_files{$item} == DIST_CLEAN)
2339         {
2340             push (@dist_rms, "\t-rm -f $item");
2341         }
2342         else
2343         {
2344           prog_error 'invalid entry in %compile_clean_files';
2345         }
2346     }
2348     my ($coms, $vars, $rules) =
2349       &file_contents_internal (1, "$libdir/am/compile.am",
2350                                new Automake::Location,
2351                                ('DEFAULT_INCLUDES' => $default_includes,
2352                                 'MOSTLYRMS' => join ("\n", @mostly_rms),
2353                                 'DISTRMS' => join ("\n", @dist_rms)));
2354     $output_vars .= $vars;
2355     $output_rules .= "$coms$rules";
2357     # Check for automatic de-ANSI-fication.
2358     if (option 'ansi2knr')
2359       {
2360         my ($ansi2knr_filename, $ansi2knr_where) = @{option 'ansi2knr'};
2361         my $ansi2knr_dir = '';
2363         require_variables ($ansi2knr_where, "option `ansi2knr' is used",
2364                            TRUE, "ANSI2KNR", "U");
2366         # topdir is where ansi2knr should be.
2367         if ($ansi2knr_filename eq 'ansi2knr')
2368           {
2369             # Only require ansi2knr files if they should appear in
2370             # this directory.
2371             require_file ($ansi2knr_where, FOREIGN,
2372                           'ansi2knr.c', 'ansi2knr.1');
2374             # ansi2knr needs to be built before subdirs, so unshift it.
2375             unshift (@all, '$(ANSI2KNR)');
2376           }
2377         else
2378           {
2379             $ansi2knr_dir = dirname ($ansi2knr_filename);
2380           }
2382         $output_rules .= &file_contents ('ansi2knr',
2383                                          new Automake::Location,
2384                                          'ANSI2KNR-DIR' => $ansi2knr_dir);
2386     }
2389 # handle_libtool ()
2390 # -----------------
2391 # Handle libtool rules.
2392 sub handle_libtool
2394   return unless var ('LIBTOOL');
2396   # Libtool requires some files, but only at top level.
2397   # (Starting with Libtool 2.0 we do not have to bother.  These
2398   # requirements are done with AC_REQUIRE_AUX_FILE.)
2399   require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2400     if $relative_dir eq '.' && ! $libtool_new_api;
2402   my @libtool_rms;
2403   foreach my $item (sort keys %libtool_clean_directories)
2404     {
2405       my $dir = ($item eq '.') ? '' : "$item/";
2406       # .libs is for Unix, _libs for DOS.
2407       push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2408     }
2410   check_user_variables 'LIBTOOLFLAGS';
2412   # Output the libtool compilation rules.
2413   $output_rules .= &file_contents ('libtool',
2414                                    new Automake::Location,
2415                                    LTRMS => join ("\n", @libtool_rms));
2418 # handle_programs ()
2419 # ------------------
2420 # Handle C programs.
2421 sub handle_programs
2423   my @proglist = &am_install_var ('progs', 'PROGRAMS',
2424                                   'bin', 'sbin', 'libexec', 'pkglib',
2425                                   'noinst', 'check');
2426   return if ! @proglist;
2428   my $seen_global_libobjs =
2429     var ('LDADD') && &handle_lib_objects ('', 'LDADD');
2431   foreach my $pair (@proglist)
2432     {
2433       my ($where, $one_file) = @$pair;
2435       my $seen_libobjs = 0;
2436       my $obj = get_object_extension '.$(OBJEXT)';
2438       # Strip any $(EXEEXT) suffix the user might have added, or this
2439       # will confuse &handle_source_transform and &check_canonical_spelling.
2440       # We'll add $(EXEEXT) back later anyway.
2441       $one_file =~ s/\$\(EXEEXT\)$//;
2443       $known_programs{$one_file} = $where;
2445       # Canonicalize names and check for misspellings.
2446       my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2447                                              '_SOURCES', '_OBJECTS',
2448                                              '_DEPENDENCIES');
2450       $where->push_context ("while processing program `$one_file'");
2451       $where->set (INTERNAL->get);
2453       my $linker = &handle_source_transform ($xname, $one_file, $obj, $where,
2454                                              NONLIBTOOL => 1, LIBTOOL => 0);
2456       if (var ($xname . "_LDADD"))
2457         {
2458           $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
2459         }
2460       else
2461         {
2462           # User didn't define prog_LDADD override.  So do it.
2463           &define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2465           # This does a bit too much work.  But we need it to
2466           # generate _DEPENDENCIES when appropriate.
2467           if (var ('LDADD'))
2468             {
2469               $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
2470             }
2471         }
2473       reject_var ($xname . '_LIBADD',
2474                   "use `${xname}_LDADD', not `${xname}_LIBADD'");
2476       set_seen ($xname . '_DEPENDENCIES');
2477       set_seen ($xname . '_LDFLAGS');
2479       # Determine program to use for link.
2480       my $xlink = &define_per_target_linker_variable ($linker, $xname);
2482       # If the resulting program lies into a subdirectory,
2483       # make sure this directory will exist.
2484       my $dirstamp = require_build_directory_maybe ($one_file);
2486       $libtool_clean_directories{dirname ($one_file)} = 1;
2488       $output_rules .= &file_contents ('program',
2489                                        $where,
2490                                        PROGRAM  => $one_file,
2491                                        XPROGRAM => $xname,
2492                                        XLINK    => $xlink,
2493                                        DIRSTAMP => $dirstamp,
2494                                        EXEEXT   => '$(EXEEXT)');
2496       if ($seen_libobjs || $seen_global_libobjs)
2497         {
2498           if (var ($xname . '_LDADD'))
2499             {
2500               &check_libobjs_sources ($xname, $xname . '_LDADD');
2501             }
2502           elsif (var ('LDADD'))
2503             {
2504               &check_libobjs_sources ($xname, 'LDADD');
2505             }
2506         }
2507     }
2511 # handle_libraries ()
2512 # -------------------
2513 # Handle libraries.
2514 sub handle_libraries
2516   my @liblist = &am_install_var ('libs', 'LIBRARIES',
2517                                  'lib', 'pkglib', 'noinst', 'check');
2518   return if ! @liblist;
2520   my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2521                                     'noinst', 'check');
2523   if (@prefix)
2524     {
2525       my $var = rvar ($prefix[0] . '_LIBRARIES');
2526       $var->requires_variables ('library used', 'RANLIB');
2527     }
2529   &define_variable ('AR', 'ar', INTERNAL);
2530   &define_variable ('ARFLAGS', 'cru', INTERNAL);
2532   foreach my $pair (@liblist)
2533     {
2534       my ($where, $onelib) = @$pair;
2536       my $seen_libobjs = 0;
2537       # Check that the library fits the standard naming convention.
2538       my $bn = basename ($onelib);
2539       if ($bn !~ /^lib.*\.a$/)
2540         {
2541           $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2542           my $suggestion = dirname ($onelib) . "/$bn";
2543           $suggestion =~ s|^\./||g;
2544           msg ('error-gnu/warn', $where,
2545                "`$onelib' is not a standard library name\n"
2546                . "did you mean `$suggestion'?")
2547         }
2549       $where->push_context ("while processing library `$onelib'");
2550       $where->set (INTERNAL->get);
2552       my $obj = get_object_extension '.$(OBJEXT)';
2554       # Canonicalize names and check for misspellings.
2555       my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2556                                             '_OBJECTS', '_DEPENDENCIES',
2557                                             '_AR');
2559       if (! var ($xlib . '_AR'))
2560         {
2561           &define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2562         }
2564       # Generate support for conditional object inclusion in
2565       # libraries.
2566       if (var ($xlib . '_LIBADD'))
2567         {
2568           if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2569             {
2570               $seen_libobjs = 1;
2571             }
2572         }
2573       else
2574         {
2575           &define_variable ($xlib . "_LIBADD", '', $where);
2576         }
2578       reject_var ($xlib . '_LDADD',
2579                   "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2581       # Make sure we at look at this.
2582       set_seen ($xlib . '_DEPENDENCIES');
2584       &handle_source_transform ($xlib, $onelib, $obj, $where,
2585                                 NONLIBTOOL => 1, LIBTOOL => 0);
2587       # If the resulting library lies into a subdirectory,
2588       # make sure this directory will exist.
2589       my $dirstamp = require_build_directory_maybe ($onelib);
2591       $output_rules .= &file_contents ('library',
2592                                        $where,
2593                                        LIBRARY  => $onelib,
2594                                        XLIBRARY => $xlib,
2595                                        DIRSTAMP => $dirstamp);
2597       if ($seen_libobjs)
2598         {
2599           if (var ($xlib . '_LIBADD'))
2600             {
2601               &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2602             }
2603         }
2604     }
2608 # handle_ltlibraries ()
2609 # ---------------------
2610 # Handle shared libraries.
2611 sub handle_ltlibraries
2613   my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2614                                  'noinst', 'lib', 'pkglib', 'check');
2615   return if ! @liblist;
2617   my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2618                                     'noinst', 'check');
2620   if (@prefix)
2621     {
2622       my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2623       $var->requires_variables ('Libtool library used', 'LIBTOOL');
2624     }
2626   my %instdirs = ();
2627   my %instconds = ();
2628   my %liblocations = ();        # Location (in Makefile.am) of each library.
2630   foreach my $key (@prefix)
2631     {
2632       # Get the installation directory of each library.
2633       (my $dir = $key) =~ s/^nobase_//;
2634       my $var = rvar ($key . '_LTLIBRARIES');
2636       # We reject libraries which are installed in several places
2637       # in the same condition, because we can only specify one
2638       # `-rpath' option.
2639       $var->traverse_recursively
2640         (sub
2641          {
2642            my ($var, $val, $cond, $full_cond) = @_;
2643            my $hcond = $full_cond->human;
2644            my $where = $var->rdef ($cond)->location;
2645            # A library cannot be installed in different directory
2646            # in overlapping conditions.
2647            if (exists $instconds{$val})
2648              {
2649                my ($msg, $acond) =
2650                  $instconds{$val}->ambiguous_p ($val, $full_cond);
2652                if ($msg)
2653                  {
2654                    error ($where, $msg, partial => 1);
2656                    my $dirtxt = "installed in `$dir'";
2657                    $dirtxt = "built for `$dir'"
2658                      if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2659                    my $dircond =
2660                      $full_cond->true ? "" : " in condition $hcond";
2662                    error ($where, "`$val' should be $dirtxt$dircond ...",
2663                           partial => 1);
2665                    my $hacond = $acond->human;
2666                    my $adir = $instdirs{$val}{$acond};
2667                    my $adirtxt = "installed in `$adir'";
2668                    $adirtxt = "built for `$adir'"
2669                      if ($adir eq 'EXTRA' || $adir eq 'noinst'
2670                          || $adir eq 'check');
2671                    my $adircond = $acond->true ? "" : " in condition $hacond";
2673                    my $onlyone = ($dir ne $adir) ?
2674                      ("\nLibtool libraries can be built for only one "
2675                       . "destination.") : "";
2677                    error ($liblocations{$val}{$acond},
2678                           "... and should also be $adirtxt$adircond.$onlyone");
2679                    return;
2680                  }
2681              }
2682            else
2683              {
2684                $instconds{$val} = new Automake::DisjConditions;
2685              }
2686            $instdirs{$val}{$full_cond} = $dir;
2687            $liblocations{$val}{$full_cond} = $where;
2688            $instconds{$val} = $instconds{$val}->merge ($full_cond);
2689          },
2690          sub
2691          {
2692            return ();
2693          },
2694          skip_ac_subst => 1);
2695     }
2697   foreach my $pair (@liblist)
2698     {
2699       my ($where, $onelib) = @$pair;
2701       my $seen_libobjs = 0;
2702       my $obj = get_object_extension '.lo';
2704       # Canonicalize names and check for misspellings.
2705       my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2706                                             '_SOURCES', '_OBJECTS',
2707                                             '_DEPENDENCIES');
2709       # Check that the library fits the standard naming convention.
2710       my $libname_rx = '^lib.*\.la';
2711       my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2712       my $ldvar2 = var ('LDFLAGS');
2713       if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2714           || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2715         {
2716           # Relax name checking for libtool modules.
2717           $libname_rx = '\.la';
2718         }
2720       my $bn = basename ($onelib);
2721       if ($bn !~ /$libname_rx$/)
2722         {
2723           my $type = 'library';
2724           if ($libname_rx eq '\.la')
2725             {
2726               $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2727               $type = 'module';
2728             }
2729           else
2730             {
2731               $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2732             }
2733           my $suggestion = dirname ($onelib) . "/$bn";
2734           $suggestion =~ s|^\./||g;
2735           msg ('error-gnu/warn', $where,
2736                "`$onelib' is not a standard libtool $type name\n"
2737                . "did you mean `$suggestion'?")
2738         }
2740       $where->push_context ("while processing Libtool library `$onelib'");
2741       $where->set (INTERNAL->get);
2743       # Make sure we look at these.
2744       set_seen ($xlib . '_LDFLAGS');
2745       set_seen ($xlib . '_DEPENDENCIES');
2747       # Generate support for conditional object inclusion in
2748       # libraries.
2749       if (var ($xlib . '_LIBADD'))
2750         {
2751           if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2752             {
2753               $seen_libobjs = 1;
2754             }
2755         }
2756       else
2757         {
2758           &define_variable ($xlib . "_LIBADD", '', $where);
2759         }
2761       reject_var ("${xlib}_LDADD",
2762                   "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2765       my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where,
2766                                              NONLIBTOOL => 0, LIBTOOL => 1);
2768       # Determine program to use for link.
2769       my $xlink = &define_per_target_linker_variable ($linker, $xlib);
2771       my $rpathvar = "am_${xlib}_rpath";
2772       my $rpath = "\$($rpathvar)";
2773       foreach my $rcond ($instconds{$onelib}->conds)
2774         {
2775           my $val;
2776           if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2777               || $instdirs{$onelib}{$rcond} eq 'noinst'
2778               || $instdirs{$onelib}{$rcond} eq 'check')
2779             {
2780               # It's an EXTRA_ library, so we can't specify -rpath,
2781               # because we don't know where the library will end up.
2782               # The user probably knows, but generally speaking automake
2783               # doesn't -- and in fact configure could decide
2784               # dynamically between two different locations.
2785               $val = '';
2786             }
2787           else
2788             {
2789               $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2790             }
2791           if ($rcond->true)
2792             {
2793               # If $rcond is true there is only one condition and
2794               # there is no point defining an helper variable.
2795               $rpath = $val;
2796             }
2797           else
2798             {
2799               define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2800             }
2801         }
2803       # If the resulting library lies into a subdirectory,
2804       # make sure this directory will exist.
2805       my $dirstamp = require_build_directory_maybe ($onelib);
2807       # Remember to cleanup .libs/ in this directory.
2808       my $dirname = dirname $onelib;
2809       $libtool_clean_directories{$dirname} = 1;
2811       $output_rules .= &file_contents ('ltlibrary',
2812                                        $where,
2813                                        LTLIBRARY  => $onelib,
2814                                        XLTLIBRARY => $xlib,
2815                                        RPATH      => $rpath,
2816                                        XLINK      => $xlink,
2817                                        DIRSTAMP   => $dirstamp);
2818       if ($seen_libobjs)
2819         {
2820           if (var ($xlib . '_LIBADD'))
2821             {
2822               &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2823             }
2824         }
2825     }
2828 # See if any _SOURCES variable were misspelled.
2829 sub check_typos ()
2831   # It is ok if the user sets this particular variable.
2832   set_seen 'AM_LDFLAGS';
2834   foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
2835     {
2836       foreach my $var (variables $primary)
2837         {
2838           my $varname = $var->name;
2839           # A configure variable is always legitimate.
2840           next if exists $configure_vars{$varname};
2842           for my $cond ($var->conditions->conds)
2843             {
2844               $varname =~ /^(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
2845               msg_var ('syntax', $var, "variable `$varname' is defined but no"
2846                        . " program or\nlibrary has `$1' as canonic name"
2847                        . " (possible typo)")
2848                 unless $var->rdef ($cond)->seen;
2849             }
2850         }
2851     }
2855 # Handle scripts.
2856 sub handle_scripts
2858     # NOTE we no longer automatically clean SCRIPTS, because it is
2859     # useful to sometimes distribute scripts verbatim.  This happens
2860     # e.g. in Automake itself.
2861     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2862                      'bin', 'sbin', 'libexec', 'pkgdata',
2863                      'noinst', 'check');
2869 ## ------------------------ ##
2870 ## Handling Texinfo files.  ##
2871 ## ------------------------ ##
2873 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2874 # &scan_texinfo_file ($FILENAME)
2875 # ------------------------------
2876 # $OUTFILE     - name of the info file produced by $FILENAME.
2877 # $VFILE       - name of the version.texi file used (undef if none).
2878 # @CLEAN_FILES - list of byproducts (indexes etc.)
2879 sub scan_texinfo_file ($)
2881   my ($filename) = @_;
2883   # Some of the following extensions are always created, no matter
2884   # whether indexes are used or not.  Other (like cps, fns, ... pgs)
2885   # are only created when they are used.  We used to scan $FILENAME
2886   # for their use, but that is not enough: they could be used in
2887   # included files.  We can't scan included files because we don't
2888   # know the include path.  Therefore we always erase these files, no
2889   # matter whether they are used or not.
2890   #
2891   # (tmp is only created if an @macro is used and a certain e-TeX
2892   # feature is not available.)
2893   my %clean_suffixes =
2894     map { $_ => 1 } (qw(aux log toc tmp
2895                         cp cps
2896                         fn fns
2897                         ky kys
2898                         vr vrs
2899                         tp tps
2900                         pg pgs)); # grep 'new.*index' texinfo.tex
2902   my $texi = new Automake::XFile "< $filename";
2903   verb "reading $filename";
2905   my ($outfile, $vfile);
2906   while ($_ = $texi->getline)
2907     {
2908       if (/^\@setfilename +(\S+)/)
2909         {
2910           # Honor only the first @setfilename.  (It's possible to have
2911           # more occurrences later if the manual shows examples of how
2912           # to use @setfilename...)
2913           next if $outfile;
2915           $outfile = $1;
2916           if ($outfile =~ /\.([^.]+)$/ && $1 ne 'info')
2917             {
2918               error ("$filename:$.",
2919                      "output `$outfile' has unrecognized extension");
2920               return;
2921             }
2922         }
2923       # A "version.texi" file is actually any file whose name matches
2924       # "vers*.texi".
2925       elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2926         {
2927           $vfile = $1;
2928         }
2930       # Try to find new or unused indexes.
2932       # Creating a new category of index.
2933       elsif (/^\@def(code)?index (\w+)/)
2934         {
2935           $clean_suffixes{$2} = 1;
2936           $clean_suffixes{"$2s"} = 1;
2937         }
2939       # Merging an index into an another.
2940       elsif (/^\@syn(code)?index (\w+) (\w+)/)
2941         {
2942           delete $clean_suffixes{"$2s"};
2943           $clean_suffixes{"$3s"} = 1;
2944         }
2946     }
2948   if (! $outfile)
2949     {
2950       err_am "`$filename' missing \@setfilename";
2951       return;
2952     }
2954   my $infobase = basename ($filename);
2955   $infobase =~ s/\.te?xi(nfo)?$//;
2956   return ($outfile, $vfile,
2957           map { "$infobase.$_" } (sort keys %clean_suffixes));
2961 # ($DIRSTAMP, @CLEAN_FILES)
2962 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
2963 # ------------------------------------------------------------------
2964 # SOURCE - the source Texinfo file
2965 # DEST - the destination Info file
2966 # INSRC - wether DEST should be built in the source tree
2967 # DEPENDENCIES - known dependencies
2968 sub output_texinfo_build_rules ($$$@)
2970   my ($source, $dest, $insrc, @deps) = @_;
2972   # Split `a.texi' into `a' and `.texi'.
2973   my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
2974   my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
2976   $ssfx ||= "";
2977   $dsfx ||= "";
2979   # We can output two kinds of rules: the "generic" rules use Make
2980   # suffix rules and are appropriate when $source and $dest do not lie
2981   # in a sub-directory; the "specific" rules are needed in the other
2982   # case.
2983   #
2984   # The former are output only once (this is not really apparent here,
2985   # but just remember that some logic deeper in Automake will not
2986   # output the same rule twice); while the later need to be output for
2987   # each Texinfo source.
2988   my $generic;
2989   my $makeinfoflags;
2990   my $sdir = dirname $source;
2991   if ($sdir eq '.' && dirname ($dest) eq '.')
2992     {
2993       $generic = 1;
2994       $makeinfoflags = '-I $(srcdir)';
2995     }
2996   else
2997     {
2998       $generic = 0;
2999       $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3000     }
3002   # A directory can contain two kinds of info files: some built in the
3003   # source tree, and some built in the build tree.  The rules are
3004   # different in each case.  However we cannot output two different
3005   # set of generic rules.  Because in-source builds are more usual, we
3006   # use generic rules in this case and fall back to "specific" rules
3007   # for build-dir builds.  (It should not be a problem to invert this
3008   # if needed.)
3009   $generic = 0 unless $insrc;
3011   # We cannot use a suffix rule to build info files with an empty
3012   # extension.  Otherwise we would output a single suffix inference
3013   # rule, with separate dependencies, as in
3014   #
3015   #    .texi:
3016   #             $(MAKEINFO) ...
3017   #    foo.info: foo.texi
3018   #
3019   # which confuse Solaris make.  (See the Autoconf manual for
3020   # details.)  Therefore we use a specific rule in this case.  This
3021   # applies to info files only (dvi and pdf files always have an
3022   # extension).
3023   my $generic_info = ($generic && $dsfx) ? 1 : 0;
3025   # If the resulting file lie into a subdirectory,
3026   # make sure this directory will exist.
3027   my $dirstamp = require_build_directory_maybe ($dest);
3029   my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
3031   $output_rules .= file_contents ('texibuild',
3032                                   new Automake::Location,
3033                                   DEPS             => "@deps",
3034                                   DEST_PREFIX      => $dpfx,
3035                                   DEST_INFO_PREFIX => $dipfx,
3036                                   DEST_SUFFIX      => $dsfx,
3037                                   DIRSTAMP         => $dirstamp,
3038                                   GENERIC          => $generic,
3039                                   GENERIC_INFO     => $generic_info,
3040                                   INSRC            => $insrc,
3041                                   MAKEINFOFLAGS    => $makeinfoflags,
3042                                   SOURCE           => ($generic
3043                                                        ? '$<' : $source),
3044                                   SOURCE_INFO      => ($generic_info
3045                                                        ? '$<' : $source),
3046                                   SOURCE_REAL      => $source,
3047                                   SOURCE_SUFFIX    => $ssfx,
3048                                   );
3049   return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
3053 # $TEXICLEANS
3054 # handle_texinfo_helper ($info_texinfos)
3055 # --------------------------------------
3056 # Handle all Texinfo source; helper for handle_texinfo.
3057 sub handle_texinfo_helper ($)
3059   my ($info_texinfos) = @_;
3060   my (@infobase, @info_deps_list, @texi_deps);
3061   my %versions;
3062   my $done = 0;
3063   my @texi_cleans;
3065   # Build a regex matching user-cleaned files.
3066   my $d = var 'DISTCLEANFILES';
3067   my $c = var 'CLEANFILES';
3068   my @f = ();
3069   push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
3070   push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
3071   @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
3072   my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
3074   foreach my $texi
3075       ($info_texinfos->value_as_list_recursive (inner_expand => 1))
3076     {
3077       my $infobase = $texi;
3078       $infobase =~ s/\.(txi|texinfo|texi)$//;
3080       if ($infobase eq $texi)
3081         {
3082           # FIXME: report line number.
3083           err_am "texinfo file `$texi' has unrecognized extension";
3084           next;
3085         }
3087       push @infobase, $infobase;
3089       # If 'version.texi' is referenced by input file, then include
3090       # automatic versioning capability.
3091       my ($out_file, $vtexi, @clean_files) =
3092         scan_texinfo_file ("$relative_dir/$texi")
3093         or next;
3094       push (@texi_cleans, @clean_files);
3096       # If the Texinfo source is in a subdirectory, create the
3097       # resulting info in this subdirectory.  If it is in the current
3098       # directory, try hard to not prefix "./" because it breaks the
3099       # generic rules.
3100       my $outdir = dirname ($texi) . '/';
3101       $outdir = "" if $outdir eq './';
3102       $out_file =  $outdir . $out_file;
3104       # Until Automake 1.6.3, .info files were built in the
3105       # source tree.  This was an obstacle to the support of
3106       # non-distributed .info files, and non-distributed .texi
3107       # files.
3108       #
3109       # * Non-distributed .texi files is important in some packages
3110       #   where .texi files are built at make time, probably using
3111       #   other binaries built in the package itself, maybe using
3112       #   tools or information found on the build host.  Because
3113       #   these files are not distributed they are always rebuilt
3114       #   at make time; they should therefore not lie in the source
3115       #   directory.  One plan was to support this using
3116       #   nodist_info_TEXINFOS or something similar.  (Doing this
3117       #   requires some sanity checks.  For instance Automake should
3118       #   not allow:
3119       #      dist_info_TEXINFO = foo.texi
3120       #      nodist_foo_TEXINFO = included.texi
3121       #   because a distributed file should never depend on a
3122       #   non-distributed file.)
3123       #
3124       # * If .texi files are not distributed, then .info files should
3125       #   not be distributed either.  There are also cases where one
3126       #   want to distribute .texi files, but do not want to
3127       #   distribute the .info files.  For instance the Texinfo package
3128       #   distributes the tool used to build these files; it would
3129       #   be a waste of space to distribute them.  It's not clear
3130       #   which syntax we should use to indicate that .info files should
3131       #   not be distributed.  Akim Demaille suggested that eventually
3132       #   we switch to a new syntax:
3133       #   |  Maybe we should take some inspiration from what's already
3134       #   |  done in the rest of Automake.  Maybe there is too much
3135       #   |  syntactic sugar here, and you want
3136       #   |     nodist_INFO = bar.info
3137       #   |     dist_bar_info_SOURCES = bar.texi
3138       #   |     bar_texi_DEPENDENCIES = foo.texi
3139       #   |  with a bit of magic to have bar.info represent the whole
3140       #   |  bar*info set.  That's a lot more verbose that the current
3141       #   |  situation, but it is # not new, hence the user has less
3142       #   |  to learn.
3143       #   |
3144       #   |  But there is still too much room for meaningless specs:
3145       #   |     nodist_INFO = bar.info
3146       #   |     dist_bar_info_SOURCES = bar.texi
3147       #   |     dist_PS = bar.ps something-written-by-hand.ps
3148       #   |     nodist_bar_ps_SOURCES = bar.texi
3149       #   |     bar_texi_DEPENDENCIES = foo.texi
3150       #   |  here bar.texi is dist_ in line 2, and nodist_ in 4.
3151       #
3152       # Back to the point, it should be clear that in order to support
3153       # non-distributed .info files, we need to build them in the
3154       # build tree, not in the source tree (non-distributed .texi
3155       # files are less of a problem, because we do not output build
3156       # rules for them).  In Automake 1.7 .info build rules have been
3157       # largely cleaned up so that .info files get always build in the
3158       # build tree, even when distributed.  The idea was that
3159       #   (1) if during a VPATH build the .info file was found to be
3160       #       absent or out-of-date (in the source tree or in the
3161       #       build tree), Make would rebuild it in the build tree.
3162       #       If an up-to-date source-tree of the .info file existed,
3163       #       make would not rebuild it in the build tree.
3164       #   (2) having two copies of .info files, one in the source tree
3165       #       and one (newer) in the build tree is not a problem
3166       #       because `make dist' always pick files in the build tree
3167       #       first.
3168       # However it turned out the be a bad idea for several reasons:
3169       #   * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3170       #     like GNU Make on point (1) above.  These implementations
3171       #     of Make would always rebuild .info files in the build
3172       #     tree, even if such files were up to date in the source
3173       #     tree.  Consequently, it was impossible to perform a VPATH
3174       #     build of a package containing Texinfo files using these
3175       #     Make implementations.
3176       #     (Refer to the Autoconf Manual, section "Limitation of
3177       #     Make", paragraph "VPATH", item "target lookup", for
3178       #     an account of the differences between these
3179       #     implementations.)
3180       #   * The GNU Coding Standards require these files to be built
3181       #     in the source-tree (when they are distributed, that is).
3182       #   * Keeping a fresher copy of distributed files in the
3183       #     build tree can be annoying during development because
3184       #     - if the files is kept under CVS, you really want it
3185       #       to be updated in the source tree
3186       #     - it is confusing that `make distclean' does not erase
3187       #       all files in the build tree.
3188       #
3189       # Consequently, starting with Automake 1.8, .info files are
3190       # built in the source tree again.  Because we still plan to
3191       # support non-distributed .info files at some point, we
3192       # have a single variable ($INSRC) that controls whether
3193       # the current .info file must be built in the source tree
3194       # or in the build tree.  Actually this variable is switched
3195       # off for .info files that appear to be cleaned; this is
3196       # for backward compatibility with package such as Texinfo,
3197       # which do things like
3198       #   info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
3199       #   DISTCLEANFILES = texinfo texinfo-* info*.info*
3200       #   # Do not create info files for distribution.
3201       #   dist-info:
3202       # in order not to distribute .info files.
3203       my $insrc = ($out_file =~ $user_cleaned_files) ? 0 : 1;
3205       my $soutdir = '$(srcdir)/' . $outdir;
3206       $outdir = $soutdir if $insrc;
3208       # If user specified file_TEXINFOS, then use that as explicit
3209       # dependency list.
3210       @texi_deps = ();
3211       push (@texi_deps, "$soutdir$vtexi") if $vtexi;
3213       my $canonical = canonicalize ($infobase);
3214       if (var ($canonical . "_TEXINFOS"))
3215         {
3216           push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3217           push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3218         }
3220       my ($dirstamp, @cfiles) =
3221         output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3222       push (@texi_cleans, @cfiles);
3224       push (@info_deps_list, $out_file);
3226       # If a vers*.texi file is needed, emit the rule.
3227       if ($vtexi)
3228         {
3229           err_am ("`$vtexi', included in `$texi', "
3230                   . "also included in `$versions{$vtexi}'")
3231             if defined $versions{$vtexi};
3232           $versions{$vtexi} = $texi;
3234           # We number the stamp-vti files.  This is doable since the
3235           # actual names don't matter much.  We only number starting
3236           # with the second one, so that the common case looks nice.
3237           my $vti = ($done ? $done : 'vti');
3238           ++$done;
3240           # This is ugly, but it is our historical practice.
3241           if ($config_aux_dir_set_in_configure_ac)
3242             {
3243               require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3244                                             'mdate-sh');
3245             }
3246           else
3247             {
3248               require_file_with_macro (TRUE, 'info_TEXINFOS',
3249                                        FOREIGN, 'mdate-sh');
3250             }
3252           my $conf_dir;
3253           if ($config_aux_dir_set_in_configure_ac)
3254             {
3255               $conf_dir = "$am_config_aux_dir/";
3256             }
3257           else
3258             {
3259               $conf_dir = '$(srcdir)/';
3260             }
3261           $output_rules .= file_contents ('texi-vers',
3262                                           new Automake::Location,
3263                                           TEXI     => $texi,
3264                                           VTI      => $vti,
3265                                           STAMPVTI => "${soutdir}stamp-$vti",
3266                                           VTEXI    => "$soutdir$vtexi",
3267                                           MDDIR    => $conf_dir,
3268                                           DIRSTAMP => $dirstamp);
3269         }
3270     }
3272   # Handle location of texinfo.tex.
3273   my $need_texi_file = 0;
3274   my $texinfodir;
3275   if (var ('TEXINFO_TEX'))
3276     {
3277       # The user defined TEXINFO_TEX so assume he knows what he is
3278       # doing.
3279       $texinfodir = ('$(srcdir)/'
3280                      . dirname (variable_value ('TEXINFO_TEX')));
3281     }
3282   elsif (option 'cygnus')
3283     {
3284       $texinfodir = '$(top_srcdir)/../texinfo';
3285       define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3286     }
3287   elsif ($config_aux_dir_set_in_configure_ac)
3288     {
3289       $texinfodir = $am_config_aux_dir;
3290       define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3291       $need_texi_file = 2; # so that we require_conf_file later
3292     }
3293   else
3294     {
3295       $texinfodir = '$(srcdir)';
3296       $need_texi_file = 1;
3297     }
3298   define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3300   push (@dist_targets, 'dist-info');
3302   if (! option 'no-installinfo')
3303     {
3304       # Make sure documentation is made and installed first.  Use
3305       # $(INFO_DEPS), not 'info', because otherwise recursive makes
3306       # get run twice during "make all".
3307       unshift (@all, '$(INFO_DEPS)');
3308     }
3310   define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3311   define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3312   define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3313   define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3315   # This next isn't strictly needed now -- the places that look here
3316   # could easily be changed to look in info_TEXINFOS.  But this is
3317   # probably better, in case noinst_TEXINFOS is ever supported.
3318   define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3320   # Do some error checking.  Note that this file is not required
3321   # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3322   # up above.
3323   if ($need_texi_file && ! option 'no-texinfo.tex')
3324     {
3325       if ($need_texi_file > 1)
3326         {
3327           require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3328                                         'texinfo.tex');
3329         }
3330       else
3331         {
3332           require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3333                                    'texinfo.tex');
3334         }
3335     }
3337   return makefile_wrap ("", "\t  ", @texi_cleans);
3341 # handle_texinfo ()
3342 # -----------------
3343 # Handle all Texinfo source.
3344 sub handle_texinfo ()
3346   reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
3347   # FIXME: I think this is an obsolete future feature name.
3348   reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3350   my $info_texinfos = var ('info_TEXINFOS');
3351   my $texiclean = "";
3352   if ($info_texinfos)
3353     {
3354       $texiclean = handle_texinfo_helper ($info_texinfos);
3355     }
3356   $output_rules .=  file_contents ('texinfos',
3357                                    new Automake::Location,
3358                                    TEXICLEAN     => $texiclean,
3359                                    'LOCAL-TEXIS' => !!$info_texinfos);
3363 # Handle any man pages.
3364 sub handle_man_pages
3366   reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
3368   # Find all the sections in use.  We do this by first looking for
3369   # "standard" sections, and then looking for any additional
3370   # sections used in man_MANS.
3371   my (%sections, %vlist);
3372   # We handle nodist_ for uniformity.  man pages aren't distributed
3373   # by default so it isn't actually very important.
3374   foreach my $pfx ('', 'dist_', 'nodist_')
3375     {
3376       # Add more sections as needed.
3377       foreach my $section ('0'..'9', 'n', 'l')
3378         {
3379           my $varname = $pfx . 'man' . $section . '_MANS';
3380           if (var ($varname))
3381             {
3382               $sections{$section} = 1;
3383               $varname = '$(' . $varname . ')';
3384               $vlist{$varname} = 1;
3386               &push_dist_common ($varname)
3387                 if $pfx eq 'dist_';
3388             }
3389         }
3391       my $varname = $pfx . 'man_MANS';
3392       my $var = var ($varname);
3393       if ($var)
3394         {
3395           foreach ($var->value_as_list_recursive)
3396             {
3397               # A page like `foo.1c' goes into man1dir.
3398               if (/\.([0-9a-z])([a-z]*)$/)
3399                 {
3400                   $sections{$1} = 1;
3401                 }
3402             }
3404           $varname = '$(' . $varname . ')';
3405           $vlist{$varname} = 1;
3406           &push_dist_common ($varname)
3407             if $pfx eq 'dist_';
3408         }
3409     }
3411   return unless %sections;
3413   # Now for each section, generate an install and uninstall rule.
3414   # Sort sections so output is deterministic.
3415   foreach my $section (sort keys %sections)
3416     {
3417       $output_rules .= &file_contents ('mans',
3418                                        new Automake::Location,
3419                                        SECTION => $section);
3420     }
3422   my @mans = sort keys %vlist;
3423   $output_vars .= file_contents ('mans-vars',
3424                                  new Automake::Location,
3425                                  MANS => "@mans");
3427   push (@all, '$(MANS)')
3428     unless option 'no-installman';
3431 # Handle DATA variables.
3432 sub handle_data
3434     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3435                      'data', 'dataroot', 'dvi', 'html', 'pdf', 'ps',
3436                      'sysconf', 'sharedstate', 'localstate',
3437                      'pkgdata', 'lisp', 'noinst', 'check');
3440 # Handle TAGS.
3441 sub handle_tags
3443     my @tag_deps = ();
3444     my @ctag_deps = ();
3445     if (var ('SUBDIRS'))
3446     {
3447         $output_rules .= ("tags-recursive:\n"
3448                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3449                           # Never fail here if a subdir fails; it
3450                           # isn't important.
3451                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
3452                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3453                           . "\tdone\n");
3454         push (@tag_deps, 'tags-recursive');
3455         &depend ('.PHONY', 'tags-recursive');
3457         $output_rules .= ("ctags-recursive:\n"
3458                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3459                           # Never fail here if a subdir fails; it
3460                           # isn't important.
3461                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
3462                           . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
3463                           . "\tdone\n");
3464         push (@ctag_deps, 'ctags-recursive');
3465         &depend ('.PHONY', 'ctags-recursive');
3466     }
3468     if (&saw_sources_p (1)
3469         || var ('ETAGS_ARGS')
3470         || @tag_deps)
3471     {
3472         my @config;
3473         foreach my $spec (@config_headers)
3474         {
3475             my ($out, @ins) = split_config_file_spec ($spec);
3476             foreach my $in (@ins)
3477               {
3478                 # If the config header source is in this directory,
3479                 # require it.
3480                 push @config, basename ($in)
3481                   if $relative_dir eq dirname ($in);
3482               }
3483         }
3484         $output_rules .= &file_contents ('tags',
3485                                          new Automake::Location,
3486                                          CONFIG    => "@config",
3487                                          TAGSDIRS  => "@tag_deps",
3488                                          CTAGSDIRS => "@ctag_deps");
3490         set_seen 'TAGS_DEPENDENCIES';
3491     }
3492     elsif (reject_var ('TAGS_DEPENDENCIES',
3493                        "doesn't make sense to define `TAGS_DEPENDENCIES'"
3494                        . "without\nsources or `ETAGS_ARGS'"))
3495     {
3496     }
3497     else
3498     {
3499         # Every Makefile must define some sort of TAGS rule.
3500         # Otherwise, it would be possible for a top-level "make TAGS"
3501         # to fail because some subdirectory failed.
3502         $output_rules .= "tags: TAGS\nTAGS:\n\n";
3503         # Ditto ctags.
3504         $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
3505     }
3508 # Handle multilib support.
3509 sub handle_multilib
3511   if ($seen_multilib && $relative_dir eq '.')
3512     {
3513       $output_rules .= &file_contents ('multilib', new Automake::Location);
3514       push (@all, 'all-multi');
3515     }
3519 # user_phony_rule ($NAME)
3520 # -----------------------
3521 # Return false if rule $NAME does not exist.  Otherwise,
3522 # declare it as phony, complete its definition (in case it is
3523 # conditional), and return its Automake::Rule instance.
3524 sub user_phony_rule ($)
3526   my ($name) = @_;
3527   my $rule = rule $name;
3528   if ($rule)
3529     {
3530       depend ('.PHONY', $name);
3531       # Define $NAME in all condition where it is not already defined,
3532       # so that it is always OK to depend on $NAME.
3533       for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3534         {
3535           Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3536                                   $c, INTERNAL);
3537           $output_rules .= $c->subst_string . "$name:\n";
3538         }
3539     }
3540   return $rule;
3544 # $BOOLEAN
3545 # &for_dist_common ($A, $B)
3546 # -------------------------
3547 # Subroutine for &handle_dist: sort files to dist.
3549 # We put README first because it then becomes easier to make a
3550 # Usenet-compliant shar file (in these, README must be first).
3552 # FIXME: do more ordering of files here.
3553 sub for_dist_common
3555     return 0
3556         if $a eq $b;
3557     return -1
3558         if $a eq 'README';
3559     return 1
3560         if $b eq 'README';
3561     return $a cmp $b;
3564 # handle_dist
3565 # -----------
3566 # Handle 'dist' target.
3567 sub handle_dist ()
3569   # Substitutions for distdir.am
3570   my %transform;
3572   # Define DIST_SUBDIRS.  This must always be done, regardless of the
3573   # no-dist setting: target like `distclean' or `maintainer-clean' use it.
3574   my $subdirs = var ('SUBDIRS');
3575   if ($subdirs)
3576     {
3577       # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3578       # to all possible directories, and use it.  If DIST_SUBDIRS is
3579       # defined, just use it.
3581       # Note that we check DIST_SUBDIRS first on purpose, so that
3582       # we don't call has_conditional_contents for now reason.
3583       # (In the past one project used so many conditional subdirectories
3584       # that calling has_conditional_contents on SUBDIRS caused
3585       # automake to grow to 150Mb -- this should not happen with
3586       # the current implementation of has_conditional_contents,
3587       # but it's more efficient to avoid the call anyway.)
3588       if (var ('DIST_SUBDIRS'))
3589         {
3590         }
3591       elsif ($subdirs->has_conditional_contents)
3592         {
3593           define_pretty_variable
3594             ('DIST_SUBDIRS', TRUE, INTERNAL,
3595              uniq ($subdirs->value_as_list_recursive));
3596         }
3597       else
3598         {
3599           # We always define this because that is what `distclean'
3600           # wants.
3601           define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3602                                   '$(SUBDIRS)');
3603         }
3604     }
3606   # The remaining definitions are only required when a dist target is used.
3607   return if option 'no-dist';
3609   # At least one of the archive formats must be enabled.
3610   if ($relative_dir eq '.')
3611     {
3612       my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3613       $archive_defined ||=
3614         grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzma);
3615       error (option 'no-dist-gzip',
3616              "no-dist-gzip specified but no dist-* specified, "
3617              . "at least one archive format must be enabled")
3618         unless $archive_defined;
3619     }
3621   # Look for common files that should be included in distribution.
3622   # If the aux dir is set, and it does not have a Makefile.am, then
3623   # we check for these files there as well.
3624   my $check_aux = 0;
3625   if ($relative_dir eq '.'
3626       && $config_aux_dir_set_in_configure_ac)
3627     {
3628       if (! &is_make_dir ($config_aux_dir))
3629         {
3630           $check_aux = 1;
3631         }
3632     }
3633   foreach my $cfile (@common_files)
3634     {
3635       if (dir_has_case_matching_file ($relative_dir, $cfile)
3636           # The file might be absent, but if it can be built it's ok.
3637           || rule $cfile)
3638         {
3639           &push_dist_common ($cfile);
3640         }
3642       # Don't use `elsif' here because a file might meaningfully
3643       # appear in both directories.
3644       if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3645         {
3646           &push_dist_common ("$config_aux_dir/$cfile")
3647         }
3648     }
3650   # We might copy elements from $configure_dist_common to
3651   # %dist_common if we think we need to.  If the file appears in our
3652   # directory, we would have discovered it already, so we don't
3653   # check that.  But if the file is in a subdir without a Makefile,
3654   # we want to distribute it here if we are doing `.'.  Ugly!
3655   if ($relative_dir eq '.')
3656     {
3657       foreach my $file (split (' ' , $configure_dist_common))
3658         {
3659           push_dist_common ($file)
3660             unless is_make_dir (dirname ($file));
3661         }
3662     }
3664   # Files to distributed.  Don't use ->value_as_list_recursive
3665   # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3666   my @dist_common = split (' ', rvar ('DIST_COMMON')->variable_value);
3667   @dist_common = uniq (sort for_dist_common (@dist_common));
3668   variable_delete 'DIST_COMMON';
3669   define_pretty_variable ('DIST_COMMON', TRUE, INTERNAL, @dist_common);
3671   # Now that we've processed DIST_COMMON, disallow further attempts
3672   # to set it.
3673   $handle_dist_run = 1;
3675   # Scan EXTRA_DIST to see if we need to distribute anything from a
3676   # subdir.  If so, add it to the list.  I didn't want to do this
3677   # originally, but there were so many requests that I finally
3678   # relented.
3679   my $extra_dist = var ('EXTRA_DIST');
3681   $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3682   $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3684   # If the target `dist-hook' exists, make sure it is run.  This
3685   # allows users to do random weird things to the distribution
3686   # before it is packaged up.
3687   push (@dist_targets, 'dist-hook')
3688     if user_phony_rule 'dist-hook';
3689   $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3691   my $flm = option ('filename-length-max');
3692   my $filename_filter = $flm ? '.' x $flm->[1] : '';
3694   $output_rules .= &file_contents ('distdir',
3695                                    new Automake::Location,
3696                                    %transform,
3697                                    FILENAME_FILTER => $filename_filter);
3701 # check_directory ($NAME, $WHERE)
3702 # -------------------------------
3703 # Ensure $NAME is a directory, and that it uses sane name.
3704 # Use $WHERE as a location in the diagnostic, if any.
3705 sub check_directory ($$)
3707   my ($dir, $where) = @_;
3709   error $where, "required directory $relative_dir/$dir does not exist"
3710     unless -d "$relative_dir/$dir";
3712   # If an `obj/' directory exists, BSD make will enter it before
3713   # reading `Makefile'.  Hence the `Makefile' in the current directory
3714   # will not be read.
3715   #
3716   #  % cat Makefile
3717   #  all:
3718   #          echo Hello
3719   #  % cat obj/Makefile
3720   #  all:
3721   #          echo World
3722   #  % make      # GNU make
3723   #  echo Hello
3724   #  Hello
3725   #  % pmake     # BSD make
3726   #  echo World
3727   #  World
3728   msg ('portability', $where,
3729        "naming a subdirectory `obj' causes troubles with BSD make")
3730     if $dir eq 'obj';
3732   # `aux' is probably the most important of the following forbidden name,
3733   # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3734   msg ('portability', $where,
3735        "name `$dir' is reserved on W32 and DOS platforms")
3736     if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3739 # check_directories_in_var ($VARIABLE)
3740 # ------------------------------------
3741 # Recursively check all items in variables $VARIABLE as directories
3742 sub check_directories_in_var ($)
3744   my ($var) = @_;
3745   $var->traverse_recursively
3746     (sub
3747      {
3748        my ($var, $val, $cond, $full_cond) = @_;
3749        check_directory ($val, $var->rdef ($cond)->location);
3750        return ();
3751      },
3752      undef,
3753      skip_ac_subst => 1);
3756 # &handle_subdirs ()
3757 # ------------------
3758 # Handle subdirectories.
3759 sub handle_subdirs ()
3761   my $subdirs = var ('SUBDIRS');
3762   return
3763     unless $subdirs;
3765   check_directories_in_var $subdirs;
3767   my $dsubdirs = var ('DIST_SUBDIRS');
3768   check_directories_in_var $dsubdirs
3769     if $dsubdirs;
3771   $output_rules .= &file_contents ('subdirs', new Automake::Location);
3772   rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3776 # ($REGEN, @DEPENDENCIES)
3777 # &scan_aclocal_m4
3778 # ----------------
3779 # If aclocal.m4 creation is automated, return the list of its dependencies.
3780 sub scan_aclocal_m4 ()
3782   my $regen_aclocal = 0;
3784   set_seen 'CONFIG_STATUS_DEPENDENCIES';
3785   set_seen 'CONFIGURE_DEPENDENCIES';
3787   if (-f 'aclocal.m4')
3788     {
3789       &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3791       my $aclocal = new Automake::XFile "< aclocal.m4";
3792       my $line = $aclocal->getline;
3793       $regen_aclocal = $line =~ 'generated automatically by aclocal';
3794     }
3796   my @ac_deps = ();
3798   if (set_seen ('ACLOCAL_M4_SOURCES'))
3799     {
3800       push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3801       msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
3802                "`ACLOCAL_M4_SOURCES' is obsolete.\n"
3803                . "It should be safe to simply remove it.");
3804     }
3806   # Note that it might be possible that aclocal.m4 doesn't exist but
3807   # should be auto-generated.  This case probably isn't very
3808   # important.
3810   return ($regen_aclocal, @ac_deps);
3814 # Helper function for substitute_ac_subst_variables.
3815 sub substitute_ac_subst_variables_worker($)
3817   my ($token) = @_;
3818   return "\@$token\@" if var $token;
3819   return "\${$token\}";
3822 # substitute_ac_subst_variables ($TEXT)
3823 # -------------------------------------
3824 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
3825 # variable.
3826 sub substitute_ac_subst_variables ($)
3828   my ($text) = @_;
3829   $text =~ s/\${([^ \t=:+{}]+)}/&substitute_ac_subst_variables_worker ($1)/ge;
3830   return $text;
3833 # @DEPENDENCIES
3834 # &prepend_srcdir (@INPUTS)
3835 # -------------------------
3836 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS.  The idea is that
3837 # if an input file has a directory part the same as the current
3838 # directory, then the directory part is simply replaced by $(srcdir).
3839 # But if the directory part is different, then $(top_srcdir) is
3840 # prepended.
3841 sub prepend_srcdir (@)
3843   my (@inputs) = @_;
3844   my @newinputs;
3846   foreach my $single (@inputs)
3847     {
3848       if (dirname ($single) eq $relative_dir)
3849         {
3850           push (@newinputs, '$(srcdir)/' . basename ($single));
3851         }
3852       else
3853         {
3854           push (@newinputs, '$(top_srcdir)/' . $single);
3855         }
3856     }
3857   return @newinputs;
3860 # @DEPENDENCIES
3861 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
3862 # ---------------------------------------------------
3863 # Compute a list of dependencies appropriate for the rebuild
3864 # rule of
3865 #   AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
3866 # Also distribute $INPUTs which are not build by another AC_CONFIG_FILES.
3867 sub rewrite_inputs_into_dependencies ($@)
3869   my ($file, @inputs) = @_;
3870   my @res = ();
3872   for my $i (@inputs)
3873     {
3874       # We cannot create dependencies on shell variables.
3875       next if (substitute_ac_subst_variables $i) =~ /\$/;
3877       if (exists $ac_config_files_location{$i})
3878         {
3879           my $di = dirname $i;
3880           if ($di eq $relative_dir)
3881             {
3882               $i = basename $i;
3883             }
3884           # In the top-level Makefile we do not use $(top_builddir), because
3885           # we are already there, and since the targets are built without
3886           # a $(top_builddir), it helps BSD Make to match them with
3887           # dependencies.
3888           elsif ($relative_dir ne '.')
3889             {
3890               $i = '$(top_builddir)/' . $i;
3891             }
3892         }
3893       else
3894         {
3895           msg ('error', $ac_config_files_location{$file},
3896                "required file `$i' not found")
3897             unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
3898           ($i) = prepend_srcdir ($i);
3899           push_dist_common ($i);
3900         }
3901       push @res, $i;
3902     }
3903   return @res;
3908 # &handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
3909 # ------------------------------------------------------------------
3910 # Handle remaking and configure stuff.
3911 # We need the name of the input file, to do proper remaking rules.
3912 sub handle_configure ($$$@)
3914   my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
3916   prog_error 'empty @inputs'
3917     unless @inputs;
3919   my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
3920                                                             $makefile_in);
3921   my $rel_makefile = basename $makefile;
3923   my $colon_infile = ':' . join (':', @inputs);
3924   $colon_infile = '' if $colon_infile eq ":$makefile.in";
3925   my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
3926   my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
3927   define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
3928                           @configure_deps, @aclocal_m4_deps,
3929                           '$(top_srcdir)/' . $configure_ac);
3930   my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
3931   push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
3932   define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
3933                           @configuredeps);
3935   $output_rules .= file_contents
3936     ('configure',
3937      new Automake::Location,
3938      MAKEFILE              => $rel_makefile,
3939      'MAKEFILE-DEPS'       => "@rewritten",
3940      'CONFIG-MAKEFILE'     => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
3941      'MAKEFILE-IN'         => $rel_makefile_in,
3942      'MAKEFILE-IN-DEPS'    => "@include_stack",
3943      'MAKEFILE-AM'         => $rel_makefile_am,
3944      STRICTNESS            => global_option 'cygnus'
3945                                 ? 'cygnus' : $strictness_name,
3946      'USE-DEPS'            => global_option 'no-dependencies'
3947                                 ? ' --ignore-deps' : '',
3948      'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
3949      'REGEN-ACLOCAL-M4'    => $regen_aclocal_m4);
3951   if ($relative_dir eq '.')
3952     {
3953       &push_dist_common ('acconfig.h')
3954         if -f 'acconfig.h';
3955     }
3957   # If we have a configure header, require it.
3958   my $hdr_index = 0;
3959   my @distclean_config;
3960   foreach my $spec (@config_headers)
3961     {
3962       $hdr_index += 1;
3963       # $CONFIG_H_PATH: config.h from top level.
3964       my ($config_h_path, @ins) = split_config_file_spec ($spec);
3965       my $config_h_dir = dirname ($config_h_path);
3967       # If the header is in the current directory we want to build
3968       # the header here.  Otherwise, if we're at the topmost
3969       # directory and the header's directory doesn't have a
3970       # Makefile, then we also want to build the header.
3971       if ($relative_dir eq $config_h_dir
3972           || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
3973         {
3974           my ($cn_sans_dir, $stamp_dir);
3975           if ($relative_dir eq $config_h_dir)
3976             {
3977               $cn_sans_dir = basename ($config_h_path);
3978               $stamp_dir = '';
3979             }
3980           else
3981             {
3982               $cn_sans_dir = $config_h_path;
3983               if ($config_h_dir eq '.')
3984                 {
3985                   $stamp_dir = '';
3986                 }
3987               else
3988                 {
3989                   $stamp_dir = $config_h_dir . '/';
3990                 }
3991             }
3993           # This will also distribute all inputs.
3994           @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
3996           # Cannot define rebuild rules for filenames with shell variables.
3997           next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
3999           # Header defined in this directory.
4000           my @files;
4001           if (-f $config_h_path . '.top')
4002             {
4003               push (@files, "$cn_sans_dir.top");
4004             }
4005           if (-f $config_h_path . '.bot')
4006             {
4007               push (@files, "$cn_sans_dir.bot");
4008             }
4010           push_dist_common (@files);
4012           # For now, acconfig.h can only appear in the top srcdir.
4013           if (-f 'acconfig.h')
4014             {
4015               push (@files, '$(top_srcdir)/acconfig.h');
4016             }
4018           my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4019           $output_rules .=
4020             file_contents ('remake-hdr',
4021                            new Automake::Location,
4022                            FILES            => "@files",
4023                            CONFIG_H         => $cn_sans_dir,
4024                            CONFIG_HIN       => $ins[0],
4025                            CONFIG_H_DEPS    => "@ins",
4026                            CONFIG_H_PATH    => $config_h_path,
4027                            STAMP            => "$stamp");
4029           push @distclean_config, $cn_sans_dir, $stamp;
4030         }
4031     }
4033   $output_rules .= file_contents ('clean-hdr',
4034                                   new Automake::Location,
4035                                   FILES => "@distclean_config")
4036     if @distclean_config;
4038   # Distribute and define mkinstalldirs only if it is already present
4039   # in the package, for backward compatibility (some people may still
4040   # use $(mkinstalldirs)).
4041   my $mkidpath = "$config_aux_dir/mkinstalldirs";
4042   if (-f $mkidpath)
4043     {
4044       # Use require_file so that any existing script gets updated
4045       # by --force-missing.
4046       require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
4047       define_variable ('mkinstalldirs',
4048                        "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
4049     }
4050   else
4051     {
4052       # Use $(install_sh), not $(MKDIR_P) because the latter requires
4053       # at least one argument, and $(mkinstalldirs) used to work
4054       # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
4055       define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
4056     }
4058   reject_var ('CONFIG_HEADER',
4059               "`CONFIG_HEADER' is an anachronism; now determined "
4060               . "automatically\nfrom `$configure_ac'");
4062   my @config_h;
4063   foreach my $spec (@config_headers)
4064     {
4065       my ($out, @ins) = split_config_file_spec ($spec);
4066       # Generate CONFIG_HEADER define.
4067       if ($relative_dir eq dirname ($out))
4068         {
4069           push @config_h, basename ($out);
4070         }
4071       else
4072         {
4073           push @config_h, "\$(top_builddir)/$out";
4074         }
4075     }
4076   define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
4077     if @config_h;
4079   # Now look for other files in this directory which must be remade
4080   # by config.status, and generate rules for them.
4081   my @actual_other_files = ();
4082   foreach my $lfile (@other_input_files)
4083     {
4084       my $file;
4085       my @inputs;
4086       if ($lfile =~ /^([^:]*):(.*)$/)
4087         {
4088           # This is the ":" syntax of AC_OUTPUT.
4089           $file = $1;
4090           @inputs = split (':', $2);
4091         }
4092       else
4093         {
4094           # Normal usage.
4095           $file = $lfile;
4096           @inputs = $file . '.in';
4097         }
4099       # Automake files should not be stored in here, but in %MAKE_LIST.
4100       prog_error ("$lfile in \@other_input_files\n"
4101                   . "\@other_input_files = (@other_input_files)")
4102         if -f $file . '.am';
4104       my $local = basename ($file);
4106       # We skip files that aren't in this directory.  However, if
4107       # the file's directory does not have a Makefile, and we are
4108       # currently doing `.', then we create a rule to rebuild the
4109       # file in the subdir.
4110       my $fd = dirname ($file);
4111       if ($fd ne $relative_dir)
4112         {
4113           if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4114             {
4115               $local = $file;
4116             }
4117           else
4118             {
4119               next;
4120             }
4121         }
4123       my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4125       # Cannot output rules for shell variables.
4126       next if (substitute_ac_subst_variables $local) =~ /\$/;
4128       $output_rules .= ($local . ': '
4129                         . '$(top_builddir)/config.status '
4130                         . "@rewritten_inputs\n"
4131                         . "\t"
4132                         . 'cd $(top_builddir) && '
4133                         . '$(SHELL) ./config.status '
4134                         . ($relative_dir eq '.' ? '' : '$(subdir)/')
4135                         . '$@'
4136                         . "\n");
4137       push (@actual_other_files, $local);
4138     }
4140   # For links we should clean destinations and distribute sources.
4141   foreach my $spec (@config_links)
4142     {
4143       my ($link, $file) = split /:/, $spec;
4144       # Some people do AC_CONFIG_LINKS($computed).  We only handle
4145       # the DEST:SRC form.
4146       next unless $file;
4147       my $where = $ac_config_files_location{$link};
4149       # Skip destinations that contain shell variables.
4150       if ((substitute_ac_subst_variables $link) !~ /\$/)
4151         {
4152           # We skip links that aren't in this directory.  However, if
4153           # the link's directory does not have a Makefile, and we are
4154           # currently doing `.', then we add the link to CONFIG_CLEAN_FILES
4155           # in `.'s Makefile.in.
4156           my $local = basename ($link);
4157           my $fd = dirname ($link);
4158           if ($fd ne $relative_dir)
4159             {
4160               if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4161                 {
4162                   $local = $link;
4163                 }
4164               else
4165                 {
4166                   $local = undef;
4167                 }
4168             }
4169           push @actual_other_files, $local if $local;
4170         }
4172       # Do not process sources that contain shell variables.
4173       if ((substitute_ac_subst_variables $file) !~ /\$/)
4174         {
4175           my $fd = dirname ($file);
4177           # We distribute files that are in this directory.
4178           # At the top-level (`.') we also distribute files whose
4179           # directory does not have a Makefile.
4180           if (($fd eq $relative_dir)
4181               || ($relative_dir eq '.' && ! &is_make_dir ($fd)))
4182             {
4183               # The following will distribute $file as a side-effect when
4184               # it is appropriate (i.e., when $file is not already an output).
4185               # We do not need the result, just the side-effect.
4186               rewrite_inputs_into_dependencies ($link, $file);
4187             }
4188         }
4189     }
4191   # These files get removed by "make distclean".
4192   define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4193                           @actual_other_files);
4196 # Handle C headers.
4197 sub handle_headers
4199     my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4200                              'oldinclude', 'pkginclude',
4201                              'noinst', 'check');
4202     foreach (@r)
4203     {
4204       next unless $_->[1] =~ /\..*$/;
4205       &saw_extension ($&);
4206     }
4209 sub handle_gettext
4211   return if ! $seen_gettext || $relative_dir ne '.';
4213   my $subdirs = var 'SUBDIRS';
4215   if (! $subdirs)
4216     {
4217       err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4218       return;
4219     }
4221   # Perform some sanity checks to help users get the right setup.
4222   # We disable these tests when po/ doesn't exist in order not to disallow
4223   # unusual gettext setups.
4224   #
4225   # Bruno Haible:
4226   # | The idea is:
4227   # |
4228   # |  1) If a package doesn't have a directory po/ at top level, it
4229   # |     will likely have multiple po/ directories in subpackages.
4230   # |
4231   # |  2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4232   # |     is used without 'external'. It is also useful to warn for the
4233   # |     presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4234   # |     warnings apply only to the usual layout of packages, therefore
4235   # |     they should both be disabled if no po/ directory is found at
4236   # |     top level.
4238   if (-d 'po')
4239     {
4240       my @subdirs = $subdirs->value_as_list_recursive;
4242       msg_var ('syntax', $subdirs,
4243                "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4244         if ! grep ($_ eq 'po', @subdirs);
4246       # intl/ is not required when AM_GNU_GETTEXT is called with the
4247       # `external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
4248       msg_var ('syntax', $subdirs,
4249                "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4250         if (! ($seen_gettext_external && ! $seen_gettext_intl)
4251             && ! grep ($_ eq 'intl', @subdirs));
4253       # intl/ should not be used with AM_GNU_GETTEXT([external]), except
4254       # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
4255       msg_var ('syntax', $subdirs,
4256                "`intl' should not be in SUBDIRS when "
4257                . "AM_GNU_GETTEXT([external]) is used")
4258         if ($seen_gettext_external && ! $seen_gettext_intl
4259             && grep ($_ eq 'intl', @subdirs));
4260     }
4262   require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4265 # Handle footer elements.
4266 sub handle_footer
4268     reject_rule ('.SUFFIXES',
4269                  "use variable `SUFFIXES', not target `.SUFFIXES'");
4271     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4272     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
4273     # anything else, by sticking it right after the default: target.
4274     $output_header .= ".SUFFIXES:\n";
4275     my $suffixes = var 'SUFFIXES';
4276     my @suffixes = Automake::Rule::suffixes;
4277     if (@suffixes || $suffixes)
4278     {
4279         # Make sure SUFFIXES has unique elements.  Sort them to ensure
4280         # the output remains consistent.  However, $(SUFFIXES) is
4281         # always at the start of the list, unsorted.  This is done
4282         # because make will choose rules depending on the ordering of
4283         # suffixes, and this lets the user have some control.  Push
4284         # actual suffixes, and not $(SUFFIXES).  Some versions of make
4285         # do not like variable substitutions on the .SUFFIXES line.
4286         my @user_suffixes = ($suffixes
4287                              ? $suffixes->value_as_list_recursive : ());
4289         my %suffixes = map { $_ => 1 } @suffixes;
4290         delete @suffixes{@user_suffixes};
4292         $output_header .= (".SUFFIXES: "
4293                            . join (' ', @user_suffixes, sort keys %suffixes)
4294                            . "\n");
4295     }
4297     $output_trailer .= file_contents ('footer', new Automake::Location);
4301 # Generate `make install' rules.
4302 sub handle_install ()
4304   $output_rules .= &file_contents
4305     ('install',
4306      new Automake::Location,
4307      maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4308                              ? (" \$(BUILT_SOURCES)\n"
4309                                 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4310                              : ''),
4311      'installdirs-local' => (user_phony_rule 'installdirs-local'
4312                              ? ' installdirs-local' : ''),
4313      am__installdirs => variable_value ('am__installdirs') || '');
4317 # Deal with all and all-am.
4318 sub handle_all ($)
4320     my ($makefile) = @_;
4322     # Output `all-am'.
4324     # Put this at the beginning for the sake of non-GNU makes.  This
4325     # is still wrong if these makes can run parallel jobs.  But it is
4326     # right enough.
4327     unshift (@all, basename ($makefile));
4329     foreach my $spec (@config_headers)
4330       {
4331         my ($out, @ins) = split_config_file_spec ($spec);
4332         push (@all, basename ($out))
4333           if dirname ($out) eq $relative_dir;
4334       }
4336     # Install `all' hooks.
4337     push (@all, "all-local")
4338       if user_phony_rule "all-local";
4340     &pretty_print_rule ("all-am:", "\t\t", @all);
4341     &depend ('.PHONY', 'all-am', 'all');
4344     # Output `all'.
4346     my @local_headers = ();
4347     push @local_headers, '$(BUILT_SOURCES)'
4348       if var ('BUILT_SOURCES');
4349     foreach my $spec (@config_headers)
4350       {
4351         my ($out, @ins) = split_config_file_spec ($spec);
4352         push @local_headers, basename ($out)
4353           if dirname ($out) eq $relative_dir;
4354       }
4356     if (@local_headers)
4357       {
4358         # We need to make sure config.h is built before we recurse.
4359         # We also want to make sure that built sources are built
4360         # before any ordinary `all' targets are run.  We can't do this
4361         # by changing the order of dependencies to the "all" because
4362         # that breaks when using parallel makes.  Instead we handle
4363         # things explicitly.
4364         $output_all .= ("all: @local_headers"
4365                         . "\n\t"
4366                         . '$(MAKE) $(AM_MAKEFLAGS) '
4367                         . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4368                         . "\n\n");
4369       }
4370     else
4371       {
4372         $output_all .= "all: " . (var ('SUBDIRS')
4373                                   ? 'all-recursive' : 'all-am') . "\n\n";
4374       }
4378 # &do_check_merge_target ()
4379 # -------------------------
4380 # Handle check merge target specially.
4381 sub do_check_merge_target ()
4383   # Include user-defined local form of target.
4384   push @check_tests, 'check-local'
4385     if user_phony_rule 'check-local';
4387   # In --cygnus mode, check doesn't depend on all.
4388   if (option 'cygnus')
4389     {
4390       # Just run the local check rules.
4391       pretty_print_rule ('check-am:', "\t\t", @check);
4392     }
4393   else
4394     {
4395       # The check target must depend on the local equivalent of
4396       # `all', to ensure all the primary targets are built.  Then it
4397       # must build the local check rules.
4398       $output_rules .= "check-am: all-am\n";
4399       pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4400                          @check)
4401         if @check;
4402     }
4403   pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4404                      @check_tests)
4405     if @check_tests;
4407   depend '.PHONY', 'check', 'check-am';
4408   # Handle recursion.  We have to honor BUILT_SOURCES like for `all:'.
4409   $output_rules .= ("check: "
4410                     . (var ('BUILT_SOURCES')
4411                        ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4412                        : '')
4413                     . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4414                     . "\n");
4417 # handle_clean ($MAKEFILE)
4418 # ------------------------
4419 # Handle all 'clean' targets.
4420 sub handle_clean ($)
4422   my ($makefile) = @_;
4424   # Clean the files listed in user variables if they exist.
4425   $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4426     if var ('MOSTLYCLEANFILES');
4427   $clean_files{'$(CLEANFILES)'} = CLEAN
4428     if var ('CLEANFILES');
4429   $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4430     if var ('DISTCLEANFILES');
4431   $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4432     if var ('MAINTAINERCLEANFILES');
4434   # Built sources are automatically removed by maintainer-clean.
4435   $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4436     if var ('BUILT_SOURCES');
4438   # Compute a list of "rm"s to run for each target.
4439   my %rms = (MOSTLY_CLEAN, [],
4440              CLEAN, [],
4441              DIST_CLEAN, [],
4442              MAINTAINER_CLEAN, []);
4444   foreach my $file (keys %clean_files)
4445     {
4446       my $when = $clean_files{$file};
4447       prog_error 'invalid entry in %clean_files'
4448         unless exists $rms{$when};
4450       my $rm = "rm -f $file";
4451       # If file is a variable, make sure when don't call `rm -f' without args.
4452       $rm ="test -z \"$file\" || $rm"
4453         if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4455       push @{$rms{$when}}, "\t-$rm\n";
4456     }
4458   $output_rules .= &file_contents
4459     ('clean',
4460      new Automake::Location,
4461      MOSTLYCLEAN_RMS      => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4462      CLEAN_RMS            => join ('', sort @{$rms{&CLEAN}}),
4463      DISTCLEAN_RMS        => join ('', sort @{$rms{&DIST_CLEAN}}),
4464      MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4465      MAKEFILE             => basename $makefile,
4466      );
4470 # &target_cmp ($A, $B)
4471 # --------------------
4472 # Subroutine for &handle_factored_dependencies to let `.PHONY' and
4473 # other `.TARGETS' be last.
4474 sub target_cmp
4476   return 0 if $a eq $b;
4478   my $a1 = substr ($a, 0, 1);
4479   my $b1 = substr ($b, 0, 1);
4480   if ($a1 ne $b1)
4481     {
4482       return -1 if $b1 eq '.';
4483       return 1 if $a1 eq '.';
4484     }
4485   return $a cmp $b;
4489 # &handle_factored_dependencies ()
4490 # --------------------------------
4491 # Handle everything related to gathered targets.
4492 sub handle_factored_dependencies
4494   # Reject bad hooks.
4495   foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4496                      'uninstall-exec-local', 'uninstall-exec-hook',
4497                      'uninstall-dvi-local',
4498                      'uninstall-html-local',
4499                      'uninstall-info-local',
4500                      'uninstall-pdf-local',
4501                      'uninstall-ps-local')
4502     {
4503       my $x = $utarg;
4504       $x =~ s/-.*-/-/;
4505       reject_rule ($utarg, "use `$x', not `$utarg'");
4506     }
4508   reject_rule ('install-local',
4509                "use `install-data-local' or `install-exec-local', "
4510                . "not `install-local'");
4512   reject_rule ('install-hook',
4513                "use `install-data-hook' or `install-exec-hook', "
4514                . "not `install-hook'");
4516   # Install the -local hooks.
4517   foreach (keys %dependencies)
4518     {
4519       # Hooks are installed on the -am targets.
4520       s/-am$// or next;
4521       depend ("$_-am", "$_-local")
4522         if user_phony_rule "$_-local";
4523     }
4525   # Install the -hook hooks.
4526   # FIXME: Why not be as liberal as we are with -local hooks?
4527   foreach ('install-exec', 'install-data', 'uninstall')
4528     {
4529       if (user_phony_rule "$_-hook")
4530         {
4531           depend ('.MAKE', "$_-am");
4532           register_action("$_-am",
4533                           ("\t\@\$(NORMAL_INSTALL)\n"
4534                            . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
4535         }
4536     }
4538   # All the required targets are phony.
4539   depend ('.PHONY', keys %required_targets);
4541   # Actually output gathered targets.
4542   foreach (sort target_cmp keys %dependencies)
4543     {
4544       # If there is nothing about this guy, skip it.
4545       next
4546         unless (@{$dependencies{$_}}
4547                 || $actions{$_}
4548                 || $required_targets{$_});
4550       # Define gathered targets in undefined conditions.
4551       # FIXME: Right now we must handle .PHONY as an exception,
4552       # because people write things like
4553       #    .PHONY: myphonytarget
4554       # to append dependencies.  This would not work if Automake
4555       # refrained from defining its own .PHONY target as it does
4556       # with other overridden targets.
4557       # Likewise for `.MAKE'.
4558       my @undefined_conds = (TRUE,);
4559       if ($_ ne '.PHONY' && $_ ne '.MAKE')
4560         {
4561           @undefined_conds =
4562             Automake::Rule::define ($_, 'internal',
4563                                     RULE_AUTOMAKE, TRUE, INTERNAL);
4564         }
4565       my @uniq_deps = uniq (sort @{$dependencies{$_}});
4566       foreach my $cond (@undefined_conds)
4567         {
4568           my $condstr = $cond->subst_string;
4569           &pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4570           $output_rules .= $actions{$_} if defined $actions{$_};
4571           $output_rules .= "\n";
4572         }
4573     }
4577 # &handle_tests_dejagnu ()
4578 # ------------------------
4579 sub handle_tests_dejagnu
4581     push (@check_tests, 'check-DEJAGNU');
4582     $output_rules .= file_contents ('dejagnu', new Automake::Location);
4586 # Handle TESTS variable and other checks.
4587 sub handle_tests
4589   if (option 'dejagnu')
4590     {
4591       &handle_tests_dejagnu;
4592     }
4593   else
4594     {
4595       foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4596         {
4597           reject_var ($c, "`$c' defined but `dejagnu' not in "
4598                       . "`AUTOMAKE_OPTIONS'");
4599         }
4600     }
4602   if (var ('TESTS'))
4603     {
4604       push (@check_tests, 'check-TESTS');
4605       $output_rules .= &file_contents ('check', new Automake::Location,
4606                                        COLOR => !! option 'color-tests');
4608       # Tests that are known programs should have $(EXEEXT) appended.
4609       # For matching purposes, we need to adjust XFAIL_TESTS as well.
4610       append_exeext { exists $known_programs{$_[0]} } 'TESTS';
4611       append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
4612         if (var ('XFAIL_TESTS'));
4613     }
4616 # Handle Emacs Lisp.
4617 sub handle_emacs_lisp
4619   my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4620                                  'lisp', 'noinst');
4622   return if ! @elfiles;
4624   define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
4625                           map { $_->[1] } @elfiles);
4626   define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
4627                           '$(am__ELFILES:.el=.elc)');
4628   # This one can be overridden by users.
4629   define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
4631   push @all, '$(ELCFILES)';
4633   require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
4634                      'EMACS', 'lispdir');
4635   require_conf_file ($elfiles[0][0], FOREIGN, 'elisp-comp');
4636   &define_variable ('elisp_comp', "$am_config_aux_dir/elisp-comp", INTERNAL);
4639 # Handle Python
4640 sub handle_python
4642   my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4643                                  'noinst');
4644   return if ! @pyfiles;
4646   require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
4647   require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
4648   &define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
4651 # Handle Java.
4652 sub handle_java
4654     my @sourcelist = &am_install_var ('-candist',
4655                                       'java', 'JAVA',
4656                                       'java', 'noinst', 'check');
4657     return if ! @sourcelist;
4659     my @prefix = am_primary_prefixes ('JAVA', 1,
4660                                       'java', 'noinst', 'check');
4662     my $dir;
4663     foreach my $curs (@prefix)
4664       {
4665         next
4666           if $curs eq 'EXTRA';
4668         err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
4669           if defined $dir;
4670         $dir = $curs;
4671       }
4674     push (@all, 'class' . $dir . '.stamp');
4678 # Handle some of the minor options.
4679 sub handle_minor_options
4681   if (option 'readme-alpha')
4682     {
4683       if ($relative_dir eq '.')
4684         {
4685           if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4686             {
4687               msg ('error-gnits', $package_version_location,
4688                    "version `$package_version' doesn't follow " .
4689                    "Gnits standards");
4690             }
4691           if (defined $1 && -f 'README-alpha')
4692             {
4693               # This means we have an alpha release.  See
4694               # GNITS_VERSION_PATTERN for details.
4695               push_dist_common ('README-alpha');
4696             }
4697         }
4698     }
4701 ################################################################
4703 # ($OUTPUT, @INPUTS)
4704 # &split_config_file_spec ($SPEC)
4705 # -------------------------------
4706 # Decode the Autoconf syntax for config files (files, headers, links
4707 # etc.).
4708 sub split_config_file_spec ($)
4710   my ($spec) = @_;
4711   my ($output, @inputs) = split (/:/, $spec);
4713   push @inputs, "$output.in"
4714     unless @inputs;
4716   return ($output, @inputs);
4719 # $input
4720 # locate_am (@POSSIBLE_SOURCES)
4721 # -----------------------------
4722 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
4723 # This functions returns the first *.in file for which a *.am exists.
4724 # It returns undef otherwise.
4725 sub locate_am (@)
4727   my (@rest) = @_;
4728   my $input;
4729   foreach my $file (@rest)
4730     {
4731       if (($file =~ /^(.*)\.in$/) && -f "$1.am")
4732         {
4733           $input = $file;
4734           last;
4735         }
4736     }
4737   return $input;
4740 my %make_list;
4742 # &scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
4743 # ---------------------------------------------------
4744 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4745 # (or AC_OUTPUT).
4746 sub scan_autoconf_config_files ($$)
4748   my ($where, $config_files) = @_;
4750   # Look at potential Makefile.am's.
4751   foreach (split ' ', $config_files)
4752     {
4753       # Must skip empty string for Perl 4.
4754       next if $_ eq "\\" || $_ eq '';
4756       # Handle $local:$input syntax.
4757       my ($local, @rest) = split (/:/);
4758       @rest = ("$local.in",) unless @rest;
4759       msg ('portability', $where,
4760           "Omit leading `./' from config file names such as `$local',"
4761           . "\nas not all make implementations treat `file' and `./file' equally.")
4762         if ($local =~ /^\.\//);
4763       my $input = locate_am @rest;
4764       if ($input)
4765         {
4766           # We have a file that automake should generate.
4767           $make_list{$input} = join (':', ($local, @rest));
4768         }
4769       else
4770         {
4771           # We have a file that automake should cause to be
4772           # rebuilt, but shouldn't generate itself.
4773           push (@other_input_files, $_);
4774         }
4775       $ac_config_files_location{$local} = $where;
4776     }
4780 # &scan_autoconf_traces ($FILENAME)
4781 # ---------------------------------
4782 sub scan_autoconf_traces ($)
4784   my ($filename) = @_;
4786   # Macros to trace, with their minimal number of arguments.
4787   #
4788   # IMPORTANT: If you add a macro here, you should also add this macro
4789   # =========  to Automake-preselection in autoconf/lib/autom4te.in.
4790   my %traced = (
4791                 AC_CANONICAL_BUILD => 0,
4792                 AC_CANONICAL_HOST => 0,
4793                 AC_CANONICAL_TARGET => 0,
4794                 AC_CONFIG_AUX_DIR => 1,
4795                 AC_CONFIG_FILES => 1,
4796                 AC_CONFIG_HEADERS => 1,
4797                 AC_CONFIG_LIBOBJ_DIR => 1,
4798                 AC_CONFIG_LINKS => 1,
4799                 AC_FC_SRCEXT => 1,
4800                 AC_INIT => 0,
4801                 AC_LIBSOURCE => 1,
4802                 AC_REQUIRE_AUX_FILE => 1,
4803                 AC_SUBST_TRACE => 1,
4804                 AM_AUTOMAKE_VERSION => 1,
4805                 AM_CONDITIONAL => 2,
4806                 AM_ENABLE_MULTILIB => 0,
4807                 AM_GNU_GETTEXT => 0,
4808                 AM_GNU_GETTEXT_INTL_SUBDIR => 0,
4809                 AM_INIT_AUTOMAKE => 0,
4810                 AM_MAINTAINER_MODE => 0,
4811                 AM_PROG_CC_C_O => 0,
4812                 _AM_SUBST_NOTMAKE => 1,
4813                 LT_SUPPORTED_TAG => 1,
4814                 _LT_AC_TAGCONFIG => 0,
4815                 m4_include => 1,
4816                 m4_sinclude => 1,
4817                 sinclude => 1,
4818               );
4820   my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
4822   # Use a separator unlikely to be used, not `:', the default, which
4823   # has a precise meaning for AC_CONFIG_FILES and so on.
4824   $traces .= join (' ',
4825                    map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' }
4826                    (keys %traced));
4828   my $tracefh = new Automake::XFile ("$traces $filename |");
4829   verb "reading $traces";
4831   while ($_ = $tracefh->getline)
4832     {
4833       chomp;
4834       my ($here, @args) = split (/::/);
4835       my $where = new Automake::Location $here;
4836       my $macro = $args[0];
4838       prog_error ("unrequested trace `$macro'")
4839         unless exists $traced{$macro};
4841       # Skip and diagnose malformed calls.
4842       if ($#args < $traced{$macro})
4843         {
4844           msg ('syntax', $where, "not enough arguments for $macro");
4845           next;
4846         }
4848       # Alphabetical ordering please.
4849       if ($macro eq 'AC_CANONICAL_BUILD')
4850         {
4851           if ($seen_canonical <= AC_CANONICAL_BUILD)
4852             {
4853               $seen_canonical = AC_CANONICAL_BUILD;
4854               $canonical_location = $where;
4855             }
4856         }
4857       elsif ($macro eq 'AC_CANONICAL_HOST')
4858         {
4859           if ($seen_canonical <= AC_CANONICAL_HOST)
4860             {
4861               $seen_canonical = AC_CANONICAL_HOST;
4862               $canonical_location = $where;
4863             }
4864         }
4865       elsif ($macro eq 'AC_CANONICAL_TARGET')
4866         {
4867           $seen_canonical = AC_CANONICAL_TARGET;
4868           $canonical_location = $where;
4869         }
4870       elsif ($macro eq 'AC_CONFIG_AUX_DIR')
4871         {
4872           if ($seen_init_automake)
4873             {
4874               error ($where, "AC_CONFIG_AUX_DIR must be called before "
4875                      . "AM_INIT_AUTOMAKE...", partial => 1);
4876               error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
4877             }
4878           $config_aux_dir = $args[1];
4879           $config_aux_dir_set_in_configure_ac = 1;
4880           $relative_dir = '.';
4881           check_directory ($config_aux_dir, $where);
4882         }
4883       elsif ($macro eq 'AC_CONFIG_FILES')
4884         {
4885           # Look at potential Makefile.am's.
4886           scan_autoconf_config_files ($where, $args[1]);
4887         }
4888       elsif ($macro eq 'AC_CONFIG_HEADERS')
4889         {
4890           foreach my $spec (split (' ', $args[1]))
4891             {
4892               my ($dest, @src) = split (':', $spec);
4893               $ac_config_files_location{$dest} = $where;
4894               push @config_headers, $spec;
4895             }
4896         }
4897       elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
4898         {
4899           $config_libobj_dir = $args[1];
4900           $relative_dir = '.';
4901           check_directory ($config_libobj_dir, $where);
4902         }
4903       elsif ($macro eq 'AC_CONFIG_LINKS')
4904         {
4905           foreach my $spec (split (' ', $args[1]))
4906             {
4907               my ($dest, $src) = split (':', $spec);
4908               $ac_config_files_location{$dest} = $where;
4909               push @config_links, $spec;
4910             }
4911         }
4912       elsif ($macro eq 'AC_FC_SRCEXT')
4913         {
4914           my $suffix = $args[1];
4915           # These flags are used as %SOURCEFLAG% in depend2.am,
4916           # where the trailing space is important.
4917           $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ') '
4918             if ($suffix eq 'f90' || $suffix eq 'f95');
4919         }
4920       elsif ($macro eq 'AC_INIT')
4921         {
4922           if (defined $args[2])
4923             {
4924               $package_version = $args[2];
4925               $package_version_location = $where;
4926             }
4927         }
4928       elsif ($macro eq 'AC_LIBSOURCE')
4929         {
4930           $libsources{$args[1]} = $here;
4931         }
4932       elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
4933         {
4934           # Only remember the first time a file is required.
4935           $required_aux_file{$args[1]} = $where
4936             unless exists $required_aux_file{$args[1]};
4937         }
4938       elsif ($macro eq 'AC_SUBST_TRACE')
4939         {
4940           # Just check for alphanumeric in AC_SUBST_TRACE.  If you do
4941           # AC_SUBST(5), then too bad.
4942           $configure_vars{$args[1]} = $where
4943             if $args[1] =~ /^\w+$/;
4944         }
4945       elsif ($macro eq 'AM_AUTOMAKE_VERSION')
4946         {
4947           error ($where,
4948                  "version mismatch.  This is Automake $VERSION,\n" .
4949                  "but the definition used by this AM_INIT_AUTOMAKE\n" .
4950                  "comes from Automake $args[1].  You should recreate\n" .
4951                  "aclocal.m4 with aclocal and run automake again.\n",
4952                  # $? = 63 is used to indicate version mismatch to missing.
4953                  exit_code => 63)
4954             if $VERSION ne $args[1];
4956           $seen_automake_version = 1;
4957         }
4958       elsif ($macro eq 'AM_CONDITIONAL')
4959         {
4960           $configure_cond{$args[1]} = $where;
4961         }
4962       elsif ($macro eq 'AM_ENABLE_MULTILIB')
4963         {
4964           $seen_multilib = $where;
4965         }
4966       elsif ($macro eq 'AM_GNU_GETTEXT')
4967         {
4968           $seen_gettext = $where;
4969           $ac_gettext_location = $where;
4970           $seen_gettext_external = grep ($_ eq 'external', @args);
4971         }
4972       elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
4973         {
4974           $seen_gettext_intl = $where;
4975         }
4976       elsif ($macro eq 'AM_INIT_AUTOMAKE')
4977         {
4978           $seen_init_automake = $where;
4979           if (defined $args[2])
4980             {
4981               $package_version = $args[2];
4982               $package_version_location = $where;
4983             }
4984           elsif (defined $args[1])
4985             {
4986               exit $exit_code
4987                 if (process_global_option_list ($where,
4988                                                 split (' ', $args[1])));
4989             }
4990         }
4991       elsif ($macro eq 'AM_MAINTAINER_MODE')
4992         {
4993           $seen_maint_mode = $where;
4994         }
4995       elsif ($macro eq 'AM_PROG_CC_C_O')
4996         {
4997           $seen_cc_c_o = $where;
4998         }
4999       elsif ($macro eq '_AM_SUBST_NOTMAKE')
5000         {
5001           $ignored_configure_vars{$args[1]} = $where;
5002         }
5003       elsif ($macro eq 'm4_include'
5004              || $macro eq 'm4_sinclude'
5005              || $macro eq 'sinclude')
5006         {
5007           # Skip missing `sinclude'd files.
5008           next if $macro ne 'm4_include' && ! -f $args[1];
5010           # Some modified versions of Autoconf don't use
5011           # frozen files.  Consequently it's possible that we see all
5012           # m4_include's performed during Autoconf's startup.
5013           # Obviously we don't want to distribute Autoconf's files
5014           # so we skip absolute filenames here.
5015           push @configure_deps, '$(top_srcdir)/' . $args[1]
5016             unless $here =~ m,^(?:\w:)?[\\/],;
5017           # Keep track of the greatest timestamp.
5018           if (-e $args[1])
5019             {
5020               my $mtime = mtime $args[1];
5021               $configure_deps_greatest_timestamp = $mtime
5022                 if $mtime > $configure_deps_greatest_timestamp;
5023             }
5024         }
5025       elsif ($macro eq 'LT_SUPPORTED_TAG')
5026         {
5027           $libtool_tags{$args[1]} = 1;
5028           $libtool_new_api = 1;
5029         }
5030       elsif ($macro eq '_LT_AC_TAGCONFIG')
5031         {
5032           # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
5033           # We use it to detect whether tags are supported.  Our
5034           # preferred interface is LT_SUPPORTED_TAG, but it was
5035           # introduced in Libtool 1.6.
5036           if (0 == keys %libtool_tags)
5037             {
5038               # Hardcode the tags supported by Libtool 1.5.
5039               %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
5040             }
5041         }
5042     }
5044   $tracefh->close;
5048 # &scan_autoconf_files ()
5049 # -----------------------
5050 # Check whether we use `configure.ac' or `configure.in'.
5051 # Scan it (and possibly `aclocal.m4') for interesting things.
5052 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5053 sub scan_autoconf_files ()
5055   # Reinitialize libsources here.  This isn't really necessary,
5056   # since we currently assume there is only one configure.ac.  But
5057   # that won't always be the case.
5058   %libsources = ();
5060   # Keep track of the youngest configure dependency.
5061   $configure_deps_greatest_timestamp = mtime $configure_ac;
5062   if (-e 'aclocal.m4')
5063     {
5064       my $mtime = mtime 'aclocal.m4';
5065       $configure_deps_greatest_timestamp = $mtime
5066         if $mtime > $configure_deps_greatest_timestamp;
5067     }
5069   scan_autoconf_traces ($configure_ac);
5071   @configure_input_files = sort keys %make_list;
5072   # Set input and output files if not specified by user.
5073   if (! @input_files)
5074     {
5075       @input_files = @configure_input_files;
5076       %output_files = %make_list;
5077     }
5080   if (! $seen_init_automake)
5081     {
5082       err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
5083               . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
5084               . "\nthat aclocal.m4 is present in the top-level directory,\n"
5085               . "and that aclocal.m4 was recently regenerated "
5086               . "(using aclocal).");
5087     }
5088   else
5089     {
5090       if (! $seen_automake_version)
5091         {
5092           if (-f 'aclocal.m4')
5093             {
5094               error ($seen_init_automake,
5095                      "your implementation of AM_INIT_AUTOMAKE comes from " .
5096                      "an\nold Automake version.  You should recreate " .
5097                      "aclocal.m4\nwith aclocal and run automake again.\n",
5098                      # $? = 63 is used to indicate version mismatch to missing.
5099                      exit_code => 63);
5100             }
5101           else
5102             {
5103               error ($seen_init_automake,
5104                      "no proper implementation of AM_INIT_AUTOMAKE was " .
5105                      "found,\nprobably because aclocal.m4 is missing...\n" .
5106                      "You should run aclocal to create this file, then\n" .
5107                      "run automake again.\n");
5108             }
5109         }
5110     }
5112   locate_aux_dir ();
5114   # Reorder @input_files so that the Makefile that distributes aux
5115   # files is processed last.  This is important because each directory
5116   # can require auxiliary scripts and we should wait until they have
5117   # been installed before distributing them.
5119   # The Makefile.in that distribute the aux files is the one in
5120   # $config_aux_dir or the top-level Makefile.
5121   my $auxdirdist = is_make_dir ($config_aux_dir) ? $config_aux_dir : '.';
5122   my @new_input_files = ();
5123   while (@input_files)
5124     {
5125       my $in = pop @input_files;
5126       my @ins = split (/:/, $output_files{$in});
5127       if (dirname ($ins[0]) eq $auxdirdist)
5128         {
5129           push @new_input_files, $in;
5130           $automake_will_process_aux_dir = 1;
5131         }
5132       else
5133         {
5134           unshift @new_input_files, $in;
5135         }
5136     }
5137   @input_files = @new_input_files;
5139   # If neither the auxdir/Makefile nor the ./Makefile are generated
5140   # by Automake, we won't distribute the aux files anyway.  Assume
5141   # the user know what (s)he does, and pretend we will distribute
5142   # them to disable the error in require_file_internal.
5143   $automake_will_process_aux_dir = 1 if ! is_make_dir ($auxdirdist);
5145   # Look for some files we need.  Always check for these.  This
5146   # check must be done for every run, even those where we are only
5147   # looking at a subdir Makefile.  We must set relative_dir for
5148   # maybe_push_required_file to work.
5149   $relative_dir = '.';
5150   foreach my $file (keys %required_aux_file)
5151     {
5152       require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5153     }
5154   err_am "`install.sh' is an anachronism; use `install-sh' instead"
5155     if -f $config_aux_dir . '/install.sh';
5157   # Preserve dist_common for later.
5158   $configure_dist_common = variable_value ('DIST_COMMON') || '';
5162 ################################################################
5164 # Set up for Cygnus mode.
5165 sub check_cygnus
5167   my $cygnus = option 'cygnus';
5168   return unless $cygnus;
5170   set_strictness ('foreign');
5171   set_option ('no-installinfo', $cygnus);
5172   set_option ('no-dependencies', $cygnus);
5173   set_option ('no-dist', $cygnus);
5175   err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
5176     if !$seen_maint_mode;
5179 # Do any extra checking for GNU standards.
5180 sub check_gnu_standards
5182   if ($relative_dir eq '.')
5183     {
5184       # In top level (or only) directory.
5185       require_file ("$am_file.am", GNU,
5186                     qw/INSTALL NEWS README AUTHORS ChangeLog/);
5188       # Accept one of these three licenses; default to COPYING.
5189       # Make sure we do not overwrite an existing license.
5190       my $license;
5191       foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5192         {
5193           if (-f $_)
5194             {
5195               $license = $_;
5196               last;
5197             }
5198         }
5199       require_file ("$am_file.am", GNU, 'COPYING')
5200         unless $license;
5201     }
5203   for my $opt ('no-installman', 'no-installinfo')
5204     {
5205       msg ('error-gnu', option $opt,
5206            "option `$opt' disallowed by GNU standards")
5207         if option $opt;
5208     }
5211 # Do any extra checking for GNITS standards.
5212 sub check_gnits_standards
5214   if ($relative_dir eq '.')
5215     {
5216       # In top level (or only) directory.
5217       require_file ("$am_file.am", GNITS, 'THANKS');
5218     }
5221 ################################################################
5223 # Functions to handle files of each language.
5225 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5226 # simple formula: Return value is LANG_SUBDIR if the resulting object
5227 # file should be in a subdir if the source file is, LANG_PROCESS if
5228 # file is to be dealt with, LANG_IGNORE otherwise.
5230 # Much of the actual processing is handled in
5231 # handle_single_transform.  These functions exist so that
5232 # auxiliary information can be recorded for a later cleanup pass.
5233 # Note that the calls to these functions are computed, so don't bother
5234 # searching for their precise names in the source.
5236 # This is just a convenience function that can be used to determine
5237 # when a subdir object should be used.
5238 sub lang_sub_obj
5240     return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
5243 # Rewrite a single C source file.
5244 sub lang_c_rewrite
5246   my ($directory, $base, $ext, $nonansi_obj, $have_per_exec_flags, $var) = @_;
5248   if (option 'ansi2knr' && $base =~ /_$/)
5249     {
5250       # FIXME: include line number in error.
5251       err_am "C source file `$base.c' would be deleted by ansi2knr rules";
5252     }
5254   my $r = LANG_PROCESS;
5255   if (option 'subdir-objects')
5256     {
5257       $r = LANG_SUBDIR;
5258       if ($directory && $directory ne '.')
5259         {
5260           $base = $directory . '/' . $base;
5262           # libtool is always able to put the object at the proper place,
5263           # so we do not have to require AM_PROG_CC_C_O when building .lo files.
5264           msg_var ('portability', $var,
5265                    "compiling `$base.c' in subdir requires "
5266                    . "`AM_PROG_CC_C_O' in `$configure_ac'",
5267                    uniq_scope => US_GLOBAL,
5268                    uniq_part => 'AM_PROG_CC_C_O subdir')
5269             unless $seen_cc_c_o || $nonansi_obj eq '.lo';
5270         }
5272       # In this case we already have the directory information, so
5273       # don't add it again.
5274       $de_ansi_files{$base} = '';
5275     }
5276   else
5277     {
5278       $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
5279                                ? ''
5280                                : "$directory/");
5281     }
5283   if (! $seen_cc_c_o
5284       && $have_per_exec_flags
5285       && ! option 'subdir-objects'
5286       && $nonansi_obj ne '.lo')
5287     {
5288       msg_var ('portability',
5289                $var, "compiling `$base.c' with per-target flags requires "
5290                . "`AM_PROG_CC_C_O' in `$configure_ac'",
5291                uniq_scope => US_GLOBAL,
5292                uniq_part => 'AM_PROG_CC_C_O per-target')
5293     }
5295     return $r;
5298 # Rewrite a single C++ source file.
5299 sub lang_cxx_rewrite
5301     return &lang_sub_obj;
5304 # Rewrite a single header file.
5305 sub lang_header_rewrite
5307     # Header files are simply ignored.
5308     return LANG_IGNORE;
5311 # Rewrite a single yacc file.
5312 sub lang_yacc_rewrite
5314     my ($directory, $base, $ext) = @_;
5316     my $r = &lang_sub_obj;
5317     (my $newext = $ext) =~ tr/y/c/;
5318     return ($r, $newext);
5321 # Rewrite a single yacc++ file.
5322 sub lang_yaccxx_rewrite
5324     my ($directory, $base, $ext) = @_;
5326     my $r = &lang_sub_obj;
5327     (my $newext = $ext) =~ tr/y/c/;
5328     return ($r, $newext);
5331 # Rewrite a single lex file.
5332 sub lang_lex_rewrite
5334     my ($directory, $base, $ext) = @_;
5336     my $r = &lang_sub_obj;
5337     (my $newext = $ext) =~ tr/l/c/;
5338     return ($r, $newext);
5341 # Rewrite a single lex++ file.
5342 sub lang_lexxx_rewrite
5344     my ($directory, $base, $ext) = @_;
5346     my $r = &lang_sub_obj;
5347     (my $newext = $ext) =~ tr/l/c/;
5348     return ($r, $newext);
5351 # Rewrite a single assembly file.
5352 sub lang_asm_rewrite
5354     return &lang_sub_obj;
5357 # Rewrite a single preprocessed assembly file.
5358 sub lang_cppasm_rewrite
5360     return &lang_sub_obj;
5363 # Rewrite a single Fortran 77 file.
5364 sub lang_f77_rewrite
5366     return &lang_sub_obj;
5369 # Rewrite a single Fortran file.
5370 sub lang_fc_rewrite
5372     return &lang_sub_obj;
5375 # Rewrite a single preprocessed Fortran file.
5376 sub lang_ppfc_rewrite
5378     return &lang_sub_obj;
5381 # Rewrite a single preprocessed Fortran 77 file.
5382 sub lang_ppf77_rewrite
5384     return &lang_sub_obj;
5387 # Rewrite a single ratfor file.
5388 sub lang_ratfor_rewrite
5390     return &lang_sub_obj;
5393 # Rewrite a single Objective C file.
5394 sub lang_objc_rewrite
5396     return &lang_sub_obj;
5399 # Rewrite a single Unified Parallel C file.
5400 sub lang_upc_rewrite
5402     return &lang_sub_obj;
5405 # Rewrite a single Java file.
5406 sub lang_java_rewrite
5408     return LANG_SUBDIR;
5411 # The lang_X_finish functions are called after all source file
5412 # processing is done.  Each should handle defining rules for the
5413 # language, etc.  A finish function is only called if a source file of
5414 # the appropriate type has been seen.
5416 sub lang_c_finish
5418     # Push all libobjs files onto de_ansi_files.  We actually only
5419     # push files which exist in the current directory, and which are
5420     # genuine source files.
5421     foreach my $file (keys %libsources)
5422     {
5423         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5424         {
5425             $de_ansi_files{$1} = ''
5426         }
5427     }
5429     if (option 'ansi2knr' && keys %de_ansi_files)
5430     {
5431         # Make all _.c files depend on their corresponding .c files.
5432         my @objects;
5433         foreach my $base (sort keys %de_ansi_files)
5434         {
5435             # Each _.c file must depend on ansi2knr; otherwise it
5436             # might be used in a parallel build before it is built.
5437             # We need to support files in the srcdir and in the build
5438             # dir (because these files might be auto-generated.  But
5439             # we can't use $< -- some makes only define $< during a
5440             # suffix rule.
5441             my $ansfile = $de_ansi_files{$base} . $base . '.c';
5442             $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5443                               . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5444                               . '`if test -f $(srcdir)/' . $ansfile
5445                               . '; then echo $(srcdir)/' . $ansfile
5446                               . '; else echo ' . $ansfile . '; fi` '
5447                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5448                               . '| $(ANSI2KNR) > $@'
5449                               # If ansi2knr fails then we shouldn't
5450                               # create the _.c file
5451                               . " || rm -f \$\@\n");
5452             push (@objects, $base . '_.$(OBJEXT)');
5453             push (@objects, $base . '_.lo')
5454               if var ('LIBTOOL');
5456             # Explicitly clean the _.c files if they are in a
5457             # subdirectory. (In the current directory they get erased
5458             # by a `rm -f *_.c' rule.)
5459             $clean_files{$base . '_.c'} = MOSTLY_CLEAN
5460               if dirname ($base) ne '.';
5461         }
5463         # Make all _.o (and _.lo) files depend on ansi2knr.
5464         # Use a sneaky little hack to make it print nicely.
5465         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5466     }
5469 # This is a yacc helper which is called whenever we have decided to
5470 # compile a yacc file.
5471 sub lang_yacc_target_hook
5473     my ($self, $aggregate, $output, $input, %transform) = @_;
5475     my $flag = $aggregate . "_YFLAGS";
5476     my $flagvar = var $flag;
5477     my $YFLAGSvar = var 'YFLAGS';
5478     if (($flagvar && $flagvar->variable_value =~ /$DASH_D_PATTERN/o)
5479         || ($YFLAGSvar && $YFLAGSvar->variable_value =~ /$DASH_D_PATTERN/o))
5480     {
5481         (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5482         my $header = $output_base . '.h';
5484         # Found a `-d' that applies to the compilation of this file.
5485         # Add a dependency for the generated header file, and arrange
5486         # for that file to be included in the distribution.
5487         foreach my $cond (Automake::Rule::define (${header}, 'internal',
5488                                                   RULE_AUTOMAKE, TRUE,
5489                                                   INTERNAL))
5490           {
5491             my $condstr = $cond->subst_string;
5492             $output_rules .=
5493               "$condstr${header}: $output\n"
5494               # Recover from removal of $header
5495               . "$condstr\t\@if test ! -f \$@; then \\\n"
5496               . "$condstr\t  rm -f $output; \\\n"
5497               . "$condstr\t  \$(MAKE) \$(AM_MAKEFLAGS) $output; \\\n"
5498               . "$condstr\telse :; fi\n";
5499           }
5500         # Distribute the generated file, unless its .y source was
5501         # listed in a nodist_ variable.  (&handle_source_transform
5502         # will set DIST_SOURCE.)
5503         &push_dist_common ($header)
5504           if $transform{'DIST_SOURCE'};
5506         # If the files are built in the build directory, then we want
5507         # to remove them with `make clean'.  If they are in srcdir
5508         # they shouldn't be touched.  However, we can't determine this
5509         # statically, and the GNU rules say that yacc/lex output files
5510         # should be removed by maintainer-clean.  So that's what we
5511         # do.
5512         $clean_files{$header} = MAINTAINER_CLEAN;
5513     }
5514     # Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
5515     # See the comment above for $HEADER.
5516     $clean_files{$output} = MAINTAINER_CLEAN;
5519 # This is a lex helper which is called whenever we have decided to
5520 # compile a lex file.
5521 sub lang_lex_target_hook
5523     my ($self, $aggregate, $output, $input) = @_;
5524     # If the files are built in the build directory, then we want to
5525     # remove them with `make clean'.  If they are in srcdir they
5526     # shouldn't be touched.  However, we can't determine this
5527     # statically, and the GNU rules say that yacc/lex output files
5528     # should be removed by maintainer-clean.  So that's what we do.
5529     $clean_files{$output} = MAINTAINER_CLEAN;
5532 # This is a helper for both lex and yacc.
5533 sub yacc_lex_finish_helper
5535   return if defined $language_scratch{'lex-yacc-done'};
5536   $language_scratch{'lex-yacc-done'} = 1;
5538   # FIXME: for now, no line number.
5539   require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5540   &define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
5543 sub lang_yacc_finish
5545   return if defined $language_scratch{'yacc-done'};
5546   $language_scratch{'yacc-done'} = 1;
5548   reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
5550   yacc_lex_finish_helper;
5554 sub lang_lex_finish
5556   return if defined $language_scratch{'lex-done'};
5557   $language_scratch{'lex-done'} = 1;
5559   yacc_lex_finish_helper;
5563 # Given a hash table of linker names, pick the name that has the most
5564 # precedence.  This is lame, but something has to have global
5565 # knowledge in order to eliminate the conflict.  Add more linkers as
5566 # required.
5567 sub resolve_linker
5569     my (%linkers) = @_;
5571     foreach my $l (qw(GCJLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
5572     {
5573         return $l if defined $linkers{$l};
5574     }
5575     return 'LINK';
5578 # Called to indicate that an extension was used.
5579 sub saw_extension
5581     my ($ext) = @_;
5582     if (! defined $extension_seen{$ext})
5583     {
5584         $extension_seen{$ext} = 1;
5585     }
5586     else
5587     {
5588         ++$extension_seen{$ext};
5589     }
5592 # Return the number of files seen for a given language.  Knows about
5593 # special cases we care about.  FIXME: this is hideous.  We need
5594 # something that involves real language objects.  For instance yacc
5595 # and yaccxx could both derive from a common yacc class which would
5596 # know about the strange ylwrap requirement.  (Or better yet we could
5597 # just not support legacy yacc!)
5598 sub count_files_for_language
5600     my ($name) = @_;
5602     my @names;
5603     if ($name eq 'yacc' || $name eq 'yaccxx')
5604     {
5605         @names = ('yacc', 'yaccxx');
5606     }
5607     elsif ($name eq 'lex' || $name eq 'lexxx')
5608     {
5609         @names = ('lex', 'lexxx');
5610     }
5611     else
5612     {
5613         @names = ($name);
5614     }
5616     my $r = 0;
5617     foreach $name (@names)
5618     {
5619         my $lang = $languages{$name};
5620         foreach my $ext (@{$lang->extensions})
5621         {
5622             $r += $extension_seen{$ext}
5623                 if defined $extension_seen{$ext};
5624         }
5625     }
5627     return $r
5630 # Called to ask whether source files have been seen . If HEADERS is 1,
5631 # headers can be included.
5632 sub saw_sources_p
5634     my ($headers) = @_;
5636     # count all the sources
5637     my $count = 0;
5638     foreach my $val (values %extension_seen)
5639     {
5640         $count += $val;
5641     }
5643     if (!$headers)
5644     {
5645         $count -= count_files_for_language ('header');
5646     }
5648     return $count > 0;
5652 # register_language (%ATTRIBUTE)
5653 # ------------------------------
5654 # Register a single language.
5655 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5656 sub register_language (%)
5658   my (%option) = @_;
5660   # Set the defaults.
5661   $option{'ansi'} = 0
5662     unless defined $option{'ansi'};
5663   $option{'autodep'} = 'no'
5664     unless defined $option{'autodep'};
5665   $option{'linker'} = ''
5666     unless defined $option{'linker'};
5667   $option{'flags'} = []
5668     unless defined $option{'flags'};
5669   $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5670     unless defined $option{'output_extensions'};
5671   $option{'nodist_specific'} = 0
5672     unless defined $option{'nodist_specific'};
5674   my $lang = new Language (%option);
5676   # Fill indexes.
5677   $extension_map{$_} = $lang->name foreach @{$lang->extensions};
5678   $languages{$lang->name} = $lang;
5679   my $link = $lang->linker;
5680   if ($link)
5681     {
5682       if (exists $link_languages{$link})
5683         {
5684           prog_error ("`$link' has different definitions in "
5685                       . $lang->name . " and " . $link_languages{$link}->name)
5686             if $lang->link ne $link_languages{$link}->link;
5687         }
5688       else
5689         {
5690           $link_languages{$link} = $lang;
5691         }
5692     }
5694   # Update the pattern of known extensions.
5695   accept_extensions (@{$lang->extensions});
5697   # Upate the $suffix_rule map.
5698   foreach my $suffix (@{$lang->extensions})
5699     {
5700       foreach my $dest (&{$lang->output_extensions} ($suffix))
5701         {
5702           register_suffix_rule (INTERNAL, $suffix, $dest);
5703         }
5704     }
5707 # derive_suffix ($EXT, $OBJ)
5708 # --------------------------
5709 # This function is used to find a path from a user-specified suffix $EXT
5710 # to $OBJ or to some other suffix we recognize internally, e.g. `cc'.
5711 sub derive_suffix ($$)
5713   my ($source_ext, $obj) = @_;
5715   while (! $extension_map{$source_ext}
5716          && $source_ext ne $obj
5717          && exists $suffix_rules->{$source_ext}
5718          && exists $suffix_rules->{$source_ext}{$obj})
5719     {
5720       $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
5721     }
5723   return $source_ext;
5727 ################################################################
5729 # Pretty-print something and append to output_rules.
5730 sub pretty_print_rule
5732     $output_rules .= &makefile_wrap (@_);
5736 ################################################################
5739 ## -------------------------------- ##
5740 ## Handling the conditional stack.  ##
5741 ## -------------------------------- ##
5744 # $STRING
5745 # make_conditional_string ($NEGATE, $COND)
5746 # ----------------------------------------
5747 sub make_conditional_string ($$)
5749   my ($negate, $cond) = @_;
5750   $cond = "${cond}_TRUE"
5751     unless $cond =~ /^TRUE|FALSE$/;
5752   $cond = Automake::Condition::conditional_negate ($cond)
5753     if $negate;
5754   return $cond;
5758 my %_am_macro_for_cond =
5759   (
5760   AMDEP => "one of the compiler tests\n"
5761            . "    AC_PROG_CC, AC_PROG_CXX, AC_PROG_CXX, AC_PROG_OBJC,\n"
5762            . "    AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
5763   am__fastdepCC => 'AC_PROG_CC',
5764   am__fastdepCCAS => 'AM_PROG_AS',
5765   am__fastdepCXX => 'AC_PROG_CXX',
5766   am__fastdepGCJ => 'AM_PROG_GCJ',
5767   am__fastdepOBJC => 'AC_PROG_OBJC',
5768   am__fastdepUPC => 'AM_PROG_UPC'
5769   );
5771 # $COND
5772 # cond_stack_if ($NEGATE, $COND, $WHERE)
5773 # --------------------------------------
5774 sub cond_stack_if ($$$)
5776   my ($negate, $cond, $where) = @_;
5778   if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
5779     {
5780       my $text = "$cond does not appear in AM_CONDITIONAL";
5781       my $scope = US_LOCAL;
5782       if (exists $_am_macro_for_cond{$cond})
5783         {
5784           my $mac = $_am_macro_for_cond{$cond};
5785           $text .= "\n  The usual way to define `$cond' is to add ";
5786           $text .= ($mac =~ / /) ? $mac : "`$mac'";
5787           $text .= "\n  to `$configure_ac' and run `aclocal' and `autoconf' again.";
5788           # These warnings appear in Automake files (depend2.am),
5789           # so there is no need to display them more than once:
5790           $scope = US_GLOBAL;
5791         }
5792       error $where, $text, uniq_scope => $scope;
5793     }
5795   push (@cond_stack, make_conditional_string ($negate, $cond));
5797   return new Automake::Condition (@cond_stack);
5801 # $COND
5802 # cond_stack_else ($NEGATE, $COND, $WHERE)
5803 # ----------------------------------------
5804 sub cond_stack_else ($$$)
5806   my ($negate, $cond, $where) = @_;
5808   if (! @cond_stack)
5809     {
5810       error $where, "else without if";
5811       return FALSE;
5812     }
5814   $cond_stack[$#cond_stack] =
5815     Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
5817   # If $COND is given, check against it.
5818   if (defined $cond)
5819     {
5820       $cond = make_conditional_string ($negate, $cond);
5822       error ($where, "else reminder ($negate$cond) incompatible with "
5823              . "current conditional: $cond_stack[$#cond_stack]")
5824         if $cond_stack[$#cond_stack] ne $cond;
5825     }
5827   return new Automake::Condition (@cond_stack);
5831 # $COND
5832 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5833 # -----------------------------------------
5834 sub cond_stack_endif ($$$)
5836   my ($negate, $cond, $where) = @_;
5837   my $old_cond;
5839   if (! @cond_stack)
5840     {
5841       error $where, "endif without if";
5842       return TRUE;
5843     }
5845   # If $COND is given, check against it.
5846   if (defined $cond)
5847     {
5848       $cond = make_conditional_string ($negate, $cond);
5850       error ($where, "endif reminder ($negate$cond) incompatible with "
5851              . "current conditional: $cond_stack[$#cond_stack]")
5852         if $cond_stack[$#cond_stack] ne $cond;
5853     }
5855   pop @cond_stack;
5857   return new Automake::Condition (@cond_stack);
5864 ## ------------------------ ##
5865 ## Handling the variables.  ##
5866 ## ------------------------ ##
5869 # &define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
5870 # -----------------------------------------------------
5871 # Like define_variable, but the value is a list, and the variable may
5872 # be defined conditionally.  The second argument is the Condition
5873 # under which the value should be defined; this should be the empty
5874 # string to define the variable unconditionally.  The third argument
5875 # is a list holding the values to use for the variable.  The value is
5876 # pretty printed in the output file.
5877 sub define_pretty_variable ($$$@)
5879     my ($var, $cond, $where, @value) = @_;
5881     if (! vardef ($var, $cond))
5882     {
5883         Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
5884                                     '', $where, VAR_PRETTY);
5885         rvar ($var)->rdef ($cond)->set_seen;
5886     }
5890 # define_variable ($VAR, $VALUE, $WHERE)
5891 # --------------------------------------
5892 # Define a new Automake Makefile variable VAR to VALUE, but only if
5893 # not already defined.
5894 sub define_variable ($$$)
5896     my ($var, $value, $where) = @_;
5897     define_pretty_variable ($var, TRUE, $where, $value);
5901 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
5902 # -----------------------------------------------------------
5903 # Define the $VAR which content is the list of file names composed of
5904 # a @BASENAME and the $EXTENSION.
5905 sub define_files_variable ($\@$$)
5907   my ($var, $basename, $extension, $where) = @_;
5908   define_variable ($var,
5909                    join (' ', map { "$_.$extension" } @$basename),
5910                    $where);
5914 # Like define_variable, but define a variable to be the configure
5915 # substitution by the same name.
5916 sub define_configure_variable ($)
5918   my ($var) = @_;
5920   my $pretty = VAR_ASIS;
5921   my $owner = VAR_CONFIGURE;
5923   # Some variables we do not want to output.  For instance it
5924   # would be a bad idea to output `U = @U@` when `@U@` can be
5925   # substituted as `\`.
5926   $pretty = VAR_SILENT if exists $ignored_configure_vars{$var};
5928   # ANSI2KNR is a variable that Automake wants to redefine, so
5929   # it must be owned by Automake.  (It is also used as a proof
5930   # that AM_C_PROTOTYPES has been run, that's why we do not simply
5931   # omit the AC_SUBST.)
5932   $owner = VAR_AUTOMAKE if $var eq 'ANSI2KNR';
5934   Automake::Variable::define ($var, $owner, '', TRUE, subst $var,
5935                               '', $configure_vars{$var}, $pretty);
5939 # define_compiler_variable ($LANG)
5940 # --------------------------------
5941 # Define a compiler variable.  We also handle defining the `LT'
5942 # version of the command when using libtool.
5943 sub define_compiler_variable ($)
5945     my ($lang) = @_;
5947     my ($var, $value) = ($lang->compiler, $lang->compile);
5948     my $libtool_tag = '';
5949     $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5950       if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5951     &define_variable ($var, $value, INTERNAL);
5952     &define_variable ("LT$var",
5953                       "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5954                       . "\$(LIBTOOLFLAGS) --mode=compile $value",
5955                       INTERNAL)
5956       if var ('LIBTOOL');
5960 # define_linker_variable ($LANG)
5961 # ------------------------------
5962 # Define linker variables.
5963 sub define_linker_variable ($)
5965     my ($lang) = @_;
5967     my $libtool_tag = '';
5968     $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5969       if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5970     # CCLD = $(CC).
5971     &define_variable ($lang->lder, $lang->ld, INTERNAL);
5972     # CCLINK = $(CCLD) blah blah...
5973     &define_variable ($lang->linker,
5974                       ((var ('LIBTOOL') ?
5975                         "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5976                         . "\$(LIBTOOLFLAGS) --mode=link " : '')
5977                        . $lang->link),
5978                       INTERNAL);
5981 sub define_per_target_linker_variable ($$)
5983   my ($linker, $target) = @_;
5985   # If the user wrote a custom link command, we don't define ours.
5986   return "${target}_LINK"
5987     if set_seen "${target}_LINK";
5989   my $xlink = $linker ? $linker : 'LINK';
5991   my $lang = $link_languages{$xlink};
5992   prog_error "Unknown language for linker variable `$xlink'"
5993     unless $lang;
5995   my $link_command = $lang->link;
5996   if (var 'LIBTOOL')
5997     {
5998       my $libtool_tag = '';
5999       $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6000         if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6002       $link_command =
6003         "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
6004         . "--mode=link " . $link_command;
6005     }
6007   # Rewrite each occurrence of `AM_$flag' in the link
6008   # command into `${derived}_$flag' if it exists.
6009   my $orig_command = $link_command;
6010   my @flags = (@{$lang->flags}, 'LDFLAGS');
6011   push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
6012   for my $flag (@flags)
6013     {
6014       my $val = "${target}_$flag";
6015       $link_command =~ s/\(AM_$flag\)/\($val\)/
6016         if set_seen ($val);
6017     }
6019   # If the computed command is the same as the generic command, use
6020   # the command linker variable.
6021   return $lang->linker
6022     if $link_command eq $orig_command;
6024   &define_variable ("${target}_LINK", $link_command, INTERNAL);
6025   return "${target}_LINK";
6028 ################################################################
6030 # &check_trailing_slash ($WHERE, $LINE)
6031 # --------------------------------------
6032 # Return 1 iff $LINE ends with a slash.
6033 # Might modify $LINE.
6034 sub check_trailing_slash ($\$)
6036   my ($where, $line) = @_;
6038   # Ignore `##' lines.
6039   return 0 if $$line =~ /$IGNORE_PATTERN/o;
6041   # Catch and fix a common error.
6042   msg "syntax", $where, "whitespace following trailing backslash"
6043     if $$line =~ s/\\\s+\n$/\\\n/;
6045   return $$line =~ /\\$/;
6049 # &read_am_file ($AMFILE, $WHERE)
6050 # -------------------------------
6051 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6052 # from Makefile.am into $output_trailer, or define variables as
6053 # appropriate.  NOTE we put rules in the trailer section.  We want
6054 # user rules to come after our generated stuff.
6055 sub read_am_file ($$)
6057     my ($amfile, $where) = @_;
6059     my $am_file = new Automake::XFile ("< $amfile");
6060     verb "reading $amfile";
6062     # Keep track of the youngest output dependency.
6063     my $mtime = mtime $amfile;
6064     $output_deps_greatest_timestamp = $mtime
6065       if $mtime > $output_deps_greatest_timestamp;
6067     my $spacing = '';
6068     my $comment = '';
6069     my $blank = 0;
6070     my $saw_bk = 0;
6071     my $var_look = VAR_ASIS;
6073     use constant IN_VAR_DEF => 0;
6074     use constant IN_RULE_DEF => 1;
6075     use constant IN_COMMENT => 2;
6076     my $prev_state = IN_RULE_DEF;
6078     while ($_ = $am_file->getline)
6079     {
6080         $where->set ("$amfile:$.");
6081         if (/$IGNORE_PATTERN/o)
6082         {
6083             # Merely delete comments beginning with two hashes.
6084         }
6085         elsif (/$WHITE_PATTERN/o)
6086         {
6087             error $where, "blank line following trailing backslash"
6088               if $saw_bk;
6089             # Stick a single white line before the incoming macro or rule.
6090             $spacing = "\n";
6091             $blank = 1;
6092             # Flush all comments seen so far.
6093             if ($comment ne '')
6094             {
6095                 $output_vars .= $comment;
6096                 $comment = '';
6097             }
6098         }
6099         elsif (/$COMMENT_PATTERN/o)
6100         {
6101             # Stick comments before the incoming macro or rule.  Make
6102             # sure a blank line precedes the first block of comments.
6103             $spacing = "\n" unless $blank;
6104             $blank = 1;
6105             $comment .= $spacing . $_;
6106             $spacing = '';
6107             $prev_state = IN_COMMENT;
6108         }
6109         else
6110         {
6111             last;
6112         }
6113         $saw_bk = check_trailing_slash ($where, $_);
6114     }
6116     # We save the conditional stack on entry, and then check to make
6117     # sure it is the same on exit.  This lets us conditionally include
6118     # other files.
6119     my @saved_cond_stack = @cond_stack;
6120     my $cond = new Automake::Condition (@cond_stack);
6122     my $last_var_name = '';
6123     my $last_var_type = '';
6124     my $last_var_value = '';
6125     my $last_where;
6126     # FIXME: shouldn't use $_ in this loop; it is too big.
6127     while ($_)
6128     {
6129         $where->set ("$amfile:$.");
6131         # Make sure the line is \n-terminated.
6132         chomp;
6133         $_ .= "\n";
6135         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6136         # used by users.  @MAINT@ is an anachronism now.
6137         $_ =~ s/\@MAINT\@//g
6138             unless $seen_maint_mode;
6140         my $new_saw_bk = check_trailing_slash ($where, $_);
6142         if (/$IGNORE_PATTERN/o)
6143         {
6144             # Merely delete comments beginning with two hashes.
6146             # Keep any backslash from the previous line.
6147             $new_saw_bk = $saw_bk;
6148         }
6149         elsif (/$WHITE_PATTERN/o)
6150         {
6151             # Stick a single white line before the incoming macro or rule.
6152             $spacing = "\n";
6153             error $where, "blank line following trailing backslash"
6154               if $saw_bk;
6155         }
6156         elsif (/$COMMENT_PATTERN/o)
6157         {
6158             error $where, "comment following trailing backslash"
6159               if $saw_bk && $comment eq '';
6161             # Stick comments before the incoming macro or rule.
6162             $comment .= $spacing . $_;
6163             $spacing = '';
6164             $prev_state = IN_COMMENT;
6165         }
6166         elsif ($saw_bk)
6167         {
6168             if ($prev_state == IN_RULE_DEF)
6169             {
6170               my $cond = new Automake::Condition @cond_stack;
6171               $output_trailer .= $cond->subst_string;
6172               $output_trailer .= $_;
6173             }
6174             elsif ($prev_state == IN_COMMENT)
6175             {
6176                 # If the line doesn't start with a `#', add it.
6177                 # We do this because a continued comment like
6178                 #   # A = foo \
6179                 #         bar \
6180                 #         baz
6181                 # is not portable.  BSD make doesn't honor
6182                 # escaped newlines in comments.
6183                 s/^#?/#/;
6184                 $comment .= $spacing . $_;
6185             }
6186             else # $prev_state == IN_VAR_DEF
6187             {
6188               $last_var_value .= ' '
6189                 unless $last_var_value =~ /\s$/;
6190               $last_var_value .= $_;
6192               if (!/\\$/)
6193                 {
6194                   Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6195                                               $last_var_type, $cond,
6196                                               $last_var_value, $comment,
6197                                               $last_where, VAR_ASIS)
6198                     if $cond != FALSE;
6199                   $comment = $spacing = '';
6200                 }
6201             }
6202         }
6204         elsif (/$IF_PATTERN/o)
6205           {
6206             $cond = cond_stack_if ($1, $2, $where);
6207           }
6208         elsif (/$ELSE_PATTERN/o)
6209           {
6210             $cond = cond_stack_else ($1, $2, $where);
6211           }
6212         elsif (/$ENDIF_PATTERN/o)
6213           {
6214             $cond = cond_stack_endif ($1, $2, $where);
6215           }
6217         elsif (/$RULE_PATTERN/o)
6218         {
6219             # Found a rule.
6220             $prev_state = IN_RULE_DEF;
6222             # For now we have to output all definitions of user rules
6223             # and can't diagnose duplicates (see the comment in
6224             # Automake::Rule::define). So we go on and ignore the return value.
6225             Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6227             check_variable_expansions ($_, $where);
6229             $output_trailer .= $comment . $spacing;
6230             my $cond = new Automake::Condition @cond_stack;
6231             $output_trailer .= $cond->subst_string;
6232             $output_trailer .= $_;
6233             $comment = $spacing = '';
6234         }
6235         elsif (/$ASSIGNMENT_PATTERN/o)
6236         {
6237             # Found a macro definition.
6238             $prev_state = IN_VAR_DEF;
6239             $last_var_name = $1;
6240             $last_var_type = $2;
6241             $last_var_value = $3;
6242             $last_where = $where->clone;
6243             if ($3 ne '' && substr ($3, -1) eq "\\")
6244               {
6245                 # We preserve the `\' because otherwise the long lines
6246                 # that are generated will be truncated by broken
6247                 # `sed's.
6248                 $last_var_value = $3 . "\n";
6249               }
6250             # Normally we try to output variable definitions in the
6251             # same format they were input.  However, POSIX compliant
6252             # systems are not required to support lines longer than
6253             # 2048 bytes (most notably, some sed implementation are
6254             # limited to 4000 bytes, and sed is used by config.status
6255             # to rewrite Makefile.in into Makefile).  Moreover nobody
6256             # would really write such long lines by hand since it is
6257             # hardly maintainable.  So if a line is longer that 1000
6258             # bytes (an arbitrary limit), assume it has been
6259             # automatically generated by some tools, and flatten the
6260             # variable definition.  Otherwise, keep the variable as it
6261             # as been input.
6262             $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6264             if (!/\\$/)
6265               {
6266                 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6267                                             $last_var_type, $cond,
6268                                             $last_var_value, $comment,
6269                                             $last_where, $var_look)
6270                   if $cond != FALSE;
6271                 $comment = $spacing = '';
6272                 $var_look = VAR_ASIS;
6273               }
6274         }
6275         elsif (/$INCLUDE_PATTERN/o)
6276         {
6277             my $path = $1;
6279             if ($path =~ s/^\$\(top_srcdir\)\///)
6280               {
6281                 push (@include_stack, "\$\(top_srcdir\)/$path");
6282                 # Distribute any included file.
6284                 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6285                 # otherwise OSF make will implicitly copy the included
6286                 # file in the build tree during `make distdir' to satisfy
6287                 # the dependency.
6288                 # (subdircond2.test and subdircond3.test will fail.)
6289                 push_dist_common ("\$\(top_srcdir\)/$path");
6290               }
6291             else
6292               {
6293                 $path =~ s/\$\(srcdir\)\///;
6294                 push (@include_stack, "\$\(srcdir\)/$path");
6295                 # Always use the $(srcdir) prefix in DIST_COMMON,
6296                 # otherwise OSF make will implicitly copy the included
6297                 # file in the build tree during `make distdir' to satisfy
6298                 # the dependency.
6299                 # (subdircond2.test and subdircond3.test will fail.)
6300                 push_dist_common ("\$\(srcdir\)/$path");
6301                 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6302               }
6303             $where->push_context ("`$path' included from here");
6304             &read_am_file ($path, $where);
6305             $where->pop_context;
6306         }
6307         else
6308         {
6309             # This isn't an error; it is probably a continued rule.
6310             # In fact, this is what we assume.
6311             $prev_state = IN_RULE_DEF;
6312             check_variable_expansions ($_, $where);
6313             $output_trailer .= $comment . $spacing;
6314             my $cond = new Automake::Condition @cond_stack;
6315             $output_trailer .= $cond->subst_string;
6316             $output_trailer .= $_;
6317             $comment = $spacing = '';
6318             error $where, "`#' comment at start of rule is unportable"
6319               if $_ =~ /^\t\s*\#/;
6320         }
6322         $saw_bk = $new_saw_bk;
6323         $_ = $am_file->getline;
6324     }
6326     $output_trailer .= $comment;
6328     error ($where, "trailing backslash on last line")
6329       if $saw_bk;
6331     error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6332                     : "too many conditionals closed in include file"))
6333       if "@saved_cond_stack" ne "@cond_stack";
6337 # define_standard_variables ()
6338 # ----------------------------
6339 # A helper for read_main_am_file which initializes configure variables
6340 # and variables from header-vars.am.
6341 sub define_standard_variables
6343   my $saved_output_vars = $output_vars;
6344   my ($comments, undef, $rules) =
6345     file_contents_internal (1, "$libdir/am/header-vars.am",
6346                             new Automake::Location);
6348   foreach my $var (sort keys %configure_vars)
6349     {
6350       &define_configure_variable ($var);
6351     }
6353   $output_vars .= $comments . $rules;
6356 # Read main am file.
6357 sub read_main_am_file
6359     my ($amfile) = @_;
6361     # This supports the strange variable tricks we are about to play.
6362     prog_error (macros_dump () . "variable defined before read_main_am_file")
6363       if (scalar (variables) > 0);
6365     # Generate copyright header for generated Makefile.in.
6366     # We do discard the output of predefined variables, handled below.
6367     $output_vars = ("# $in_file_name generated by automake "
6368                    . $VERSION . " from $am_file_name.\n");
6369     $output_vars .= '# ' . subst ('configure_input') . "\n";
6370     $output_vars .= $gen_copyright;
6372     # We want to predefine as many variables as possible.  This lets
6373     # the user set them with `+=' in Makefile.am.
6374     &define_standard_variables;
6376     # Read user file, which might override some of our values.
6377     &read_am_file ($amfile, new Automake::Location);
6382 ################################################################
6384 # $FLATTENED
6385 # &flatten ($STRING)
6386 # ------------------
6387 # Flatten the $STRING and return the result.
6388 sub flatten
6390   $_ = shift;
6392   s/\\\n//somg;
6393   s/\s+/ /g;
6394   s/^ //;
6395   s/ $//;
6397   return $_;
6401 # transform_token ($TOKEN, \%PAIRS, $KEY)
6402 # =======================================
6403 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
6404 # (which should be ?KEY? or any of the special %% requests)..
6405 sub transform_token ($$$)
6407   my ($token, $transform, $key) = @_;
6408   my $res = $transform->{$key};
6409   prog_error "Unknown key `$key' in `$token'" unless defined $res;
6410   return $res;
6414 # transform ($TOKEN, \%PAIRS)
6415 # ===========================
6416 # If ($TOKEN, $VAL) is in %PAIRS:
6417 #   - replaces %KEY% with $VAL,
6418 #   - enables/disables ?KEY? and ?!KEY?,
6419 #   - replaces %?KEY% with TRUE or FALSE.
6420 #   - replaces %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE% with
6421 #     IFTRUE / IFFALSE, as appropriate.
6422 sub transform ($$)
6424   my ($token, $transform) = @_;
6426   # %KEY%.
6427   # Must be before the following pattern to exclude the case
6428   # when there is neither IFTRUE nor IFFALSE.
6429   if ($token =~ /^%([\w\-]+)%$/)
6430     {
6431       return transform_token ($token, $transform, $1);
6432     }
6433   # %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE%.
6434   elsif ($token =~ /^%([\w\-]+)(?:\?([^?:%]+))?(?::([^?:%]+))?%$/)
6435     {
6436       return transform_token ($token, $transform, $1) ? ($2 || '') : ($3 || '');
6437     }
6438   # %?KEY%.
6439   elsif ($token =~ /^%\?([\w\-]+)%$/)
6440     {
6441       return transform_token ($token, $transform, $1) ? 'TRUE' : 'FALSE';
6442     }
6443   # ?KEY? and ?!KEY?.
6444   elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
6445     {
6446       my $neg = ($1 eq '!') ? 1 : 0;
6447       my $val = transform_token ($token, $transform, $2);
6448       return (!!$val == $neg) ? '##%' : '';
6449     }
6450   else
6451     {
6452       prog_error "Unknown request format: $token";
6453     }
6457 # @PARAGRAPHS
6458 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6459 # ------------------------------------------
6460 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6461 # paragraphs.
6462 sub make_paragraphs ($%)
6464   my ($file, %transform) = @_;
6466   # Complete %transform with global options.
6467   # Note that %transform goes last, so it overrides global options.
6468   %transform = ('CYGNUS'      => !! option 'cygnus',
6469                  'MAINTAINER-MODE'
6470                  => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6472                  'LZMA'        => !! option 'dist-lzma',
6473                  'BZIP2'       => !! option 'dist-bzip2',
6474                  'COMPRESS'    => !! option 'dist-tarZ',
6475                  'GZIP'        =>  ! option 'no-dist-gzip',
6476                  'SHAR'        => !! option 'dist-shar',
6477                  'ZIP'         => !! option 'dist-zip',
6479                  'INSTALL-INFO' =>  ! option 'no-installinfo',
6480                  'INSTALL-MAN'  =>  ! option 'no-installman',
6481                  'CK-NEWS'      => !! option 'check-news',
6483                  'SUBDIRS'      => !! var ('SUBDIRS'),
6484                  'TOPDIR_P'     => $relative_dir eq '.',
6486                  'BUILD'    => ($seen_canonical >= AC_CANONICAL_BUILD),
6487                  'HOST'     => ($seen_canonical >= AC_CANONICAL_HOST),
6488                  'TARGET'   => ($seen_canonical >= AC_CANONICAL_TARGET),
6490                  'LIBTOOL'      => !! var ('LIBTOOL'),
6491                  'NONLIBTOOL'   => 1,
6492                  'FIRST'        => ! $transformed_files{$file},
6493                 %transform);
6495   $transformed_files{$file} = 1;
6496   $_ = $am_file_cache{$file};
6498   if (! defined $_)
6499     {
6500       verb "reading $file";
6501       # Swallow the whole file.
6502       my $fc_file = new Automake::XFile "< $file";
6503       my $saved_dollar_slash = $/;
6504       undef $/;
6505       $_ = $fc_file->getline;
6506       $/ = $saved_dollar_slash;
6507       $fc_file->close;
6509       # Remove ##-comments.
6510       # Besides we don't need more than two consecutive new-lines.
6511       s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6513       $am_file_cache{$file} = $_;
6514     }
6516   # Substitute Automake template tokens.
6517   s/(?: % \?? [\w\-]+ %
6518       | % [\w\-]+ (?:\?[^?:%]+)? (?::[^?:%]+)? %
6519       | \? !? [\w\-]+ \?
6520     )/transform($&, \%transform)/gex;
6521   # transform() may have added some ##%-comments to strip.
6522   # (we use `##%' instead of `##' so we can distinguish ##%##%##% from
6523   # ####### and do not remove the latter.)
6524   s/^[ \t]*(?:##%)+.*\n//gm;
6526   # Split at unescaped new lines.
6527   my @lines = split (/(?<!\\)\n/, $_);
6528   my @res;
6530   while (defined ($_ = shift @lines))
6531     {
6532       my $paragraph = $_;
6533       # If we are a rule, eat as long as we start with a tab.
6534       if (/$RULE_PATTERN/smo)
6535         {
6536           while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6537             {
6538               $paragraph .= "\n$_";
6539             }
6540           unshift (@lines, $_);
6541         }
6543       # If we are a comments, eat as much comments as you can.
6544       elsif (/$COMMENT_PATTERN/smo)
6545         {
6546           while (defined ($_ = shift @lines)
6547                  && $_ =~ /$COMMENT_PATTERN/smo)
6548             {
6549               $paragraph .= "\n$_";
6550             }
6551           unshift (@lines, $_);
6552         }
6554       push @res, $paragraph;
6555     }
6557   return @res;
6562 # ($COMMENT, $VARIABLES, $RULES)
6563 # &file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
6564 # -------------------------------------------------------------
6565 # Return contents of a file from $libdir/am, automatically skipping
6566 # macros or rules which are already known. $IS_AM iff the caller is
6567 # reading an Automake file (as opposed to the user's Makefile.am).
6568 sub file_contents_internal ($$$%)
6570     my ($is_am, $file, $where, %transform) = @_;
6572     $where->set ($file);
6574     my $result_vars = '';
6575     my $result_rules = '';
6576     my $comment = '';
6577     my $spacing = '';
6579     # The following flags are used to track rules spanning across
6580     # multiple paragraphs.
6581     my $is_rule = 0;            # 1 if we are processing a rule.
6582     my $discard_rule = 0;       # 1 if the current rule should not be output.
6584     # We save the conditional stack on entry, and then check to make
6585     # sure it is the same on exit.  This lets us conditionally include
6586     # other files.
6587     my @saved_cond_stack = @cond_stack;
6588     my $cond = new Automake::Condition (@cond_stack);
6590     foreach (make_paragraphs ($file, %transform))
6591     {
6592         # FIXME: no line number available.
6593         $where->set ($file);
6595         # Sanity checks.
6596         error $where, "blank line following trailing backslash:\n$_"
6597           if /\\$/;
6598         error $where, "comment following trailing backslash:\n$_"
6599           if /\\#/;
6601         if (/^$/)
6602         {
6603             $is_rule = 0;
6604             # Stick empty line before the incoming macro or rule.
6605             $spacing = "\n";
6606         }
6607         elsif (/$COMMENT_PATTERN/mso)
6608         {
6609             $is_rule = 0;
6610             # Stick comments before the incoming macro or rule.
6611             $comment = "$_\n";
6612         }
6614         # Handle inclusion of other files.
6615         elsif (/$INCLUDE_PATTERN/o)
6616         {
6617             if ($cond != FALSE)
6618               {
6619                 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6620                 $where->push_context ("`$file' included from here");
6621                 # N-ary `.=' fails.
6622                 my ($com, $vars, $rules)
6623                   = file_contents_internal ($is_am, $file, $where, %transform);
6624                 $where->pop_context;
6625                 $comment .= $com;
6626                 $result_vars .= $vars;
6627                 $result_rules .= $rules;
6628               }
6629         }
6631         # Handling the conditionals.
6632         elsif (/$IF_PATTERN/o)
6633           {
6634             $cond = cond_stack_if ($1, $2, $file);
6635           }
6636         elsif (/$ELSE_PATTERN/o)
6637           {
6638             $cond = cond_stack_else ($1, $2, $file);
6639           }
6640         elsif (/$ENDIF_PATTERN/o)
6641           {
6642             $cond = cond_stack_endif ($1, $2, $file);
6643           }
6645         # Handling rules.
6646         elsif (/$RULE_PATTERN/mso)
6647         {
6648           $is_rule = 1;
6649           $discard_rule = 0;
6650           # Separate relationship from optional actions: the first
6651           # `new-line tab" not preceded by backslash (continuation
6652           # line).
6653           my $paragraph = $_;
6654           /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
6655           my ($relationship, $actions) = ($1, $2 || '');
6657           # Separate targets from dependencies: the first colon.
6658           $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6659           my ($targets, $dependencies) = ($1, $2);
6660           # Remove the escaped new lines.
6661           # I don't know why, but I have to use a tmp $flat_deps.
6662           my $flat_deps = &flatten ($dependencies);
6663           my @deps = split (' ', $flat_deps);
6665           foreach (split (' ' , $targets))
6666             {
6667               # FIXME: 1. We are not robust to people defining several targets
6668               # at once, only some of them being in %dependencies.  The
6669               # actions from the targets in %dependencies are usually generated
6670               # from the content of %actions, but if some targets in $targets
6671               # are not in %dependencies the ELSE branch will output
6672               # a rule for all $targets (i.e. the targets which are both
6673               # in %dependencies and $targets will have two rules).
6675               # FIXME: 2. The logic here is not able to output a
6676               # multi-paragraph rule several time (e.g. for each condition
6677               # it is defined for) because it only knows the first paragraph.
6679               # FIXME: 3. We are not robust to people defining a subset
6680               # of a previously defined "multiple-target" rule.  E.g.
6681               # `foo:' after `foo bar:'.
6683               # Output only if not in FALSE.
6684               if (defined $dependencies{$_} && $cond != FALSE)
6685                 {
6686                   &depend ($_, @deps);
6687                   register_action ($_, $actions);
6688                 }
6689               else
6690                 {
6691                   # Free-lance dependency.  Output the rule for all the
6692                   # targets instead of one by one.
6693                   my @undefined_conds =
6694                     Automake::Rule::define ($targets, $file,
6695                                             $is_am ? RULE_AUTOMAKE : RULE_USER,
6696                                             $cond, $where);
6697                   for my $undefined_cond (@undefined_conds)
6698                     {
6699                       my $condparagraph = $paragraph;
6700                       $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
6701                       $result_rules .= "$spacing$comment$condparagraph\n";
6702                     }
6703                   if (scalar @undefined_conds == 0)
6704                     {
6705                       # Remember to discard next paragraphs
6706                       # if they belong to this rule.
6707                       # (but see also FIXME: #2 above.)
6708                       $discard_rule = 1;
6709                     }
6710                   $comment = $spacing = '';
6711                   last;
6712                 }
6713             }
6714         }
6716         elsif (/$ASSIGNMENT_PATTERN/mso)
6717         {
6718             my ($var, $type, $val) = ($1, $2, $3);
6719             error $where, "variable `$var' with trailing backslash"
6720               if /\\$/;
6722             $is_rule = 0;
6724             Automake::Variable::define ($var,
6725                                         $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
6726                                         $type, $cond, $val, $comment, $where,
6727                                         VAR_ASIS)
6728               if $cond != FALSE;
6730             $comment = $spacing = '';
6731         }
6732         else
6733         {
6734             # This isn't an error; it is probably some tokens which
6735             # configure is supposed to replace, such as `@SET-MAKE@',
6736             # or some part of a rule cut by an if/endif.
6737             if (! $cond->false && ! ($is_rule && $discard_rule))
6738               {
6739                 s/^/$cond->subst_string/gme;
6740                 $result_rules .= "$spacing$comment$_\n";
6741               }
6742             $comment = $spacing = '';
6743         }
6744     }
6746     error ($where, @cond_stack ?
6747            "unterminated conditionals: @cond_stack" :
6748            "too many conditionals closed in include file")
6749       if "@saved_cond_stack" ne "@cond_stack";
6751     return ($comment, $result_vars, $result_rules);
6755 # $CONTENTS
6756 # &file_contents ($BASENAME, $WHERE, [%TRANSFORM])
6757 # ------------------------------------------------
6758 # Return contents of a file from $libdir/am, automatically skipping
6759 # macros or rules which are already known.
6760 sub file_contents ($$%)
6762     my ($basename, $where, %transform) = @_;
6763     my ($comments, $variables, $rules) =
6764       file_contents_internal (1, "$libdir/am/$basename.am", $where,
6765                               %transform);
6766     return "$comments$variables$rules";
6770 # @PREFIX
6771 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
6772 # -----------------------------------------------------
6773 # Find all variable prefixes that are used for install directories.  A
6774 # prefix `zar' qualifies iff:
6776 # * `zardir' is a variable.
6777 # * `zar_PRIMARY' is a variable.
6779 # As a side effect, it looks for misspellings.  It is an error to have
6780 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
6781 # "bni_PROGRAMS".  However, unusual prefixes are allowed if a variable
6782 # of the same name (with "dir" appended) exists.  For instance, if the
6783 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
6784 # This is to provide a little extra flexibility in those cases which
6785 # need it.
6786 sub am_primary_prefixes ($$@)
6788   my ($primary, $can_dist, @prefixes) = @_;
6790   local $_;
6791   my %valid = map { $_ => 0 } @prefixes;
6792   $valid{'EXTRA'} = 0;
6793   foreach my $var (variables $primary)
6794     {
6795       # Automake is allowed to define variables that look like primaries
6796       # but which aren't.  E.g. INSTALL_sh_DATA.
6797       # Autoconf can also define variables like INSTALL_DATA, so
6798       # ignore all configure variables (at least those which are not
6799       # redefined in Makefile.am).
6800       # FIXME: We should make sure that these variables are not
6801       # conditionally defined (or else adjust the condition below).
6802       my $def = $var->def (TRUE);
6803       next if $def && $def->owner != VAR_MAKEFILE;
6805       my $varname = $var->name;
6807       if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
6808         {
6809           my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
6810           if ($dist ne '' && ! $can_dist)
6811             {
6812               err_var ($var,
6813                        "invalid variable `$varname': `dist' is forbidden");
6814             }
6815           # Standard directories must be explicitly allowed.
6816           elsif (! defined $valid{$X} && exists $standard_prefix{$X})
6817             {
6818               err_var ($var,
6819                        "`${X}dir' is not a legitimate directory " .
6820                        "for `$primary'");
6821             }
6822           # A not explicitly valid directory is allowed if Xdir is defined.
6823           elsif (! defined $valid{$X} &&
6824                  $var->requires_variables ("`$varname' is used", "${X}dir"))
6825             {
6826               # Nothing to do.  Any error message has been output
6827               # by $var->requires_variables.
6828             }
6829           else
6830             {
6831               # Ensure all extended prefixes are actually used.
6832               $valid{"$base$dist$X"} = 1;
6833             }
6834         }
6835       else
6836         {
6837           prog_error "unexpected variable name: $varname";
6838         }
6839     }
6841   # Return only those which are actually defined.
6842   return sort grep { var ($_ . '_' . $primary) } keys %valid;
6846 # Handle `where_HOW' variable magic.  Does all lookups, generates
6847 # install code, and possibly generates code to define the primary
6848 # variable.  The first argument is the name of the .am file to munge,
6849 # the second argument is the primary variable (e.g. HEADERS), and all
6850 # subsequent arguments are possible installation locations.
6852 # Returns list of [$location, $value] pairs, where
6853 # $value's are the values in all where_HOW variable, and $location
6854 # there associated location (the place here their parent variables were
6855 # defined).
6857 # FIXME: this should be rewritten to be cleaner.  It should be broken
6858 # up into multiple functions.
6860 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6861 sub am_install_var
6863   my (@args) = @_;
6865   my $do_require = 1;
6866   my $can_dist = 0;
6867   my $default_dist = 0;
6868   while (@args)
6869     {
6870       if ($args[0] eq '-noextra')
6871         {
6872           $do_require = 0;
6873         }
6874       elsif ($args[0] eq '-candist')
6875         {
6876           $can_dist = 1;
6877         }
6878       elsif ($args[0] eq '-defaultdist')
6879         {
6880           $default_dist = 1;
6881           $can_dist = 1;
6882         }
6883       elsif ($args[0] !~ /^-/)
6884         {
6885           last;
6886         }
6887       shift (@args);
6888     }
6890   my ($file, $primary, @prefix) = @args;
6892   # Now that configure substitutions are allowed in where_HOW
6893   # variables, it is an error to actually define the primary.  We
6894   # allow `JAVA', as it is customarily used to mean the Java
6895   # interpreter.  This is but one of several Java hacks.  Similarly,
6896   # `PYTHON' is customarily used to mean the Python interpreter.
6897   reject_var $primary, "`$primary' is an anachronism"
6898     unless $primary eq 'JAVA' || $primary eq 'PYTHON';
6900   # Get the prefixes which are valid and actually used.
6901   @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
6903   # If a primary includes a configure substitution, then the EXTRA_
6904   # form is required.  Otherwise we can't properly do our job.
6905   my $require_extra;
6907   my @used = ();
6908   my @result = ();
6910   foreach my $X (@prefix)
6911     {
6912       my $nodir_name = $X;
6913       my $one_name = $X . '_' . $primary;
6914       my $one_var = var $one_name;
6916       my $strip_subdir = 1;
6917       # If subdir prefix should be preserved, do so.
6918       if ($nodir_name =~ /^nobase_/)
6919         {
6920           $strip_subdir = 0;
6921           $nodir_name =~ s/^nobase_//;
6922         }
6924       # If files should be distributed, do so.
6925       my $dist_p = 0;
6926       if ($can_dist)
6927         {
6928           $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
6929                      || (! $default_dist && $nodir_name =~ /^dist_/));
6930           $nodir_name =~ s/^(dist|nodist)_//;
6931         }
6934       # Use the location of the currently processed variable.
6935       # We are not processing a particular condition, so pick the first
6936       # available.
6937       my $tmpcond = $one_var->conditions->one_cond;
6938       my $where = $one_var->rdef ($tmpcond)->location->clone;
6940       # Append actual contents of where_PRIMARY variable to
6941       # @result, skipping @substitutions@.
6942       foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
6943         {
6944           my ($loc, $value) = @$locvals;
6945           # Skip configure substitutions.
6946           if ($value =~ /^\@.*\@$/)
6947             {
6948               if ($nodir_name eq 'EXTRA')
6949                 {
6950                   error ($where,
6951                          "`$one_name' contains configure substitution, "
6952                          . "but shouldn't");
6953                 }
6954               # Check here to make sure variables defined in
6955               # configure.ac do not imply that EXTRA_PRIMARY
6956               # must be defined.
6957               elsif (! defined $configure_vars{$one_name})
6958                 {
6959                   $require_extra = $one_name
6960                     if $do_require;
6961                 }
6962             }
6963           else
6964             {
6965               push (@result, $locvals);
6966             }
6967         }
6968       # A blatant hack: we rewrite each _PROGRAMS primary to include
6969       # EXEEXT.
6970       append_exeext { 1 } $one_name
6971         if $primary eq 'PROGRAMS';
6972       # "EXTRA" shouldn't be used when generating clean targets,
6973       # all, or install targets.  We used to warn if EXTRA_FOO was
6974       # defined uselessly, but this was annoying.
6975       next
6976         if $nodir_name eq 'EXTRA';
6978       if ($nodir_name eq 'check')
6979         {
6980           push (@check, '$(' . $one_name . ')');
6981         }
6982       else
6983         {
6984           push (@used, '$(' . $one_name . ')');
6985         }
6987       # Is this to be installed?
6988       my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
6990       # If so, with install-exec? (or install-data?).
6991       my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
6993       my $check_options_p = $install_p && !! option 'std-options';
6995       # Use the location of the currently processed variable as context.
6996       $where->push_context ("while processing `$one_name'");
6998       # The variable containing all file to distribute.
6999       my $distvar = "\$($one_name)";
7000       $distvar = shadow_unconditionally ($one_name, $where)
7001         if ($dist_p && $one_var->has_conditional_contents);
7003       # Singular form of $PRIMARY.
7004       (my $one_primary = $primary) =~ s/S$//;
7005       $output_rules .= &file_contents ($file, $where,
7006                                        PRIMARY     => $primary,
7007                                        ONE_PRIMARY => $one_primary,
7008                                        DIR         => $X,
7009                                        NDIR        => $nodir_name,
7010                                        BASE        => $strip_subdir,
7012                                        EXEC      => $exec_p,
7013                                        INSTALL   => $install_p,
7014                                        DIST      => $dist_p,
7015                                        DISTVAR   => $distvar,
7016                                        'CK-OPTS' => $check_options_p);
7017     }
7019   # The JAVA variable is used as the name of the Java interpreter.
7020   # The PYTHON variable is used as the name of the Python interpreter.
7021   if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7022     {
7023       # Define it.
7024       define_pretty_variable ($primary, TRUE, INTERNAL, @used);
7025       $output_vars .= "\n";
7026     }
7028   err_var ($require_extra,
7029            "`$require_extra' contains configure substitution,\n"
7030            . "but `EXTRA_$primary' not defined")
7031     if ($require_extra && ! var ('EXTRA_' . $primary));
7033   # Push here because PRIMARY might be configure time determined.
7034   push (@all, '$(' . $primary . ')')
7035     if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7037   # Make the result unique.  This lets the user use conditionals in
7038   # a natural way, but still lets us program lazily -- we don't have
7039   # to worry about handling a particular object more than once.
7040   # We will keep only one location per object.
7041   my %result = ();
7042   for my $pair (@result)
7043     {
7044       my ($loc, $val) = @$pair;
7045       $result{$val} = $loc;
7046     }
7047   my @l = sort keys %result;
7048   return map { [$result{$_}->clone, $_] } @l;
7052 ################################################################
7054 # Each key in this hash is the name of a directory holding a
7055 # Makefile.in.  These variables are local to `is_make_dir'.
7056 my %make_dirs = ();
7057 my $make_dirs_set = 0;
7059 sub is_make_dir
7061     my ($dir) = @_;
7062     if (! $make_dirs_set)
7063     {
7064         foreach my $iter (@configure_input_files)
7065         {
7066             $make_dirs{dirname ($iter)} = 1;
7067         }
7068         # We also want to notice Makefile.in's.
7069         foreach my $iter (@other_input_files)
7070         {
7071             if ($iter =~ /Makefile\.in$/)
7072             {
7073                 $make_dirs{dirname ($iter)} = 1;
7074             }
7075         }
7076         $make_dirs_set = 1;
7077     }
7078     return defined $make_dirs{$dir};
7081 ################################################################
7083 # Find the aux dir.  This should match the algorithm used by
7084 # ./configure. (See the Autoconf documentation for for
7085 # AC_CONFIG_AUX_DIR.)
7086 sub locate_aux_dir ()
7088   if (! $config_aux_dir_set_in_configure_ac)
7089     {
7090       # The default auxiliary directory is the first
7091       # of ., .., or ../.. that contains install-sh.
7092       # Assume . if install-sh doesn't exist yet.
7093       for my $dir (qw (. .. ../..))
7094         {
7095           if (-f "$dir/install-sh")
7096             {
7097               $config_aux_dir = $dir;
7098               last;
7099             }
7100         }
7101       $config_aux_dir = '.' unless $config_aux_dir;
7102     }
7103   # Avoid unsightly '/.'s.
7104   $am_config_aux_dir =
7105     '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
7106   $am_config_aux_dir =~ s,/*$,,;
7110 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
7111 # --------------------------------------------------
7112 # See if we want to push this file onto dist_common.  This function
7113 # encodes the rules for deciding when to do so.
7114 sub maybe_push_required_file
7116   my ($dir, $file, $fullfile) = @_;
7118   if ($dir eq $relative_dir)
7119     {
7120       push_dist_common ($file);
7121       return 1;
7122     }
7123   elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7124     {
7125       # If we are doing the topmost directory, and the file is in a
7126       # subdir which does not have a Makefile, then we distribute it
7127       # here.
7129       # If a required file is above the source tree, it is important
7130       # to prefix it with `$(srcdir)' so that no VPATH search is
7131       # performed.  Otherwise problems occur with Make implementations
7132       # that rewrite and simplify rules whose dependencies are found in a
7133       # VPATH location.  Here is an example with OSF1/Tru64 Make.
7134       #
7135       #   % cat Makefile
7136       #   VPATH = sub
7137       #   distdir: ../a
7138       #           echo ../a
7139       #   % ls
7140       #   Makefile a
7141       #   % make
7142       #   echo a
7143       #   a
7144       #
7145       # Dependency `../a' was found in `sub/../a', but this make
7146       # implementation simplified it as `a'.  (Note that the sub/
7147       # directory does not even exist.)
7148       #
7149       # This kind of VPATH rewriting seems hard to cancel.  The
7150       # distdir.am hack against VPATH rewriting works only when no
7151       # simplification is done, i.e., for dependencies which are in
7152       # subdirectories, not in enclosing directories.  Hence, in
7153       # the latter case we use a full path to make sure no VPATH
7154       # search occurs.
7155       $fullfile = '$(srcdir)/' . $fullfile
7156         if $dir =~ m,^\.\.(?:$|/),;
7158       push_dist_common ($fullfile);
7159       return 1;
7160     }
7161   return 0;
7165 # If a file name appears as a key in this hash, then it has already
7166 # been checked for.  This allows us not to report the same error more
7167 # than once.
7168 my %required_file_not_found = ();
7170 # &require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, @FILES)
7171 # --------------------------------------------------------------
7172 # Verify that the file must exist in $DIRECTORY, or install it.
7173 # $MYSTRICT is the strictness level at which this file becomes required.
7174 sub require_file_internal ($$$@)
7176   my ($where, $mystrict, $dir, @files) = @_;
7178   foreach my $file (@files)
7179     {
7180       my $fullfile = "$dir/$file";
7181       my $found_it = 0;
7182       my $dangling_sym = 0;
7184       if (-l $fullfile && ! -f $fullfile)
7185         {
7186           $dangling_sym = 1;
7187         }
7188       elsif (dir_has_case_matching_file ($dir, $file))
7189         {
7190           $found_it = 1;
7191           maybe_push_required_file ($dir, $file, $fullfile);
7192         }
7194       # `--force-missing' only has an effect if `--add-missing' is
7195       # specified.
7196       if ($found_it && (! $add_missing || ! $force_missing))
7197         {
7198           next;
7199         }
7200       else
7201         {
7202           # If we've already looked for it, we're done.  You might
7203           # wonder why we don't do this before searching for the
7204           # file.  If we do that, then something like
7205           # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7206           # DIST_COMMON.
7207           if (! $found_it)
7208             {
7209               next if defined $required_file_not_found{$fullfile};
7210               $required_file_not_found{$fullfile} = 1;
7211             }
7213           if ($strictness >= $mystrict)
7214             {
7215               if ($dangling_sym && $add_missing)
7216                 {
7217                   unlink ($fullfile);
7218                 }
7220               my $trailer = '';
7221               my $suppress = 0;
7223               # Only install missing files according to our desired
7224               # strictness level.
7225               my $message = "required file `$fullfile' not found";
7226               if ($add_missing)
7227                 {
7228                   if (-f "$libdir/$file")
7229                     {
7230                       $suppress = 1;
7232                       # Install the missing file.  Symlink if we
7233                       # can, copy if we must.  Note: delete the file
7234                       # first, in case it is a dangling symlink.
7235                       $message = "installing `$fullfile'";
7236                       # Windows Perl will hang if we try to delete a
7237                       # file that doesn't exist.
7238                       unlink ($fullfile) if -f $fullfile;
7239                       if ($symlink_exists && ! $copy_missing)
7240                         {
7241                           if (! symlink ("$libdir/$file", $fullfile))
7242                             {
7243                               $suppress = 0;
7244                               $trailer = "; error while making link: $!";
7245                             }
7246                         }
7247                       elsif (system ('cp', "$libdir/$file", $fullfile))
7248                         {
7249                           $suppress = 0;
7250                           $trailer = "\n    error while copying";
7251                         }
7252                       reset_dir_cache ($dir);
7253                     }
7255                   if (! maybe_push_required_file (dirname ($fullfile),
7256                                                   $file, $fullfile))
7257                     {
7258                       if (! $found_it && ! $automake_will_process_aux_dir)
7259                         {
7260                           # We have added the file but could not push it
7261                           # into DIST_COMMON, probably because this is
7262                           # an auxiliary file and we are not processing
7263                           # the top level Makefile.  Furthermore Automake
7264                           # hasn't been asked to create the Makefile.in
7265                           # that distribute the aux dir files.
7266                           error ($where, 'Please make a full run of automake'
7267                                  . " so $fullfile gets distributed.");
7268                         }
7269                     }
7270                 }
7271               else
7272                 {
7273                   $trailer = "\n  `automake --add-missing' can install `$file'"
7274                     if -f "$libdir/$file";
7275                 }
7277               # If --force-missing was specified, and we have
7278               # actually found the file, then do nothing.
7279               next
7280                 if $found_it && $force_missing;
7282               # If we couldn't install the file, but it is a target in
7283               # the Makefile, don't print anything.  This allows files
7284               # like README, AUTHORS, or THANKS to be generated.
7285               next
7286                 if !$suppress && rule $file;
7288               msg ($suppress ? 'note' : 'error', $where, "$message$trailer");
7289             }
7290         }
7291     }
7294 # &require_file ($WHERE, $MYSTRICT, @FILES)
7295 # -----------------------------------------
7296 sub require_file ($$@)
7298     my ($where, $mystrict, @files) = @_;
7299     require_file_internal ($where, $mystrict, $relative_dir, @files);
7302 # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7303 # -----------------------------------------------------------
7304 sub require_file_with_macro ($$$@)
7306     my ($cond, $macro, $mystrict, @files) = @_;
7307     $macro = rvar ($macro) unless ref $macro;
7308     require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7311 # &require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7312 # ----------------------------------------------------------------
7313 # Require an AC_LIBSOURCEd file.  If AC_CONFIG_LIBOBJ_DIR was called, it
7314 # must be in that directory.  Otherwise expect it in the current directory.
7315 sub require_libsource_with_macro ($$$@)
7317     my ($cond, $macro, $mystrict, @files) = @_;
7318     $macro = rvar ($macro) unless ref $macro;
7319     if ($config_libobj_dir)
7320       {
7321         require_file_internal ($macro->rdef ($cond)->location, $mystrict,
7322                                $config_libobj_dir, @files);
7323       }
7324     else
7325       {
7326         require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7327       }
7330 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
7331 # ----------------------------------------------
7332 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7333 sub require_conf_file ($$@)
7335     my ($where, $mystrict, @files) = @_;
7336     require_file_internal ($where, $mystrict, $config_aux_dir, @files);
7340 # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7341 # ----------------------------------------------------------------
7342 sub require_conf_file_with_macro ($$$@)
7344     my ($cond, $macro, $mystrict, @files) = @_;
7345     require_conf_file (rvar ($macro)->rdef ($cond)->location,
7346                        $mystrict, @files);
7349 ################################################################
7351 # &require_build_directory ($DIRECTORY)
7352 # ------------------------------------
7353 # Emit rules to create $DIRECTORY if needed, and return
7354 # the file that any target requiring this directory should be made
7355 # dependent upon.
7356 # We don't want to emit the rule twice, and want to reuse it
7357 # for directories with equivalent names (e.g., `foo/bar' and `./foo//bar').
7358 sub require_build_directory ($)
7360   my $directory = shift;
7362   return $directory_map{$directory} if exists $directory_map{$directory};
7364   my $cdir = File::Spec->canonpath ($directory);
7366   if (exists $directory_map{$cdir})
7367     {
7368       my $stamp = $directory_map{$cdir};
7369       $directory_map{$directory} = $stamp;
7370       return $stamp;
7371     }
7373   my $dirstamp = "$cdir/\$(am__dirstamp)";
7375   $directory_map{$directory} = $dirstamp;
7376   $directory_map{$cdir} = $dirstamp;
7378   # Set a variable for the dirstamp basename.
7379   define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
7380                           '$(am__leading_dot)dirstamp');
7382   # Directory must be removed by `make distclean'.
7383   $clean_files{$dirstamp} = DIST_CLEAN;
7385   $output_rules .= ("$dirstamp:\n"
7386                     . "\t\@\$(MKDIR_P) $directory\n"
7387                     . "\t\@: > $dirstamp\n");
7389   return $dirstamp;
7392 # &require_build_directory_maybe ($FILE)
7393 # --------------------------------------
7394 # If $FILE lies in a subdirectory, emit a rule to create this
7395 # directory and return the file that $FILE should be made
7396 # dependent upon.  Otherwise, just return the empty string.
7397 sub require_build_directory_maybe ($)
7399     my $file = shift;
7400     my $directory = dirname ($file);
7402     if ($directory ne '.')
7403     {
7404         return require_build_directory ($directory);
7405     }
7406     else
7407     {
7408         return '';
7409     }
7412 ################################################################
7414 # Push a list of files onto dist_common.
7415 sub push_dist_common
7417   prog_error "push_dist_common run after handle_dist"
7418     if $handle_dist_run;
7419   Automake::Variable::define ('DIST_COMMON', VAR_AUTOMAKE, '+', TRUE, "@_",
7420                               '', INTERNAL, VAR_PRETTY);
7424 ################################################################
7426 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
7427 # ----------------------------------------------
7428 # Generate a Makefile.in given the name of the corresponding Makefile and
7429 # the name of the file output by config.status.
7430 sub generate_makefile ($$)
7432   my ($makefile_am, $makefile_in) = @_;
7434   # Reset all the Makefile.am related variables.
7435   initialize_per_input;
7437   # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
7438   # warnings for this file.  So hold any warning issued before
7439   # we have processed AUTOMAKE_OPTIONS.
7440   buffer_messages ('warning');
7442   # Name of input file ("Makefile.am") and output file
7443   # ("Makefile.in").  These have no directory components.
7444   $am_file_name = basename ($makefile_am);
7445   $in_file_name = basename ($makefile_in);
7447   # $OUTPUT is encoded.  If it contains a ":" then the first element
7448   # is the real output file, and all remaining elements are input
7449   # files.  We don't scan or otherwise deal with these input files,
7450   # other than to mark them as dependencies.  See
7451   # &scan_autoconf_files for details.
7452   my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
7454   $relative_dir = dirname ($makefile);
7455   $am_relative_dir = dirname ($makefile_am);
7456   $topsrcdir = backname ($relative_dir);
7458   read_main_am_file ($makefile_am);
7459   if (handle_options)
7460     {
7461       # Process buffered warnings.
7462       flush_messages;
7463       # Fatal error.  Just return, so we can continue with next file.
7464       return;
7465     }
7466   # Process buffered warnings.
7467   flush_messages;
7469   # There are a few install-related variables that you should not define.
7470   foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
7471     {
7472       my $v = var $var;
7473       if ($v)
7474         {
7475           my $def = $v->def (TRUE);
7476           prog_error "$var not defined in condition TRUE"
7477             unless $def;
7478           reject_var $var, "`$var' should not be defined"
7479             if $def->owner != VAR_AUTOMAKE;
7480         }
7481     }
7483   # Catch some obsolete variables.
7484   msg_var ('obsolete', 'INCLUDES',
7485            "`INCLUDES' is the old name for `AM_CPPFLAGS' (or `*_CPPFLAGS')")
7486     if var ('INCLUDES');
7488   # Must do this after reading .am file.
7489   define_variable ('subdir', $relative_dir, INTERNAL);
7491   # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
7492   # recursive rules are enabled.
7493   define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
7494     if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
7496   # Check first, because we might modify some state.
7497   check_cygnus;
7498   check_gnu_standards;
7499   check_gnits_standards;
7501   handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
7502   handle_gettext;
7503   handle_libraries;
7504   handle_ltlibraries;
7505   handle_programs;
7506   handle_scripts;
7508   # These must be run after all the sources are scanned.  They
7509   # use variables defined by &handle_libraries, &handle_ltlibraries,
7510   # or &handle_programs.
7511   handle_compile;
7512   handle_languages;
7513   handle_libtool;
7515   # Variables used by distdir.am and tags.am.
7516   define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
7517   if (! option 'no-dist')
7518     {
7519       define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
7520     }
7522   handle_multilib;
7523   handle_texinfo;
7524   handle_emacs_lisp;
7525   handle_python;
7526   handle_java;
7527   handle_man_pages;
7528   handle_data;
7529   handle_headers;
7530   handle_subdirs;
7531   handle_tags;
7532   handle_minor_options;
7533   # Must come after handle_programs so that %known_programs is up-to-date.
7534   handle_tests;
7536   # This must come after most other rules.
7537   handle_dist;
7539   handle_footer;
7540   do_check_merge_target;
7541   handle_all ($makefile);
7543   # FIXME: Gross!
7544   if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7545     {
7546       $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
7547     }
7549   handle_install;
7550   handle_clean ($makefile);
7551   handle_factored_dependencies;
7553   # Comes last, because all the above procedures may have
7554   # defined or overridden variables.
7555   $output_vars .= output_variables;
7557   check_typos;
7559   my ($out_file) = $output_directory . '/' . $makefile_in;
7561   if ($exit_code != 0)
7562     {
7563       verb "not writing $out_file because of earlier errors";
7564       return;
7565     }
7567   if (! -d ($output_directory . '/' . $am_relative_dir))
7568     {
7569       mkdir ($output_directory . '/' . $am_relative_dir, 0755);
7570     }
7572   # We make sure that `all:' is the first target.
7573   my $output =
7574     "$output_vars$output_all$output_header$output_rules$output_trailer";
7576   # Decide whether we must update the output file or not.
7577   # We have to update in the following situations.
7578   #  * $force_generation is set.
7579   #  * any of the output dependencies is younger than the output
7580   #  * the contents of the output is different (this can happen
7581   #    if the project has been populated with a file listed in
7582   #    @common_files since the last run).
7583   # Output's dependencies are split in two sets:
7584   #  * dependencies which are also configure dependencies
7585   #    These do not change between each Makefile.am
7586   #  * other dependencies, specific to the Makefile.am being processed
7587   #    (such as the Makefile.am itself, or any Makefile fragment
7588   #    it includes).
7589   my $timestamp = mtime $out_file;
7590   if (! $force_generation
7591       && $configure_deps_greatest_timestamp < $timestamp
7592       && $output_deps_greatest_timestamp < $timestamp
7593       && $output eq contents ($out_file))
7594     {
7595       verb "$out_file unchanged";
7596       # No need to update.
7597       return;
7598     }
7600   if (-e $out_file)
7601     {
7602       unlink ($out_file)
7603         or fatal "cannot remove $out_file: $!\n";
7604     }
7606   my $gm_file = new Automake::XFile "> $out_file";
7607   verb "creating $out_file";
7608   print $gm_file $output;
7611 ################################################################
7616 ################################################################
7618 # Print usage information.
7619 sub usage ()
7621     print "Usage: $0 [OPTION] ... [Makefile]...
7623 Generate Makefile.in for configure from Makefile.am.
7625 Operation modes:
7626       --help               print this help, then exit
7627       --version            print version number, then exit
7628   -v, --verbose            verbosely list files processed
7629       --no-force           only update Makefile.in's that are out of date
7630   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
7632 Dependency tracking:
7633   -i, --ignore-deps      disable dependency tracking code
7634       --include-deps     enable dependency tracking code
7636 Flavors:
7637       --cygnus           assume program is part of Cygnus-style tree
7638       --foreign          set strictness to foreign
7639       --gnits            set strictness to gnits
7640       --gnu              set strictness to gnu
7642 Library files:
7643   -a, --add-missing      add missing standard files to package
7644       --libdir=DIR       directory storing library files
7645   -c, --copy             with -a, copy missing files (default is symlink)
7646   -f, --force-missing    force update of standard files
7649     Automake::ChannelDefs::usage;
7651     my ($last, @lcomm);
7652     $last = '';
7653     foreach my $iter (sort ((@common_files, @common_sometimes)))
7654     {
7655         push (@lcomm, $iter) unless $iter eq $last;
7656         $last = $iter;
7657     }
7659     my @four;
7660     print "\nFiles which are automatically distributed, if found:\n";
7661     format USAGE_FORMAT =
7662   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7663   $four[0],           $four[1],           $four[2],           $four[3]
7665     $~ = "USAGE_FORMAT";
7667     my $cols = 4;
7668     my $rows = int(@lcomm / $cols);
7669     my $rest = @lcomm % $cols;
7671     if ($rest)
7672     {
7673         $rows++;
7674     }
7675     else
7676     {
7677         $rest = $cols;
7678     }
7680     for (my $y = 0; $y < $rows; $y++)
7681     {
7682         @four = ("", "", "", "");
7683         for (my $x = 0; $x < $cols; $x++)
7684         {
7685             last if $y + 1 == $rows && $x == $rest;
7687             my $idx = (($x > $rest)
7688                        ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
7689                        : ($rows * $x));
7691             $idx += $y;
7692             $four[$x] = $lcomm[$idx];
7693         }
7694         write;
7695     }
7697     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7699     # --help always returns 0 per GNU standards.
7700     exit 0;
7704 # &version ()
7705 # -----------
7706 # Print version information
7707 sub version ()
7709   print <<EOF;
7710 automake (GNU $PACKAGE) $VERSION
7711 Copyright (C) 2007 Free Software Foundation, Inc.
7712 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
7713 This is free software: you are free to change and redistribute it.
7714 There is NO WARRANTY, to the extent permitted by law.
7716 Written by Tom Tromey <tromey\@redhat.com>
7717        and Alexandre Duret-Lutz <adl\@gnu.org>.
7719   # --version always returns 0 per GNU standards.
7720   exit 0;
7723 ################################################################
7725 # Parse command line.
7726 sub parse_arguments ()
7728   # Start off as gnu.
7729   set_strictness ('gnu');
7731   my $cli_where = new Automake::Location;
7732   my %cli_options =
7733     (
7734      'libdir=s' => \$libdir,
7735      'gnu'              => sub { set_strictness ('gnu'); },
7736      'gnits'            => sub { set_strictness ('gnits'); },
7737      'cygnus'           => sub { set_global_option ('cygnus', $cli_where); },
7738      'foreign'          => sub { set_strictness ('foreign'); },
7739      'include-deps'     => sub { unset_global_option ('no-dependencies'); },
7740      'i|ignore-deps'    => sub { set_global_option ('no-dependencies',
7741                                                     $cli_where); },
7742      'no-force' => sub { $force_generation = 0; },
7743      'f|force-missing'  => \$force_missing,
7744      'o|output-dir=s'   => \$output_directory,
7745      'a|add-missing'    => \$add_missing,
7746      'c|copy'           => \$copy_missing,
7747      'v|verbose'        => sub { setup_channel 'verb', silent => 0; },
7748      'W|warnings=s'     => \&parse_warnings,
7749      # These long options (--Werror and --Wno-error) for backward
7750      # compatibility.  Use -Werror and -Wno-error today.
7751      'Werror'           => sub { parse_warnings 'W', 'error'; },
7752      'Wno-error'        => sub { parse_warnings 'W', 'no-error'; },
7753      );
7754   use Getopt::Long;
7755   Getopt::Long::config ("bundling", "pass_through");
7757   # See if --version or --help is used.  We want to process these before
7758   # anything else because the GNU Coding Standards require us to
7759   # `exit 0' after processing these options, and we can't guarantee this
7760   # if we treat other options first.  (Handling other options first
7761   # could produce error diagnostics, and in this condition it is
7762   # confusing if Automake does `exit 0'.)
7763   my %cli_options_1st_pass =
7764     (
7765      'version' => \&version,
7766      'help'    => \&usage,
7767      # Recognize all other options (and their arguments) but do nothing.
7768      map { $_ => sub {} } (keys %cli_options)
7769      );
7770   my @ARGV_backup = @ARGV;
7771   Getopt::Long::GetOptions %cli_options_1st_pass
7772     or exit 1;
7773   @ARGV = @ARGV_backup;
7775   # Now *really* process the options.  This time we know that --help
7776   # and --version are not present, but we specify them nonetheless so
7777   # that ambiguous abbreviation are diagnosed.
7778   Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
7779     or exit 1;
7781   if (defined $output_directory)
7782     {
7783       msg 'obsolete', "`--output-dir' is deprecated\n";
7784     }
7785   else
7786     {
7787       # In the next release we'll remove this entirely.
7788       $output_directory = '.';
7789     }
7791   return unless @ARGV;
7793   if ($ARGV[0] =~ /^-./)
7794     {
7795       my %argopts;
7796       for my $k (keys %cli_options)
7797         {
7798           if ($k =~ /(.*)=s$/)
7799             {
7800               map { $argopts{(length ($_) == 1)
7801                              ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
7802             }
7803         }
7804       if ($ARGV[0] eq '--')
7805         {
7806           shift @ARGV;
7807         }
7808       elsif (exists $argopts{$ARGV[0]})
7809         {
7810           fatal ("option `$ARGV[0]' requires an argument\n"
7811                  . "Try `$0 --help' for more information.");
7812         }
7813       else
7814         {
7815           fatal ("unrecognized option `$ARGV[0]'.\n"
7816                  . "Try `$0 --help' for more information.");
7817         }
7818     }
7820   my $errspec = 0;
7821   foreach my $arg (@ARGV)
7822     {
7823       fatal ("empty argument\nTry `$0 --help' for more information.")
7824         if ($arg eq '');
7826       # Handle $local:$input syntax.
7827       my ($local, @rest) = split (/:/, $arg);
7828       @rest = ("$local.in",) unless @rest;
7829       my $input = locate_am @rest;
7830       if ($input)
7831         {
7832           push @input_files, $input;
7833           $output_files{$input} = join (':', ($local, @rest));
7834         }
7835       else
7836         {
7837           error "no Automake input file found for `$arg'";
7838           $errspec = 1;
7839         }
7840     }
7841   fatal "no input file found among supplied arguments"
7842     if $errspec && ! @input_files;
7845 ################################################################
7847 # Parse the WARNINGS environment variable.
7848 parse_WARNINGS;
7850 # Parse command line.
7851 parse_arguments;
7853 $configure_ac = require_configure_ac;
7855 # Do configure.ac scan only once.
7856 scan_autoconf_files;
7858 if (! @input_files)
7859   {
7860     my $msg = '';
7861     $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
7862       if -f 'Makefile.am';
7863     fatal ("no `Makefile.am' found for any configure output$msg");
7864   }
7866 # Now do all the work on each file.
7867 foreach my $file (@input_files)
7868   {
7869     ($am_file = $file) =~ s/\.in$//;
7870     if (! -f ($am_file . '.am'))
7871       {
7872         error "`$am_file.am' does not exist";
7873       }
7874     else
7875       {
7876         # Any warning setting now local to this Makefile.am.
7877         dup_channel_setup;
7879         generate_makefile ($am_file . '.am', $file);
7881         # Back out any warning setting.
7882         drop_channel_setup;
7883       }
7884   }
7886 exit $exit_code;
7889 ### Setup "GNU" style for perl-mode and cperl-mode.
7890 ## Local Variables:
7891 ## perl-indent-level: 2
7892 ## perl-continued-statement-offset: 2
7893 ## perl-continued-brace-offset: 0
7894 ## perl-brace-offset: 0
7895 ## perl-brace-imaginary-offset: 0
7896 ## perl-label-offset: -2
7897 ## cperl-indent-level: 2
7898 ## cperl-brace-offset: 0
7899 ## cperl-continued-brace-offset: 0
7900 ## cperl-label-offset: -2
7901 ## cperl-extra-newline-before-brace: t
7902 ## cperl-merge-trailing-else: nil
7903 ## cperl-continued-statement-offset: 2
7904 ## End: