summaryrefslogtreecommitdiff
path: root/lib/am/header-vars.mk
blob: 4361f4ef51ff02fc647fc4aa88b3572975a55b2b (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
## automake - create Makefile.in from Makefile.am
## Copyright (C) 1994-2014 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 2, 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/>.

# Makefiles generated by Automake-NG require GNU make >= 3.81.
# The .FEATURES special variable has been introduced in that make
# version, so use it as a witness to determine whether the current
# make is good enough.
ifndef .FEATURES
  $(error Automake-NG based builds require GNU make 3.81 or later)
endif

VPATH = $(srcdir)

# Enhance performance by removing GNU make builtin rules that would be
# rather irrelevant (e.g., rules to automatically check out files from
# from RCS or SCCS repositories), or overridden by Automake (e.g., rules
# to compile C or C++ files).  For larger packages (like GNU coreutils),
# this can greatly speed up null or almost-null builds, up to even 50%!
MAKEFLAGS += --no-builtin-rules

# For when we need a do-nothing target.  Add an actual rule to it to avoid
# the annoying message "make[1]: Nothing to be done for .am/nil" from make.
.PHONY: .am/nil
.am/nil:
	@:

# Declare an error, without immediately terminating the execution (proper
# code will take care of that later).  This will allow us to diagnose more
# issues at once, rather than stopping at the first one.
am.error.seen :=
define am.error
$(warning $1)$(eval am.error.seen := yes)
endef

# Declare an error, and immediately terminate execution.
define am.fatal
$(if $1,$(call am.error,$1))$(error Some Automake-NG error occurred)
endef

#
# Sometimes, in our makefiles, we want to assign a default value to a
# variable that might not have been assigned yet.  One might think that
# using the GNU make assignment '?=' is enough:
#
#    VAR ?= DEFAULT-VALUE
#
# But alas, such a usage allows interferences from the environment; i.e.,
# if an environment variable named 'VAR' is defined to, say, BAD-VALUE,
# the construct above will result in the $(VAR) make variable being
# defined to BAD-VALUE, not to DEFAULT-VALUE.
#
# Use the 'am.vars.is-undef' function to avoid this situation.  It tells
# whether the given make variable is not "safely" defined, i.e., either
# undefined, or defined to a value that is inherited from the environment.
#
# With such a tool, we can safely declare default values for variables
# that avoids environmental interferences, as follow:
#
#     ifeq ($(call am.vars.is-undef,VAR),yes)
#       VAR = DEFAULT-VALUE
#     endif
#
define am.vars.is-undef
$(if $(filter undefined environment,$(origin $(strip $1))),yes)
endef

# Some problematic characters (especially when used in arguments
# to make functions, or for syntax highlighting).
am.chars.bslash := \\
am.chars.comma := ,
am.chars.dollar := $$
am.chars.hash := \#
am.chars.lparen := (
am.chars.rparen := )
am.chars.bquote := `
am.chars.dquote := "
am.chars.squote := '
# "` # Fix font-lock.

# An empty string.  It can be very useful to "fool" the make parser w.r.t.
# whitespace handling, and allow us to obtain tricky semantics.  See the
# definition of $(am.chars.newline) just below for a significant example.
am.chars.empty :=

# A single whitespace.
am.chars.space := $(am.chars.empty) $(am.chars.empty)

# A single tabulation character.
am.chars.tab := $(am.chars.empty)	$(am.chars.empty)

# A literal newline character, that does not get stripped if used
# at the end of the expansion of another macro.
define am.chars.newline

$(am.chars.empty)
endef

# Neutralize unwarranted environment settings that might interfere with
# our Makefiles.
ifeq ($(call am.vars.is-undef,SUBDIRS),yes)
  SUBDIRS :=
endif
ifeq ($(call am.vars.is-undef,EXEEXT),yes)
  EXEEXT :=
endif

# CDPATH is only useful in interactive usage, and should never be exported
# in the environment; doing so could cause our recipes and scripts to chdir
# to unexpected places, causing all sort of hard to reproduce mayhem.
# Still, but some people nonetheless export CDPATH (or did so in the past),
# so to be extra safe we have to neutralize it.
unexport CDPATH

# Be verbose by default.  Yes, we really want $(V) to be overridable
# from the environment, both for simplicity and for consistency with
# mainline Automake.
# FIXME: maybe normalize/sanitize $(V)?
V ?= 0

# In a recipe, ensure the given directory exists, creating it if
# necessary; but tries to do so avoiding useless forks, stats, and
# extra recipe text (the latter is useful when doing "make V=1").
# If the target has no directory component, or if the parent
# directory of the target already exists, we have nothing to do, so
# try to optimize for those cases -- especially because, for our
# usage patterns, one of them should always be true in non-VPATH
# builds.
am.cmd.ensure-dir-exists = \
  $(if $(filter .,$1),:,$(if $(wildcard $1/),:,$(MKDIR_P) $1))

# Ensure the directory containing the target of the current recipe
# exists, by creating it if necessary.
am.cmd.ensure-target-dir-exists = $(call am.cmd.ensure-dir-exists,$(@D))

# The 'all' target must be the default one, independently from the
# position it is declared in the output Makefile.
.DEFAULT_GOAL := all

# Emulate VPATH rewrites.  This uses only GNU make primitives, which
# allows us to avoid extra forks.
am.vpath.rewrite = \
  $(firstword $(wildcard $(strip $(1))) $(srcdir)/$(strip $(1)))

# Leave this overridable from the environment, for better compatibility
# with mainline Automake.
DESTDIR ?=

# Determine whether the current make instance is running with a given
# single-character option (e.g., -k, -n) that takes no argument.
# It is either 'true' or 'false', so that it can be easily used in
# shell code as well as in GNU make conditionals.
# Use $(MFLAGS), not $(MAKEFLAGS), since the former doesn't contain
# the command line variable definitions, and it always begins with
# a hyphen unless it is empty, assumptions that allow a simpler
# implementation.  It is worthwhile to note that, when expanded
# from the top-level make, $(MFLAGS) doesn't contain references to
# options that take an argument, either mandatory (e.g., '-I') or
# optional (e.g., '-O').  This *vastly* simplifies the implementation
# of this macro.
am.make.is-running-with-option = \
  $(if $(findstring $(strip $1),$(filter-out --%,$(MFLAGS))),true,false)

# Tell whether make is running in dry mode ("make -n") or not.
am.make.dry-run := $(call am.make.is-running-with-option, n)

# Tell whether make is running in "keep-going mode" ("make -k") or not.
# Useful in rules that must recursively descend into subdirectories,
# and decide whether to stop at the first error or not.
am.make.keep-going := $(call am.make.is-running-with-option, k)

am.util.strip-first-word = $(wordlist 2,$(words $(1)),$(1))
am.util.strip-last-word  = $(wordlist 2,$(words $(1)),dummy $(1))

# Remove repeated elements from the given list (without reordering),
# and return the reduced list.
am.util.uniq = $(strip \
## If the list is empty, we have nothing to do.  Otherwise, go on.
  $(if $(strip $(1)), \
## Call the function recursively on the list of all the elements
## but the last one.
    $(call $0, \
      $(call am.util.strip-last-word, $(1))) \
## And append the last element, unless it was already present.
      $(if $(filter $(lastword $(1)), \
                    $(call am.util.strip-last-word, $(1))), \
           $(am.chars.empty), \
           $(lastword $(1)))))

## These definitions have been generated by the following Bash 4 script:
##
##    #!/bin/bash
##    toupper='$1' tolower='$1'
##    for c in {a..z}; do
##        C=${c^^}
##        toupper="\$(subst $c,$C,$toupper)"
##        tolower="\$(subst $C,$c,$tolower)"
##    done
##    echo "am.util.tolower = $tolower"
##    echo "am.util.toupper = $toupper"

am.util.tolower = $(subst Z,z,$(subst Y,y,$(subst X,x,$(subst W,w,$(subst V,v,$(subst U,u,$(subst T,t,$(subst S,s,$(subst R,r,$(subst Q,q,$(subst P,p,$(subst O,o,$(subst N,n,$(subst M,m,$(subst L,l,$(subst K,k,$(subst J,j,$(subst I,i,$(subst H,h,$(subst G,g,$(subst F,f,$(subst E,e,$(subst D,d,$(subst C,c,$(subst B,b,$(subst A,a,$1))))))))))))))))))))))))))

am.util.toupper = $(subst z,Z,$(subst y,Y,$(subst x,X,$(subst w,W,$(subst v,V,$(subst u,U,$(subst t,T,$(subst s,S,$(subst r,R,$(subst q,Q,$(subst p,P,$(subst o,O,$(subst n,N,$(subst m,M,$(subst l,L,$(subst k,K,$(subst j,J,$(subst i,I,$(subst h,H,$(subst g,G,$(subst f,F,$(subst e,E,$(subst d,D,$(subst c,C,$(subst b,B,$(subst a,A,$1))))))))))))))))))))))))))

# Canonicalize the given filename.  See also the &canonicalize function
# in the automake script.

am.util.canon = $(strip \
  $(subst ~,_,\
  $(subst },_,\
  $(subst |,_,\
  $(subst {,_,\
  $(subst $(am.chars.bquote),_,\
  $(subst ^,_,\
  $(subst $(am.chars.bslash),_,\
  $(subst [,_,\
  $(subst ],_,\
  $(subst ?,_,\
  $(subst >,_,\
  $(subst =,_,\
  $(subst <,_,\
  $(subst ;,_,\
  $(subst :,_,\
  $(subst /,_,\
  $(subst .,_,\
  $(subst -,_,\
  $(subst $(am.chars.comma),_,\
  $(subst +,_,\
  $(subst *,_,\
  $(subst $(am.chars.lparen),_,\
  $(subst $(am.chars.rparen),_,\
  $(subst $(am.chars.squote),_,\
  $(subst &,_,\
  $(subst %,_,\
  $(subst $(am.chars.dollar),_,\
  $(subst $(am.chars.hash),_,\
  $(subst $(am.chars.dquote),_,\
  $(subst !,_,$1)))))))))))))))))))))))))))))))


# Simple memoization for recursive make variables.  It is useful for
# situations where immediate variables can't be used (due, say, to
# ordering issues with the assignments of the referenced variables),
# but where the value of the lazy variable is costly to calculate
# (e.g., a $(shell ...) call with a non-trivial command line), so that
# we can't afford to re-calculate it over and over every time the
# variable gets expanded.  Example of usage:
#
#   var1 = $(am.memoize,var1,$(shell EXPENSIVE-COMMAND-LINE))
#   var2 = $(am.memoize,var2,$(sort VERY-LONG-LIST))
#
# This API and implementation seems to work around a bug in GNU make
# (present up to and including version 3.82) which caused our first
# implementation attempts to fail:
#
#   <http://lists.gnu.org/archive/html/bug-make/2012-05/msg00013.html>
#   <https://savannah.gnu.org/patch/?7534>
#
# So please don't change this without a very good reason.
#
am.memoize = $(or $(am.memoize.value/$1),$(strip \
  $(eval am.memoize.value/$1 := $$2))$(am.memoize.value/$1))

# $(call am.util.strip-suffixes, SUFFIXES, LIST)
# ----------------------------------------------
# Strip any of the SUFFIXES from each of the entries of LIST.  Even if an
# entry of LIST terminates with several suffixes, only one is stripped:
# the first one that matches.
am.hack.private-suffix = .,;&!@
am.util.strip-suffixes = $(strip \
  $(if \
    $(strip $1), \
      $(patsubst %$(am.hack.private-suffix),%, \
        $(call $0, \
          $(call am.util.strip-first-word,$1), \
          $(patsubst %$(firstword $1),%$(am.hack.private-suffix),$2))), \
    $2))

# Now, some helper functions and variables to help in recipes that could
# exceed the command line length limit.

# And in the Information Age, we somehow managed to revert to abacus-like
# counting.  Yay for us :-)
am.max-cmdline-args := xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# FIXME! The above accounts for max forty arguments; this is basically
# arbitrary.  In the long term, defining that after a configure-time test
# on the command-line length limits, or at least on a system-by-system
# basis, might be better.  But don't make the new limit too big (even if
# the system would allow it), or our implementation will likely suffer in
# performance and in memory consumption.

# $(call am.xargs-map,FUNCTION,LIST,[EXTRA-ARGS..])
# -------------------------------------------------
# Map the function $1 on the whitespace-separated list $2, ensuring that
# each call of $1 has at most 40 entries from that list at once.  If
# further arguments are given (up to $9), they are passed to each $1
# invocation.
# This implementation is hacky, but the more elegant or "naive" ones
# (based on recursion) proved to be ludicrously memory-hungry with
# huge lists.
# A drawback of this implementation is that am.xargs-map cannot be
# recursively invoked, but that shouldn't matter for our use cases.
# The extra $(strip) calls are only to allow clearer formatting.
define am.xargs-map
$(if $2,$(strip \
  )$(eval $0.partial-args :=)$(strip \
  )$(eval $0.counter :=)$(strip \
  )$(foreach i,$2,$(strip \
    )$(eval $0.counter := $$($0.counter)x)$(strip \
    )$(eval $0.partial-args += $$i)$(strip \
    )$(if $(filter $(am.max-cmdline-args),$($0.counter)),$(strip \
      )$(call $1,$(strip $($0.partial-args)),$3,$4,$5,$6,$7,$8,$9)$(strip \
      )$(eval $0.partial-args :=)$(strip \
      )$(eval $0.counter :=)))$(strip \
  )$(if $($0.counter),$(call $1,$(strip \
                        $($0.partial-args)),$3,$4,$5,$6,$7,$8,$9)))
endef

# Used only by the 'am.clean-cmd.*' functions below.  Do not use in
# other places.
am.hack.rm-f = $(if $(strip $1),rm -f $(strip $1)$(am.chars.newline))
am.hack.rm-rf = $(if $(strip $1),rm -rf $(strip $1)$(am.chars.newline))

# Needed to ensure the invocations of "rm -f" and "rm -rf" in our cleaning
# rules are not given too many arguments, which might cause command line
# length limits to be exceeded.  These are only meant to be used in a
# "sub-recipe" by their own; e.g.,
#
#    # This is ok.
#    clean-x:
#        @echo "Cleaning X Files"
#        @$(call am.clean-cmd.f,$(X_FILES))
#
#    # This is *wrong*.
#    clean-x:
#        @echo "Cleaning X Files" \
#          && $(call am.clean-cmd.f,$(X_FILES))
#
am.clean-cmd.f = $(call am.xargs-map,am.hack.rm-f,$1)
am.clean-cmd.d = $(call am.xargs-map,am.hack.rm-rf,$1)

# Some derived variables that have been found to be useful.
# These have since long been documented in the Automake manual and used
# by many real-world packages, so they are now an established feature
# and should not be changed.
pkgdatadir = $(datadir)/$(PACKAGE)
pkgincludedir = $(includedir)/$(PACKAGE)
pkglibdir = $(libdir)/$(PACKAGE)
pkglibexecdir = $(libexecdir)/$(PACKAGE)

install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)

# These are defined like this to avoid introducing gratuitous
# incompatibilities with mainline Automake.
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :

# Number of files to install concurrently.
am__install_max = 40
# Take a "$list" of nobase files, collect them, indexed by their
# srcdir-stripped dirnames.  For up to am__install_max files, output
# a line containing the dirname and the files, space-separated.
# The arbitrary limit helps avoid the quadratic scaling exhibited by
# string concatenation in most shells, and should avoid line length
# limitations, while still offering only negligible performance impact
# through spawning more install commands than absolutely needed.
am__nobase_list = \
  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`; \
  for p in $$list; do echo "$$p $$p"; done | \
  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
    if (++n[$$2] == $(am__install_max)) \
      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
    END { for (dir in files) print dir, files[dir] }'
# Collect up to 40 files per line from stdin.
am__base_list = \
  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'

# New function, backslash-escape whitespace in the given string.
define am.util.whitespace-escape
$(subst $(am.chars.space),\$(am.chars.space),$(subst $(am.chars.tab),\$(am.chars.tab),$1))
endef

# Determine whether the given file exists.  Since this function is
# expected to be used on paths referencing $(DESTDIR), it must be
# ready to cope with whitespaces and shell metacharacters.
# FIXME: here we assume that the shell found by Autoconf-generated
# configure supports "test -e"; that is not completely correct ATM, but
# future versions of Autoconf will reject non-POSIX shells, so we should
# be safe in the long term.
define am.util.file-exists
$(strip \
  $(if $(strip $(findstring *,$1) $(findstring ?,$1) \
               $(findstring [,$1) $(findstring ],$1)), \
    $(shell test -e '$(subst $(am.chars.squote),'\'',$1)' && echo yes), \
    $(if $(wildcard $(call am.util.whitespace-escape,$1)),yes)))
endef

# $(call am.uninst.cmd,DIR,FILES,[RM-OPTS])
# -----------------------------------------
# Uninstall the given files from the given directory, avoiding to hit
# command line length limits, and honoring $(DESTDIR).  If the given DIR
# is actually an empty name, or it it refers to a non-existing file, it
# is assumed nothing is to be removed.  The RM-OPTS (if present) are
# passed to the rm invocation removing the files (this ca be useful in
# case such files are actually directories (as happens with the HTML
# documentation), in which case rm should be passed the '-r' option.
# Similarly to the 'am.clean-cmd.f' above, this function is only meant
# to be used in a "sub-recipe" by its own.

define am.uninst.cmd.aux
$(if $(and $2,$1),$(if $(call am.util.file-exists,$(DESTDIR)$2),$(strip \
)cd '$(DESTDIR)$2' && rm -f$(if $3, $3) $1$(am.chars.newline)))
endef

define am.uninst.cmd
$(call am.xargs-map,$0.aux,$(strip $2),$(strip $1),$(strip $3))
endef