summaryrefslogtreecommitdiff
path: root/lib/Automake/Global.pm
blob: 2288d655aea540006e310061deb809f7d465f928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# Copyright (C) 2018  Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package Automake::Global;

use 5.006;
use strict;
use Exporter;

use Automake::Location;

use vars qw (@ISA @EXPORT);

@ISA = qw (Exporter);

@EXPORT = qw ($IGNORE_PATTERN $WHITE_PATTERN $COMMENT_PATTERN $RULE_PATTERN
    $ASSIGNMENT_PATTERN $GNITS_VERSION_PATTERN $IF_PATTERN $ELSE_PATTERN
    $ENDIF_PATTERN $PATH_PATTERN $INCLUDE_PATTERN $EXEC_DIR_PATTERN
    @libtool_files @libtool_sometimes @common_files @common_sometimes
    %standard_prefix $force_generation $symlink_exists $add_missing
    $copy_missing $force_missing %libsources @config_headers @config_links
    @input_files %output_files @configure_input_files @other_input_files
    %ac_config_files_location %ac_config_files_condition $config_aux_dir
    $config_aux_dir_set_in_configure_ac $am_config_aux_dir $config_libobj_dir
    $seen_gettext $seen_gettext_external $seen_gettext_intl
    @extra_recursive_targets %libtool_tags $libtool_new_api $seen_canonical
    $package_version $seen_ar %required_aux_file $seen_init_automake
    $seen_automake_version %configure_vars %ignored_configure_vars
    @configure_deps $configure_deps_greatest_timestamp %configure_cond
    %extension_map @configure_dist_common %languages %link_languages
    %sourceflags %required_targets $am_file $configure_ac $ac_gettext_location
    $seen_maint_mode $package_version_location $required_conf_file_queue
    $relative_dir $output_deps_greatest_timestamp $output_vars $output_all
    $output_header $output_rules $output_trailer @cond_stack @include_stack
    @all @check @check_tests %clean_files %compile_clean_files
    %libtool_clean_directories @sources @dist_sources %object_map
    %object_compilation_map %directory_map %dep_files @dist_targets @proglist
    @liblist @ltliblist @dup_shortnames %known_programs %known_libraries
    %extension_seen %language_scratch %lang_specific_files @dist_common
    $handle_dist_run %linkers_used $need_link $must_handle_compiled_objects
    %transformed_files %am_file_cache AC_CANONICAL_BUILD AC_CANONICAL_HOST
    AC_CANONICAL_TARGET MOSTLY_CLEAN CLEAN DIST_CLEAN MAINTAINER_CLEAN
    LANG_IGNORE LANG_PROCESS LANG_SUBDIR COMPILE_LIBTOOL COMPILE_ORDINARY
    INTERNAL QUEUE_MESSAGE QUEUE_CONF_FILE QUEUE_LOCATION QUEUE_STRING);

## ----------- ##
## Constants.  ##
## ----------- ##

# Some regular expressions.  One reason to put them here is that it
# makes indentation work better in Emacs.

# Writing singled-quoted-$-terminated regexes is a pain because
# perl-mode thinks of $' as the ${'} variable (instead of a $ followed
# by a closing quote.  Letting perl-mode think the quote is not closed
# leads to all sort of misindentations.  On the other hand, defining
# regexes as double-quoted strings is far less readable.  So usually
# we will write:
#
#  $REGEX = '^regex_value' . "\$";

our $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
our $WHITE_PATTERN = '^\s*' . "\$";
our $COMMENT_PATTERN = '^#';
our $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
# A rule has three parts: a list of targets, a list of dependencies,
# and optionally actions.
our $RULE_PATTERN =
  "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";

# Only recognize leading spaces, not leading tabs.  If we recognize
# leading tabs here then we need to make the reader smarter, because
# otherwise it will think rules like 'foo=bar; \' are errors.
our $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
# This pattern recognizes a Gnits version id and sets $1 if the
# release is an alpha release.  We also allow a suffix which can be
# used to extend the version number with a "fork" identifier.
our $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';

our $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
our $ELSE_PATTERN =
  '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
our $ENDIF_PATTERN =
  '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
our $PATH_PATTERN = '(\w|[+/.-])+';
# This will pass through anything not of the prescribed form.
our $INCLUDE_PATTERN = ('^include\s+'
		       . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
		       . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
		       . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");

# Directories installed during 'install-exec' phase.
our $EXEC_DIR_PATTERN =
  '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";

# Values for AC_CANONICAL_*
use constant AC_CANONICAL_BUILD  => 1;
use constant AC_CANONICAL_HOST   => 2;
use constant AC_CANONICAL_TARGET => 3;

# Values indicating when something should be cleaned.
use constant MOSTLY_CLEAN     => 0;
use constant CLEAN            => 1;
use constant DIST_CLEAN       => 2;
use constant MAINTAINER_CLEAN => 3;

# Libtool files.
our @libtool_files = qw(ltmain.sh config.guess config.sub);
# ltconfig appears here for compatibility with old versions of libtool.
our @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);

# Commonly found files we look for and automatically include in
# DISTFILES.
our @common_files =
    (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
	COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
	ar-lib compile config.guess config.rpath
	config.sub depcomp install-sh libversion.in mdate-sh
	missing mkinstalldirs py-compile texinfo.tex ylwrap),
     @libtool_files, @libtool_sometimes);

# Commonly used files we auto-include, but only sometimes.  This list
# is used for the --help output only.
our @common_sometimes =
  qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
     configure.ac configure.in stamp-vti);

# Standard directories from the GNU Coding Standards, and additional
# pkg* directories from Automake.  Stored in a hash for fast member check.
our %standard_prefix =
    map { $_ => 1 } (qw(bin data dataroot doc dvi exec html include info
			lib libexec lisp locale localstate man man1 man2
			man3 man4 man5 man6 man7 man8 man9 oldinclude pdf
			pkgdata pkginclude pkglib pkglibexec ps sbin
			sharedstate sysconf));

# These constants are returned by the lang_*_rewrite functions.
# LANG_SUBDIR means that the resulting object file should be in a
# subdir if the source file is.  In this case the file name cannot
# have '..' components.
use constant LANG_IGNORE  => 0;
use constant LANG_PROCESS => 1;
use constant LANG_SUBDIR  => 2;

# These are used when keeping track of whether an object can be built
# by two different paths.
use constant COMPILE_LIBTOOL  => 1;
use constant COMPILE_ORDINARY => 2;

# We can't always associate a location to a variable or a rule,
# when it's defined by Automake.  We use INTERNAL in this case.
use constant INTERNAL => new Automake::Location;

# Serialization keys for message queues.
use constant QUEUE_MESSAGE   => "msg";
use constant QUEUE_CONF_FILE => "conf file";
use constant QUEUE_LOCATION  => "location";
use constant QUEUE_STRING    => "string";

## ---------------------------------- ##
## Variables related to the options.  ##
## ---------------------------------- ##

# TRUE if we should always generate Makefile.in.
our $force_generation = 1;

# From the Perl manual.
our $symlink_exists = (eval 'symlink ("", "");', $@ eq '');

# TRUE if missing standard files should be installed.
our $add_missing = 0;

# TRUE if we should copy missing files; otherwise symlink if possible.
our $copy_missing = 0;

# TRUE if we should always update files that we know about.
our $force_missing = 0;


## ---------------------------------------- ##
## Variables filled during files scanning.  ##
## ---------------------------------------- ##

# Name of the configure.ac file.
our $configure_ac;

# Files found by scanning configure.ac for LIBOBJS.
our %libsources = ();

# Names used in AC_CONFIG_HEADERS call.
our @config_headers = ();

# Names used in AC_CONFIG_LINKS call.
our @config_links = ();

# List of Makefile.am's to process, and their corresponding outputs.
our @input_files = ();
our %output_files = ();

# Complete list of Makefile.am's that exist.
our @configure_input_files = ();

# List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
# and their outputs.
our @other_input_files = ();
# Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADERS
# appears.  The keys are the files created by these macros.
our %ac_config_files_location = ();
# The condition under which AC_CONFIG_FOOS appears.
our %ac_config_files_condition = ();

# Directory to search for configure-required files.  This
# will be computed by locate_aux_dir() and can be set using
# AC_CONFIG_AUX_DIR in configure.ac.
# $CONFIG_AUX_DIR is the 'raw' directory, valid only in the source-tree.
our $config_aux_dir = '';
our $config_aux_dir_set_in_configure_ac = 0;
# $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
# in Makefiles.
our $am_config_aux_dir = '';

# Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
# in configure.ac.
our $config_libobj_dir = '';

# Whether AM_GNU_GETTEXT has been seen in configure.ac.
our $seen_gettext = 0;
# Whether AM_GNU_GETTEXT([external]) is used.
our $seen_gettext_external = 0;
# Where AM_GNU_GETTEXT appears.
our $ac_gettext_location;
# Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
our $seen_gettext_intl = 0;

# The arguments of the AM_EXTRA_RECURSIVE_TARGETS call (if any).
our @extra_recursive_targets = ();

# Lists of tags supported by Libtool.
our %libtool_tags = ();
# 1 if Libtool uses LT_SUPPORTED_TAG.  If it does, then it also
# uses AC_REQUIRE_AUX_FILE.
our $libtool_new_api = 0;

# Most important AC_CANONICAL_* macro seen so far.
our $seen_canonical = 0;

# Where AM_MAINTAINER_MODE appears.
our $seen_maint_mode;

# Actual version we've seen.
our $package_version = '';

# Where version is defined.
our $package_version_location;

# TRUE if we've seen AM_PROG_AR
our $seen_ar = 0;

# Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
our %required_aux_file = ();

# Where AM_INIT_AUTOMAKE is called.
our $seen_init_automake = 0;

# TRUE if we've seen AM_AUTOMAKE_VERSION.
our $seen_automake_version = 0;

# Hash table of discovered configure substitutions.  Keys are names,
# values are 'FILE:LINE' strings which are used by error message
# generation.
our %configure_vars = ();

# Ignored configure substitutions (i.e., variables not to be output in
# Makefile.in)
our %ignored_configure_vars = ();

# Files included by $configure_ac.
our @configure_deps = ();

# Greatest timestamp of configure's dependencies.
our $configure_deps_greatest_timestamp = 0;

# Hash table of AM_CONDITIONAL variables seen in configure.
our %configure_cond = ();

# This maps extensions onto language names.
our %extension_map = ();

# List of the DIST_COMMON files we discovered while reading
# configure.ac.
our @configure_dist_common = ();

# This maps languages names onto objects.
our %languages = ();
# Maps each linker variable onto a language object.
our %link_languages = ();

# maps extensions to needed source flags.
our %sourceflags = ();

# List of targets we must always output.
# FIXME: Complete, and remove falsely required targets.
our %required_targets =
  (
   'all'          => 1,
   'dvi'	  => 1,
   'pdf'	  => 1,
   'ps'		  => 1,
   'info'	  => 1,
   'install-info' => 1,
   'install'      => 1,
   'install-data' => 1,
   'install-exec' => 1,
   'uninstall'    => 1,

   # FIXME: Not required, temporary hacks.
   # Well, actually they are sort of required: the -recursive
   # targets will run them anyway...
   'html-am'         => 1,
   'dvi-am'          => 1,
   'pdf-am'          => 1,
   'ps-am'           => 1,
   'info-am'         => 1,
   'install-data-am' => 1,
   'install-exec-am' => 1,
   'install-html-am' => 1,
   'install-dvi-am'  => 1,
   'install-pdf-am'  => 1,
   'install-ps-am'   => 1,
   'install-info-am' => 1,
   'installcheck-am' => 1,
   'uninstall-am'    => 1,
   'tags-am'         => 1,
   'ctags-am'        => 1,
   'cscopelist-am'   => 1,
   'install-man'     => 1,
  );

# Queue to push require_conf_file requirements to.
our $required_conf_file_queue;

# The name of the Makefile currently being processed.
our $am_file = 'BUG';

################################################################

## ------------------------------------------ ##
## Variables reset by &initialize_per_input.  ##
## ------------------------------------------ ##

# Relative dir of the output makefile.
our $relative_dir;

# Greatest timestamp of the output's dependencies (excluding
# configure's dependencies).
our $output_deps_greatest_timestamp;

# These variables are used when generating each Makefile.in.
# They hold the Makefile.in until it is ready to be printed.
our $output_vars;
our $output_all;
our $output_header;
our $output_rules;
our $output_trailer;

# This is the conditional stack, updated on if/else/endif, and
# used to build Condition objects.
our @cond_stack;

# This holds the set of included files.
our @include_stack;

# List of dependencies for the obvious targets.
our @all;
our @check;
our @check_tests;

# Keys in this hash table are files to delete.  The associated
# value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
our %clean_files;

# Keys in this hash table are object files or other files in
# subdirectories which need to be removed.  This only holds files
# which are created by compilations.  The value in the hash indicates
# when the file should be removed.
our %compile_clean_files;

# Keys in this hash table are directories where we expect to build a
# libtool object.  We use this information to decide what directories
# to delete.
our %libtool_clean_directories;

# Value of $(SOURCES), used by tags.am.
our @sources;
# Sources which go in the distribution.
our @dist_sources;

# This hash maps object file names onto their corresponding source
# file names.  This is used to ensure that each object is created
# by a single source file.
our %object_map;

# This hash maps object file names onto an integer value representing
# whether this object has been built via ordinary compilation or
# libtool compilation (the COMPILE_* constants).
our %object_compilation_map;


# This keeps track of the directories for which we've already
# created dirstamp code.  Keys are directories, values are stamp files.
# Several keys can share the same stamp files if they are equivalent
# (as are './/foo' and 'foo').
our %directory_map;

# All .P files.
our %dep_files;

# This is a list of all targets to run during "make dist".
our @dist_targets;

# List of all programs, libraries and ltlibraries as returned
# by am_install_var
our @proglist;
our @liblist;
our @ltliblist;
# Blacklist of targets (as canonical base name) for which object file names
# may not be automatically shortened
our @dup_shortnames;

# Keep track of all programs declared in this Makefile, without
# $(EXEEXT).  @substitutions@ are not listed.
our %known_programs;
our %known_libraries;

# This keeps track of which extensions we've seen (that we care
# about).
our %extension_seen;

# This is random scratch space for the language finish functions.
# Don't randomly overwrite it; examine other uses of keys first.
our %language_scratch;

# We keep track of which objects need special (per-executable)
# handling on a per-language basis.
our %lang_specific_files;

# List of distributed files to be put in DIST_COMMON.
our @dist_common;

# This is set when 'handle_dist' has finished.  Once this happens,
# we should no longer push on dist_common.
our $handle_dist_run;

# Used to store a set of linkers needed to generate the sources currently
# under consideration.
our %linkers_used;

# True if we need 'LINK' defined.  This is a hack.
our $need_link;

# Does the generated Makefile have to build some compiled object
# (for binary programs, or plain or libtool libraries)?
our $must_handle_compiled_objects;

# Record each file processed by make_paragraphs.
our %transformed_files;

################################################################

## ---------------------------------------------- ##
## Variables not reset by &initialize_per_input.  ##
## ---------------------------------------------- ##

# Cache each file processed by make_paragraphs.
# (This is different from %transformed_files because
# %transformed_files is reset for each file while %am_file_cache
# it global to the run.)
our %am_file_cache;

1;