source: trunk/essentials/sys-devel/automake-1.8/automake.in@ 3140

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

Unixroot.

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