source: trunk/essentials/sys-devel/automake-1.10/automake.in@ 3320

Last change on this file since 3320 was 3150, checked in by bird, 18 years ago

Unixroot and the drive letter fix.

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