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
|
mod.am.description = (systemd) Automake-to-Autothing magic
mod.am.depends += gnuconf
define mod.am.doc
# Because many of the inputs/outpus are repetative, they are defined
# here in terms of $$(primary), which may be any of the supported
# Automake primaries (see below for a table).
#
# | Automake 1.15 primaries |
# +-------------------------+
# | name | supported |
# +-------------+-----------+
# | PROGRAMS | yes |
# | LIBRARIES | no |
# | LTLIBRARIES | yes |
# | LISP | no |
# | PYTHON | no |
# | JAVA | no |
# | SCRIPTS | yes |
# | DATA | yes |
# | HEADERS | yes |
# | MANS | yes |
# | TEXINFOS | no |
#
# Further, there is also $$(dirname), which could be anything; and is
# detected at runtime by inspecting $$(.VARIABLES) to find every possible
# matching value. See `_am.primary2dirs` for how this is done.
#
# Some inputs are "erased" after the pass they are used in. This means
# that they are `undefine`ed.
#
$(value _am.pass0.doc)
#
$(value _am.pass1.doc)
#
$(value _am.pass2.doc)
#
$(value _am.pass3.doc)
#
$(value _am.pass4.doc)
#
$(value _am.pass5.doc)
endef
_am.primaries =
_am.primaries += PROGRAMS
#_am.primaries += LIBRARIES
_am.primaries += LTLIBRARIES
#_am.primaries += LISP
#_am.primaries += PYTHON
#_am.primaries += JAVA
_am.primaries += SCRIPTS
_am.primaries += DATA
_am.primaries += HEADERS
_am.primaries += MANS
#_am.primaries += TEXINFOS
am.distmode_PROGRAMS = nodist
am.distmode_LTLIBRARIES = nodist
am.distmode_SCRIPTS = dist
am.distmode_DATA = nodist
am.distmode_HEADERS = dist
am.distmode_MANS = nodist
# Used by the PROGRAMS and LTLIBRARIES passes
_am.file2var = $(subst -,_,$(subst .,_,$1))
_am.file2sources = $(addprefix $(srcdir)/,$(notdir $($(_am.file2var)_SOURCES)))
_am.file2sources += $(addprefix $(outdir)/,$(notdir $(nodist_$(_am.file2var)_SOURCES)))
_am.file2.o = $(patsubst $(srcdir)/%,$(outdir)/%,$(patsubst %.c,%.o ,$(filter %.c,$(_am.file2sources))))
_am.file2.lo = $(patsubst %.o,%.lo,$(_am.file2.o))
_am.file2lib = $(foreach l, $($(_am.file2var)_$2),$(if $(filter lib%.la,$l), $($(l:.la=).DEPENDS) , $l ))
_am.file2cpp = $(foreach l,$1 $($(_am.file2var)_$2),$(if $(filter lib%.la,$l), $($(l:.la=).CPPFLAGS) , ))
define _am.pass0.doc
# == Pass 0: man_MANS ==
# Erased inputs:
# - Directory variable: `man_MANS`
# Outputs:
# - Directory variable: `man$n_MANS` for $n in `{0..9} n l`
#
# Split man_MANS into man$n_MANS
endef
_am.pass0 = $(value _am.pass0_)
define _am.pass0_
# == Pass 0: man_MANS ==
man_MANS ?=
_am.man_MANS := $(man_MANS)
undefine man_MANS
man0_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .0,$(suffix $(_am.tmp))),$(_am.tmp)))
man1_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .1,$(suffix $(_am.tmp))),$(_am.tmp)))
man2_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .2,$(suffix $(_am.tmp))),$(_am.tmp)))
man3_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .3,$(suffix $(_am.tmp))),$(_am.tmp)))
man4_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .4,$(suffix $(_am.tmp))),$(_am.tmp)))
man5_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .5,$(suffix $(_am.tmp))),$(_am.tmp)))
man6_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .6,$(suffix $(_am.tmp))),$(_am.tmp)))
man7_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .7,$(suffix $(_am.tmp))),$(_am.tmp)))
man8_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .8,$(suffix $(_am.tmp))),$(_am.tmp)))
man9_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .9,$(suffix $(_am.tmp))),$(_am.tmp)))
manl_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .l,$(suffix $(_am.tmp))),$(_am.tmp)))
mann_MANS += $(foreach _am.tmp,$(_am.man_MANS),$(if $(findstring .n,$(suffix $(_am.tmp))),$(_am.tmp)))
endef
define _am.pass1.doc
# == Pass 1: initialize variables ==
# Inputs: (used to detect a list of $(dirname)s)
# - Directory variable : `$(dirname)_$(primary)`
# - Directory variable : `nodist_$(dirname)_$(primary)`
# - Directory variable : `dist_$(dirname)_$(primary)`
# Outputs:
# - Directory variable : `noinst_$(primary) ?=`
# - Directory variable : `check_$(primary) ?=`
# - Directory variable : ` $(dirname)_$(primary) ?=`
# - Directory variable : ` dist_$(dirname)_$(primary) ?=`
# - Directory variable : `nodist_$(dirname)_$(primary) ?=`
# - Global variable : `am.outpat_$(dirname)_$(primary) ?= %`
# - Global variable : `am.syspat_$(dirname)_$(primary) ?= %`
#
# Make sure that several variabes are initialized
endef
# Utility (reused in pass 2)
_am.primary2dirs = $(sort $(filter $(patsubst %dir,%,$(filter %dir,$(.VARIABLES))),\
$(patsubst nodist_%,%,$(patsubst dist_%,%,$(patsubst %_$1,%,$(filter %_$1,$(.VARIABLES)))))))
define _am.pass1
# == Pass 1: initialize variables ==
$(foreach _am.primary,$(_am.primaries),
$(foreach _am.dirname,$(call _am.primary2dirs,$(_am.primary)),
am.outpat_$(_am.dirname)_$(_am.primary) ?= %
am.syspat_$(_am.dirname)_$(_am.primary) ?= %
)
)
endef
define _am.pass2.doc
# == Pass 2: Uniform Naming Scheme ==
# Inputs:
# - Global variable : `NORMAL_INSTALL`
# - Global variable : `MKDIR_P`
# - Global variable : `am.INSTALL_$(primary)`
# - Global variable : `am.outpat_$(dirname)_$(primary)`
# - Global variable : `am.syspat_$(dirname)_$(primary)`
# - Global variable : `am.distmode_$(primary)`
# - Global variable : `$(dirname)dir`
# Erased inputs:
# - Directory variable : `noinst_$(primary)`
# - Directory variable : `check_$(primary)`
#
# - Directory variable : `$(dirname)_$(primary)`
# - Directory variable : `dist_$(dirname)_$(primary)`
# - Directory variable : `nodist_$(dirname)_$(primary)`
# Outputs:
# - Directory variable : `am.chk_$(primary)`
# - Directory variable : `am.out_$(primary)`
# - Directory variable : `am.sys_$(primary)`
# - Targets : `$(addprefix $(DESTDIR)$(dirname)/,$(notdir $({,dist_,nodist_}$(dirname)_$(primary))))`
#
# TODO
endef
# Default values
am.INSTALL_PROGRAMS ?= $(INSTALL_PROGRAM) $< $@
am.INSTALL_SCRIPTS ?= $(INSTALL) $< $@
am.INSTALL_LTLIBRARIES ?= $(INSTALL) $< $@
am.INSTALL_DATA ?= $(INSTALL_DATA) $< $@
am.INSTALL_HEADERS ?= $(INSTALL_DATA) $< $@
am.INSTALL_MANS ?= $(INSTALL_DATA) $< $@
# Utility
_am.var_out = $(_am.dirname)_$(_am.primary)
_am.var_out += nodist_$(_am.dirname)_$(_am.primary)
#_am.var_out += noinst_$(_am.primary)
#_am.var_out += check_$(_am.primary)
_am.var_sys = $(_am.dirname)_$(_am.primary)
_am.var_sys += nodist_$(_am.dirname)_$(_am.primary)
_am.var_sys += dist_$(_am.dirname)_$(_am.primary)
define _am.pass2
# == Pass 2: Uniform Naming Scheme ==
$(foreach _am.primary,$(_am.primaries),
## primary: $(_am.primary)
noinst_$(_am.primary) ?=
check_$(_am.primary) ?=
am.chk_$(_am.primary) := $$(check_$(_am.primary))
am.out_$(_am.primary) := $$(noinst_$(_am.primary))
am.sys_$(_am.primary) :=
$(foreach _am.dirname,$(call _am.primary2dirs,$(_am.primary)),
## dirname: $(_am.dirname) ($(_am.primary))
$(_am.dirname)_$(_am.primary) ?=
dist_$(_am.dirname)_$(_am.primary) ?=
nodist_$(_am.dirname)_$(_am.primary) ?=
$(am.distmode_$(_am.primary))_$(_am.dirname)_$(_am.primary) += $$($(_am.dirname)_$(_am.primary))
# nodist
$$(addprefix $$(DESTDIR)$$($(_am.dirname)dir)/,$$(notdir $$(nodist_$(_am.dirname)_$(_am.primary)) )): \
$$(DESTDIR)$$($(_am.dirname)dir)/$(am.syspat_$(_am.dirname)_$(_am.primary)): $(call at.addprefix,$(outdir),$(am.outpat_$(_am.dirname)_$(_am.primary)))
@$$(NORMAL_INSTALL)
@$$(MKDIR_P) $$(@D)
$$(am.INSTALL_$(_am.primary))
# dist
$$(addprefix $$(DESTDIR)$$($(_am.dirname)dir)/,$$(notdir $$(dist_$(_am.dirname)_$(_am.primary)) )): \
$$(DESTDIR)$$($(_am.dirname)dir)/$(am.syspat_$(_am.dirname)_$(_am.primary)): $(call at.addprefix,$(srcdir),$(am.outpat_$(_am.dirname)_$(_am.primary)))
@$$(NORMAL_INSTALL)
@$$(MKDIR_P) $$(@D)
$$(am.INSTALL_$(_am.primary))
am.out_$(_am.primary) := $$(am.out_$(_am.primary)) $$(patsubst $(am.syspat_$(_am.dirname)_$(_am.primary)),$(am.outpat_$(_am.dirname)_$(_am.primary)),$$(notdir $$(nodist_$(_am.dirname)_$(_am.primary)) ))
am.sys_$(_am.primary) := $$(am.sys_$(_am.primary)) $$(addprefix $$($(_am.dirname)dir)/,$$(notdir $$(nodist_$(_am.dirname)_$(_am.primary)) $$(dist_$(_am.dirname)_$(_am.primary)) ))
## (end dirname)
)
## (end primary)
)
endef
define _am.pass3.doc
# == Pass 3: PROGRAMS ==
# Inputs:
# - Directory variable : `am.out_PROGRAMS`
# Erased inputs:
# - Directory variable : `$(program)_SOURCES`
# - Directory variable : `nodist_$(program)_SOURCES`
# - Directory variable : `$(program)_CFLAGS`
# - Directory variable : `$(program)_CPPFLAGS`
# - Directory variable : `$(program)_LDFLAGS`
# - Directory variable : `$(program)_LDADD`
# Outputs:
# - Directory variable : `am.CPPFLAGS`
# - Directory variable : `am.CFLAGS`
# - Target dependencies: `$(outdir)/$(program)`
# - Target variable : `$(outdir)/$(program): am.LDFLAGS`
# - Directory variable : `am.subdirs`
#
# TODO: I'm not in love with how it figures out `am.subdirs`.
# TODO: I'm not in love with how it does the `install` dependencies.
endef
# Utility
_am.var_PROGRAMS = $(_am.var)_SOURCES
_am.var_PROGRAMS += nodist_$(_am.var)_SOURCES
_am.var_PROGRAMS += $(_am.var)_CFLAGS
_am.var_PROGRAMS += $(_am.var)_CPPFLAGS
_am.var_PROGRAMS += $(_am.var)_LDFLAGS
_am.var_PROGRAMS += $(_am.var)_LDADD
define _am.pass3
# == Pass 3: PROGRAMS ==
$(foreach _am.file,$(am.out_PROGRAMS),
$(eval _am.var = $(call _am.file2var,$(_am.file)))
## PROGRAM: $(_am.file) ($(_am.var))
$(foreach var,_am.depends $(_am.var_PROGRAMS),
$(var) ?=
)
_am.depends += $$(call at.path,$$(call _am.file2.o,$(_am.file)) $$(call _am.file2lib,$(_am.file),LDADD))
am.CPPFLAGS += $$($(_am.var)_CPPFLAGS) $$(call _am.file2cpp,$(_am.file),LDADD)
am.CFLAGS += $$($(_am.var)_CFLAGS)
$$(outdir)/$(_am.file): private am.LDFLAGS := $$($(_am.var)_LDFLAGS)
$$(outdir)/$(_am.file): $$(_am.depends)
$$(outdir)/install: $$(addsuffix install,$$(dir $$(filter %.la,$$(_am.depends))))
am.subdirs := $$(sort $$(am.subdirs)\
$$(filter-out $$(abspath $$(srcdir)),\
$$(abspath $$(dir $$(filter-out -l% /%,$$(_am.depends))))))
am.CPPFLAGS := $$(am.CPPFLAGS)
am.CFLAGS := $$(am.CFLAGS)
undefine _am.depends
)
endef
define _am.pass4.doc
# == Pass 4: LTLIBRARIES ==
# Inputs:
# - Directory variable : `am.out_LTLIBRARIES`
# Erased inputs:
# - Directory variable : `$(library)_SOURCES`
# - Directory variable : `nodist_$(library)_SOURCES`
# - Directory variable : `$(library)_CFLAGS`
# - Directory variable : `$(library)_CPPFLAGS`
# - Directory variable : `$(library)_LDFLAGS`
# - Directory variable : `$(library)_LIBADD`
# Outputs:
# - Directory variable : `am.CPPFLAGS`
# - Directory variable : `am.CFLAGS`
# - Target dependencies: `$(outdir)/$(library)`
# - Target variable : `$(outdir)/$(library): am.LDFLAGS`
# - Directory variable : `am.subdirs`
#
# TODO: I'm not in love with how it figures out `am.subdirs`.
# TODO: I'm not in love with how it does the `install` dependencies.
endef
# Utility
_am.var_LTLIBRARIES = $(_am.var)_SOURCES
_am.var_LTLIBRARIES += nodist_$(_am.var)_SOURCES
_am.var_LTLIBRARIES += $(_am.var)_CFLAGS
_am.var_LTLIBRARIES += $(_am.var)_CPPFLAGS
_am.var_LTLIBRARIES += $(_am.var)_LDFLAGS
_am.var_LTLIBRARIES += $(_am.var)_LIBADD
define _am.pass4
# == Pass 4: LTLIBRARIES ==
$(foreach _am.file,$(am.out_LTLIBRARIES),
$(eval _am.var = $(call _am.file2var,$(_am.file)))
## LTLIBRARY: $(_am.file) ($(_am.var))
$(foreach var,_am.depends $(_am.var_LTLIBRARIES),
$(var) ?=
)
_am.depends += $$(call at.path,$$(call _am.file2.lo,$(_am.file)) $$(call _am.file2lib,$(_am.file),LIBADD))
am.CPPFLAGS += $$($(_am.var)_CPPFLAGS) $$(call _am.file2cpp,$(_am.file),LIBADD)
am.CFLAGS += $$($(_am.var)_CFLAGS)
$$(outdir)/$(_am.file): private am.LDFLAGS := $$($(_am.var)_LDFLAGS)
$$(outdir)/$(_am.file): $$(_am.depends)
$$(outdir)/install: $$(addsuffix install,$$(dir $$(filter %.la,$$(_am.depends))))
am.subdirs := $$(sort $$(am.subdirs)\
$$(filter-out $$(abspath $$(srcdir)),\
$$(abspath $$(dir $$(filter-out -l% /%,$$(_am.depends))))))
am.CPPFLAGS := $$(am.CPPFLAGS)
am.CFLAGS := $$(am.CFLAGS)
undefine _am.depends
)
endef
mod.am.depends += files
define _am.pass5.doc
# == Pass 5: export ==
# Inputs:
# - Directory variable : `am.subdirs`
# - Directory variable : `am.sys_$(primary)`
# - Directory variable : `am.out_$(primary)`
# - Directory variable : `am.chk_$(primary)`
# Outputs:
# - Directory variable : `at.subdirs`
# - Directory variable : `files.sys.all`
# - Directory variable : `files.out.all`
# - Directory variable : `files.out.check`
endef
_am.pass5 = $(value _am.pass5_)
define _am.pass5_
# == Pass 4: export ==
at.subdirs += $(am.subdirs)
files.out.check += $(foreach p,$(_am.primaries),$(am.chk_$p))
files.out.all += $(foreach p,$(_am.primaries),$(am.out_$p))
files.sys.all += $(foreach p,$(_am.primaries),$(am.sys_$p))
endef
|