source: trunk/essentials/sys-devel/automake-1.9/automake.in@ 3441

Last change on this file since 3441 was 3143, checked in by bird, 18 years ago

Unixroot and one silly ':' issue.

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