source: vendor/automake/1.9.6/automake.in@ 3086

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

automake 1.9.6

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