summaryrefslogtreecommitdiff
path: root/build-aux/Makefile.once.head/30-am.mk
blob: 82c01fbc22629e81ca02df33da5fc027c521480f (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
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

# Used by the per_PROGRAM and per_LTLIBRARY 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
define _am.pass0
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: _am.per_primary ==
# Inputs:
#   - Global variable    : `am.INSTALL_$(primary)`
#   - Global variable    : `am.sys2out_$(primary)`
#   - Global variable    : `$(dirname)dir`
# Erased inputs:
#   - Directory variable : `$(dirname)_$(primary)` [1] [2]
#   - Directory variable : `dist_$(dirname)_$(primary)` [1] [2]
#   - Directory variable : `nodist_$(dirname)_$(primary)` [1] [2]
#   - Directory variable : `noinst_$(primary)` [2]
#   - Directory variable : `check_$(primary)` [2]
# Outputs:
#   - Directory variable : `am.sys_$(primary)`
#   - Directory variable : `am.out_$(primary)`
#   - Directory variable : `am.check_$(primary)`
#   - Target variable    : `am.INSTALL`
#
# [1]: HACK: Each of these is first passed through `$(dir ...)`.
#
# [2]: HACK: For `am.out_*` each of these are turned into
#      $(DESTDIR)-relative paths (ie, as if for `am.sys_*`), then turned
#      back into $(outdir)-relative paths with `$(call
#      am.sys2out_$(primary),...)`.
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) $< $@
$(eval $(foreach p,$(_am.primaries),am.sys2out_$p ?= $$(notdir $$1)$(at.nl)))

# Utility functions
_am.primary2dirs = $(filter $(patsubst %dir,%,$(filter %dir,$(.VARIABLES))),\
                            $(patsubst nodist_%,%,$(patsubst dist_%,%,$(patsubst %_$1,%,$(filter %_$1,$(.VARIABLES))))))

_am.pass1 = $(eval $(foreach p,$(_am.primaries)  ,$(call _am.per_primary,$p)$(at.nl)))
define _am.per_primary
# Initialize input variables
$(foreach d,$(call _am.primary2dirs,$1),\
  $d_$1        ?=$(at.nl)\
  dist_$d_$1   ?=$(at.nl)\
  nodist_$d_$1 ?=$(at.nl))
noinst_$1 ?=
check_$1  ?=

# Directory variable outputs
am.check_$1 := $$(check_$1)
am.sys_$1 :=                       $(foreach d,$(call _am.primary2dirs,$1),$$(addprefix $$($ddir)/,$$(notdir $$($d_$1) $$(dist_$d_$1) $$(nodist_$d_$1))))
am.out_$1 := $$(call am.sys2out_$1,$(foreach d,$(call _am.primary2dirs,$1),$$(addprefix $$($ddir)/,$$(notdir $$($d_$1)                $$(nodist_$d_$1)))) $$(noinst_$1))
#                                                                                                                                                     ^^^              ^
#                                                                                                                                              notdir-'||              |
#                                                                                                                                           addprefix--'|              |
#                                                                                                                                           foreach d---'              |
#                                                                                                                                          am.sys2out------------------'

# Erase appropriate inputs
$(foreach d,$(call _am.primary2dirs,$1),undefine $d_$1$(at.nl)undefine dist_$d_$1$(at.nl)undefine nodist_$d_$1$(at.nl))
undefine noinst_$1
undefine check_$1

# Target variable outputs
$$(addprefix $$(DESTDIR),$$(am.sys_$1)): private am.INSTALL = $$(am.INSTALL_$1)
endef

define _am.pass2.doc
# == Pass 2: _am.per_PROGRAM ==
# 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`.
endef
_am.pass2 = $(eval $(foreach f,$(am.out_PROGRAMS)   ,$(call _am.per_PROGRAM,$f,$(call _am.file2var,$f))$(at.nl)))
_am.var_PROGRAMS    = $1_SOURCES nodist_$1_SOURCES $1_CFLAGS $1_CPPFLAGS $1_LDFLAGS $1_LDADD
# $1 = filename
# $2 = varname
define _am.per_PROGRAM
$(foreach var,_am.depends $(call _am.var_PROGRAMS,$2),$(var) ?=$(at.nl))
_am.depends += $$(call at.path,$$(call _am.file2.o,$1)  $$(call _am.file2lib,$1,LDADD))
am.CPPFLAGS +=                 $$($2_CPPFLAGS)          $$(call _am.file2cpp,$1,LDADD)
am.CFLAGS   +=                 $$($2_CFLAGS)
$$(outdir)/$1: private am.LDFLAGS := $$($2_LDFLAGS)
$$(outdir)/$1: $$(_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)
$(foreach var,_am.depends $(call _am.var_PROGRAMS,$2),undefine $(var)$(at.nl))
endef

define _am.pass3.doc
# == Pass 3: _am.per_LTLIBRARY ==
# 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`.
endef
_am.pass3 = $(eval $(foreach f,$(am.out_LTLIBRARIES),$(call _am.per_LTLIBRARY,$f,$(call _am.file2var,$f))$(at.nl)))
_am.var_LTLIBRARIES = $1_SOURCES nodist_$1_SOURCES $1_CFLAGS $1_CPPFLAGS $1_LDFLAGS $1_LIBADD
# $1 = filename
# $2 = varname
define _am.per_LTLIBRARY
$(foreach var,_am.depends $(call _am.var_LTLIBRARIES,$2),$(var) ?=$(at.nl))
_am.depends += $$(call at.path,$$(call _am.file2.lo,$1) $$(call _am.file2lib,$1,LIBADD))
am.CPPFLAGS +=                 $$($2_CPPFLAGS)          $$(call _am.file2cpp,$1,LIBADD)
am.CFLAGS   +=                 $$($2_CFLAGS)
$$(outdir)/$1: private am.LDFLAGS := $$($2_LDFLAGS)
$$(outdir)/$1: $$(_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)
$(foreach var,_am.depends $(call _am.var_LTLIBRARIES,$2),undefine $(var)$(at.nl))
endef

define _am.pass4.doc
# == Pass 4: Install rules / _am.per_directory ==
# Inputs:
#   - Directory variable : `am.sys_$(primary)`
# Outputs:
#   - Target : `$(DESTDIR)/$($(dirname)dir)/%`
#
# Creates simple `install` rules.  You will need to define your own rules if
# `am.sys2out_$(primary)` changed the notdir part of the filename.
endef

# Utility functions
_am.sys2dirs = $(sort $(patsubst %/,%,$(dir $(foreach p,$(_am.primaries),$(am.sys_$p)))))

_am.pass3 = $(eval $(foreach d,$(_am.sys2dirs)  ,$(call _am.per_directory,$d)$(at.nl)))
define _am.per_directory
$$(DESTDIR)$1/%: $$(outdir)/%
	@$$(NORMAL_INSTALL)
	$$(am.INSTALL)
$$(DESTDIR)$1/%: $$(srcdir)/%
	@$$(NORMAL_INSTALL)
	$$(am.INSTALL)
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.check_$(primary)`
# Outputs:
#   - Directory variable : `at.subdirs`
#   - Directory variable : `files.sys.all`
#   - Directory variable : `files.out.all`
#   - Directory variable : `files.out.check`
endef
define _am.pass5
at.subdirs += $(am.subdirs)
files.sys.all += $(foreach p,$(_am.primaries),$(am.sys_$p))
files.out.all += $(foreach p,$(_am.primaries),$(am.out_$p))
files.out.check += $(foreach p,$(_am.primaries),$(am.check_$p))
endef