source: vendor/automake/1.8.5/automake.in@ 3688

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

automake 1.8.5

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