summaryrefslogtreecommitdiffstats
path: root/make/include/contrib.defs
blob: c3f815a772e59efe809f337790146b7796445ddf (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
CONTRIB.build/    = $(BUILD/)contrib/
CONTRIB.download/ = $(SRC/)download/
CONTRIB.host      = $(if $(filter 1,$(BUILD.cross)),$(BUILD.spec))

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

##
## $(1) = module name (uppercase)
##
define import.CONTRIB.defs
    ##
    ## import gcc/g++ support mainly so we can force contrib choice of
    ## gcc executable, and debug/optimization flags.
    ##
    $$(eval $$(call import.GCC,$(1)))

    ##
    ## common values useful across targets
    ##
    $(1).src/   = $$(SRC/)contrib/$($(1).name)/
    $(1).build/ = $$(CONTRIB.build/)$($(1).name)/
    ## add prerequisites and autotool modules for all contribs
    $(1).deps   = $$(foreach n,$($(1).prerequisites) $(if $(filter $1,$(AUTOTOOL_MODULES)),,$(AUTOTOOL_MODULES)),$$($$n.INSTALL.target))

    ##
    ## target: fetch
    ##
    $(1).FETCH.tar    = $$(CONTRIB.download/)$$(notdir $$($(1).FETCH.url))
    $(1).FETCH.url    = FETCH_IS_UNDEFINED
    $(1).FETCH.target = $$($(1).FETCH.tar)
    define $(1).FETCH
        $$(call FETCH,$$@,$$($(1).FETCH.url))
    endef

    ##
    ## target: extract
    ##
    $(1).EXTRACT.tarbase = $$(strip $$(foreach x,tar.bz2 tar.gz,$$(patsubst %.$$(x),%,$$(filter %.$$(x),$$(notdir $$($(1).FETCH.url))))))
    $(1).EXTRACT.dir/    = $$($(1).build/)$$($(1).EXTRACT.tarbase)/
    $(1).EXTRACT.target  = $$($(1).build/).stamp.extract
    define $(1).EXTRACT
        $$(RM.exe) -fr $$($(1).EXTRACT.dir/)
        $$(TAR.exe) xfC $$($(1).FETCH.tar) $$($(1).build/)
        $$(TOUCH.exe) $$@
    endef

    ##
    ## target: patch
    ##
    $(1).PATCH.srcs = $$(sort $$(wildcard \
        $$($(1).src/)A??-*.patch \
        $$($(1).src/)P??-$$(BUILD.system)*.patch ))

    # extra line feed is required
    define $(1).PATCH.item
        $$(PATCH.exe) -t -N -p1 -d $$(1) < $$(2)

    endef

    $(1).PATCH.target = $$($(1).build/).stamp.patch
    define $(1).PATCH
        $$(foreach p,$$($(1).PATCH.srcs),$$(call $(1).PATCH.item,$$($(1).EXTRACT.dir/),$$(p)))
        $$(TOUCH.exe) $$@
    endef

    ##
    ## target: configure
    ##
    $(1).CONFIGURE.sete       = set -e;
    $(1).CONFIGURE.dir        = $$($(1).EXTRACT.dir/)
    $(1).CONFIGURE.bootstrap  =
    $(1).CONFIGURE.exe        = ./configure
    $(1).CONFIGURE.host       = $$(CONTRIB.host)
    $(1).CONFIGURE.prefix     = $$(call fn.ABSOLUTE,$$(CONTRIB.build/))
    $(1).CONFIGURE.deps       = --disable-dependency-tracking
    $(1).CONFIGURE.shared     = --disable-shared
    $(1).CONFIGURE.static     = --enable-static
    $(1).CONFIGURE.extra      =

    $(1).CONFIGURE.args.dir    = cd $$(1);
    $(1).CONFIGURE.args.host   = --host=$$(1)
    $(1).CONFIGURE.args.prefix = --prefix=$$(1)

    $(1).CONFIGURE.args = !sete @dir !bootstrap !env !exe @host @prefix !deps !shared !static !extra

    $(1).CONFIGURE.env.LOCAL_PATH =
    $(1).CONFIGURE.env.CC       = CC=$$($(1).GCC.gcc)
    $(1).CONFIGURE.env.CXX      = CXX=$$($(1).GCC.gxx)
    ##
    ## Only add debug and optimization flags to contribs when 
    ## debug=max or optimizations=none.  Otherwise, use the contribs defaults
    ifeq (max,$$($(1).GCC.g))
        ifeq (none,$$($(1).GCC.O))
            $(1).CONFIGURE.env.CFLAGS   = CFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?c_std ?extra .g .O *D)"
            $(1).CONFIGURE.env.CXXFLAGS = CXXFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?extra .g .O *D)"
        else
            $(1).CONFIGURE.env.CFLAGS   = CFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?c_std ?extra .g *D)"
            $(1).CONFIGURE.env.CXXFLAGS = CXXFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?extra .g *D)"
        endif
    else
        $(1).CONFIGURE.env.CFLAGS   = CFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?c_std ?extra *D)"
        $(1).CONFIGURE.env.CXXFLAGS = CXXFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?extra *D)"
    endif
    $(1).CONFIGURE.env.CPPFLAGS = CPPFLAGS="-I$$(call fn.ABSOLUTE,$(CONTRIB.build/))include $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?extra *D)"
    $(1).CONFIGURE.env.LDFLAGS  = LDFLAGS="-L$$(call fn.ABSOLUTE,$(CONTRIB.build/))lib $$(call fn.ARGS,$(1).GCC,*archs *sysroot *minver ?extra.exe *D)"
    $(1).CONFIGURE.env.PKG_CONFIG_PATH  = PKG_CONFIG_PATH="$$(call fn.ABSOLUTE,$$(CONTRIB.build/))lib/pkgconfig"

    $(1).CONFIGURE.env.args = !CC !CFLAGS !CXX !CXXFLAGS !CPPFLAGS !LDFLAGS !PKG_CONFIG_PATH !LOCAL_PATH
    $(1).CONFIGURE.env = $$(call fn.ARGS,$(1).CONFIGURE.env,$$($(1).CONFIGURE.env.args))

    $(1).CONFIGURE.target = $$($(1).build/).stamp.configure
    define $(1).CONFIGURE
        $$(call fn.ARGS,$(1).CONFIGURE,$$($(1).CONFIGURE.args))
        $$(TOUCH.exe) $$@
    endef

    ##
    ## target: build
    ##
    $(1).BUILD.env      =
    $(1).BUILD.make     = $$(MAKE)
    $(1).BUILD.dir      = $$($(1).EXTRACT.dir/)
    $(1).BUILD.extra    =
    $(1).BUILD.ntargets =

    $(1).BUILD.args = !env !make @dir !extra !ntargets
    $(1).BUILD.args.dir = -C $$(1)

    $(1).BUILD.target = $$($(1).build/).stamp.build
    define $(1).BUILD
        $$(call fn.ARGS,$(1).BUILD,$$($(1).BUILD.args))
        $$(TOUCH.exe) $$@
    endef

    ##
    ## target: install
    ##
    $(1).INSTALL.make     = $$(MAKE)
    $(1).INSTALL.dir      = $$($(1).EXTRACT.dir/)
    $(1).INSTALL.extra    =
    $(1).INSTALL.ntargets =

    $(1).INSTALL.args = !make @dir !extra !ntargets
    $(1).INSTALL.args.dir = -j 1 -C $$(1) install

    $(1).INSTALL.mkdirs = $$(CONTRIB.build/)lib/ $$(CONTRIB.build/)include/
    $(1).INSTALL.target = $$($(1).build/).stamp.install
    define $(1).INSTALL
        $$(call fn.ARGS,$(1).INSTALL,$$($(1).INSTALL.args))
        $$(TOUCH.exe) $$@
    endef

    ##
    ## target: uninstall
    ##
    $(1).UNINSTALL.make     = $$(MAKE)
    $(1).UNINSTALL.dir      = $$($(1).EXTRACT.dir/)
    $(1).UNINSTALL.extra    =
    $(1).UNINSTALL.ntargets = uninstall

    $(1).UNINSTALL.args = !make @dir !extra !ntargets
    $(1).UNINSTALL.args.dir = -C $$(1)

    define $(1).UNINSTALL
        $$(call fn.ARGS,$(1).UNINSTALL,$$($(1).UNINSTALL.args))
        $$(RM.exe) -f $$($(1).INSTALL.target)
    endef

    ##
    ## target: clean
    ##
    $(1).CLEAN.make     = $$(MAKE)
    $(1).CLEAN.dir      = $$($(1).EXTRACT.dir/)
    $(1).CLEAN.extra    =
    $(1).CLEAN.ntargets = clean

    $(1).CLEAN.args = !make @dir !extra !ntargets
    $(1).CLEAN.args.dir = -C $$(1)

    define $(1).CLEAN
        $$(call fn.ARGS,$(1).CLEAN,$$($(1).CLEAN.args))
        $$(RM.exe) -f $$($(1).BUILD.target)
    endef

    ##
    ## other values used to aid prerequisite dirs and cleanup
    ##
    $(1).out += $$($(1).build/)
    $(1).out += $$($(1).FETCH.target)
    $(1).out += $$($(1).EXTRACT.target)
    $(1).out += $$($(1).PATCH.target)
    $(1).out += $$($(1).CONFIGURE.target)
    $(1).out += $$($(1).BUILD.target)
    $(1).out += $$($(1).INSTALL.mkdirs)
    $(1).out += $$($(1).INSTALL.target)

    BUILD.out += $$($(1).out)
endef

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

##
## $(1) = module name
##
define import.CONTRIB.rules

##
## target: fetch
##
$($(1).name).fetch: $$($(1).FETCH.target)

$$($(1).FETCH.target): | $$(dir $$($(1).FETCH.target))
	$$($(1).FETCH)

##
## target: extract
## must touch dir after extraction because old timestamp is restored via tar.
##
$($(1).name).extract: $$($(1).EXTRACT.target)

$$($(1).EXTRACT.target): | $$(dir $$($(1).EXTRACT.target))
$$($(1).EXTRACT.target): $$($(1).FETCH.target)
	$$($(1).EXTRACT)

$($(1).name).extract.touch:
	$$(TOUCH.exe) $$($(1).EXTRACT.target)

$($(1).name).extract.untouch:
	$$(RM.exe) -f $$($(1).EXTRACT.target)

##
## target: patch
##
$($(1).name).patch: $$($(1).PATCH.target)

$$($(1).PATCH.target): | $$(dir $$($(1).PATCH.target))
$$($(1).PATCH.target): $$($(1).EXTRACT.target)
	$$($(1).PATCH)

$($(1).name).patch.touch:
	$$(TOUCH.exe) $$($(1).PATCH.target)

$($(1).name).patch.untouch:
	$$(RM.exe) -f $$($(1).PATCH.target)

##
## target: configure
##
$($(1).name).configure: $$($(1).CONFIGURE.target)

$$($(1).CONFIGURE.target): | $$(dir $$($(1).CONFIGURE.target))
$$($(1).CONFIGURE.target): $$($(1).deps)
$$($(1).CONFIGURE.target): $$($(1).PATCH.target)
	$$($(1).CONFIGURE)

$($(1).name).configure.touch:
	$$(TOUCH.exe) $$($(1).CONFIGURE.target)

$($(1).name).configure.untouch:
	$$(RM.exe) -f $$($(1).CONFIGURE.target)

##
## target: build
##
$($(1).name).build: $$($(1).BUILD.target)

$$($(1).BUILD.target): | $$(dir $$($(1).BUILD.target))
$$($(1).BUILD.target): $$($(1).CONFIGURE.target)
	-$$($(1).CLEAN)
	+$$($(1).BUILD)

$($(1).name).build.touch:
	$$(TOUCH.exe) $$($(1).BUILD.target)

$($(1).name).build.untouch:
	$$(RM.exe) -f $$($(1).BUILD.target)

##
## target: install
##
$($(1).name).install: $$($(1).INSTALL.target)

$$($(1).INSTALL.target): | $$(dir $$($(1).INSTALL.target)) $$($(1).INSTALL.mkdirs)
$$($(1).INSTALL.target): $$($(1).BUILD.target)
	$$($(1).INSTALL)

$($(1).name).install.touch:
	$$(TOUCH.exe) $$($(1).INSTALL.target)

$($(1).name).install.untouch:
	$$(RM.exe) -f $$($(1).INSTALL.target)

##
## target: uninstall
##
$($(1).name).uninstall:
	-$$($(1).UNINSTALL)

##
## target: clean
##
$($(1).name).clean:
	-$$($(1).CLEAN)

##
## target: xclean
##
$($(1).name).xclean: $($(1).name).uninstall
	$$(RM.exe) -fr $$($(1).build/)

##
## alias: module name is same as build
##
$($(1).name): $($(1).name).build

##
## participate with global convenience targets
##
contrib.fetch: $($(1).name).fetch
contrib.extract: $($(1).name).extract
contrib.patch: $($(1).name).patch
contrib.configure: $($(1).name).configure
contrib.build: $($(1).name).build
contrib.install: $($(1).name).install
contrib.uninstall: $($(1).name).uninstall
contrib.clean: $($(1).name).clean
contrib.xclean: $($(1).name).xclean

endef