-
-
Notifications
You must be signed in to change notification settings - Fork 337
/
HelperRules
364 lines (306 loc) · 7.82 KB
/
HelperRules
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
# Rules without side effects.
# Vanilla Jam compatibility
if ! $(INVOCATION_SUBDIR_SET) {
rule FIsPrefix
{
# FIsPrefix <a> : <b> ;
# Returns true, if list <a> is a prefix (a proper one or equal) of
# list <b>, an empty list otherwise.
local a = $(1) ;
local b = $(2) ;
while $(a) && $(a[1]) = $(b[1]) {
a = $(a[2-]) ;
b = $(b[2-]) ;
}
if $(a) {
return ;
} else {
return true ;
}
}
rule LocalClean { Clean $(1) : $(2) ; }
rule LocalDepends { Depends $(1) : $(2) ; }
} # vanilla Jam compatibility
rule FFilter
{
# FFilter <list> : <excludes> ;
# Removes all occurrences of <excludes> in <list>.
local list = $(1) ;
local excludes = $(2) ;
local newList ;
local item ;
for item in $(list) {
local skip ;
local exclude ;
for exclude in $(excludes) {
if $(item) = $(exclude) {
skip = true ;
}
}
if ! $(skip) {
newList += $(item) ;
}
}
return $(newList) ;
}
rule FGetGrist
{
# FGetGrist <target> ;
#
# Returns the grist of a target, not including leading "<" and trailing ">".
local grist = $(1[1]:G) ;
if ! $(grist) {
return ;
}
return [ Match <(.*)> : $(grist) ] ;
}
rule FSplitString string : delimiterChar
{
local result ;
while $(string) {
local split = [ Match $(delimiterChar)*([^$(delimiterChar)]+)(.*)
: $(string) ] ;
result += $(split[1]) ;
string = $(split[2-]) ;
}
return $(result) ;
}
rule FSplitPath
{
# SplitPath <path> ;
# Decomposes a path into its components.
local path = $(1:G=) ;
local components ;
# $(path:D) for "/" is "/". Therefore the second condition.
while $(path:D) && $(path:D) != $(path)
{
# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
components = $(path:D=) $(components) ;
path = $(path:D) ;
}
components = $(path) $(components) ;
return $(components) ;
}
rule FSetConditionsHold conditions : set
{
# FSetConditionsHold <conditions> : <set> ;
# Checks whether the conditions <conditions> are satisfied by the list of
# elements <set> and returns a respective result (if so: "1", if not: empty
# list). The conditions are satisfied when <conditions> is not empty and
# * none of the negative conditions it contains hold and
# * if <conditions> contains any positive conditions, at least one one of
# those holds.
# A positive condition is an element not starting with a "!". It holds when
# the element is contained in <set>.
# A negative condition is an element that starts with a "!". It holds when
# the string resulting from removing the leading "!" is not contained in
# <set>.
#
# <conditions> - The list of conditions.
# <set> - The elements against which the conditions are tested.
#
# Examples:
# For set { a b c } the following conditions hold:
# { a }, { a d }, { !d }, { !d !e }, { a !d }, { b !e !f }
# The following conditions don't hold:
# { }, { d }, { d e }, { !a }, { !a b }, { !d e } { a b !c !d }
local hasPositive ;
local hasNegative ;
local positiveMatch ;
local condition ;
for condition in $(conditions) {
switch $(condition) {
case !* :
{
hasNegative = 1 ;
condition = [ Match "!(.*)" : $(condition) ] ;
if $(condition) in $(set) {
return ;
}
}
case * :
{
hasPositive = 1 ;
if $(condition) in $(set) {
positiveMatch = 1 ;
}
}
}
}
if $(hasPositive) {
return $(positiveMatch) ;
}
return $(hasNegative) ;
}
rule SetPlatformCompatibilityFlagVariables
{
# SetPlatformCompatibilityFlagVariables <platform var> : <var prefix>
# : <platform kind> [ : other platforms ] ;
local platformVar = $(1) ;
local platform = $($(platformVar)) ;
local varPrefix = $(2) ;
local platformKind = $(3) ;
local otherPlatforms = $(4) ;
if ! $(platform) {
ECHO "Variable $(platformVar) not set. Please run ./configure or" ;
EXIT "specify it manually." ;
}
# special case: Haiku libbe.so built for testing under BeOS
if $(platform) = libbe_test {
platform = $(HOST_PLATFORM) ;
}
$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = ;
$(varPrefix)_PLATFORM_BONE_COMPATIBLE = ;
$(varPrefix)_PLATFORM_DANO_COMPATIBLE = ;
$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ;
switch $(platform)
{
case r5 :
{
$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = true ;
}
case bone :
{
$(varPrefix)_PLATFORM_BONE_COMPATIBLE = true ;
}
case dano :
{
$(varPrefix)_PLATFORM_DANO_COMPATIBLE = true ;
}
case haiku_host :
{
$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
}
case haiku :
{
$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
}
case * :
{
if ! ( $(platform) in $(otherPlatforms) ) {
Exit Unsupported $(platformKind) platform: $(platform) ;
}
}
}
# set lesser flags, e.g. "DANO" for "HAIKU" and "BEOS" for "BONE"
$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE
?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
$(varPrefix)_PLATFORM_DANO_COMPATIBLE
?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
$(varPrefix)_PLATFORM_BONE_COMPATIBLE
?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
$(varPrefix)_PLATFORM_BEOS_COMPATIBLE
?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
# set the machine friendly flags
$(varPrefix)_PLATFORM_(haiku)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
$(varPrefix)_PLATFORM_(haiku_host)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
$(varPrefix)_PLATFORM_(dano)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
$(varPrefix)_PLATFORM_(bone)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
$(varPrefix)_PLATFORM_(r5)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
$(varPrefix)_PLATFORM_(libbe_test)_COMPATIBLE
?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
}
rule FAnalyzeGCCVersion
{
# FAnalyzeGCCVersion <rawVersionVariable> ;
#
local varName = $(1) ;
local rawVersion = $($(varName)) ;
if ! $(rawVersion) {
ECHO "Variable $(varName) not set. Please run ./configure or" ;
EXIT "specify it manually." ;
}
local version = ;
# split the raw version string at `.' and `-' characters
while $(rawVersion) {
local split = [ Match "([^.-]*)[.-](.*)" : $(rawVersion) ] ;
if $(split) {
version += $(split[1]) ;
rawVersion = $(split[2]) ;
} else {
version += $(rawVersion) ;
rawVersion = ;
}
}
return $(version) ;
}
rule SetIncludePropertiesVariables
{
# SetIncludePropertiesVariables <varPrefix> ;
#
local prefix = $(1) ;
if $($(prefix)_GCC_VERSION[1]) < 4 {
$(prefix)_INCLUDES_SEPARATOR = -I- ;
$(prefix)_LOCAL_INCLUDES_OPTION = -I ;
$(prefix)_SYSTEM_INCLUDES_OPTION = -I ;
} else {
$(prefix)_INCLUDES_SEPARATOR = ;
$(prefix)_LOCAL_INCLUDES_OPTION = "-iquote " ;
$(prefix)_SYSTEM_INCLUDES_OPTION = "-I " ;
}
}
#pragma mark -
rule SetPlatformForTarget
{
# SetPlatformForTarget <target> : <platform> ;
PLATFORM on $(1) = $(2) ;
}
rule SetSubDirPlatform
{
# SetSubDirPlatform <platform> ;
PLATFORM = $(1) ;
}
rule SetSupportedPlatformsForTarget
{
# SetSupportedPlatformsForTarget <target> : <platforms> ;
SUPPORTED_PLATFORMS on $(1) = $(2) ;
}
rule SetSubDirSupportedPlatforms
{
# SetSubDirSupportedPlatforms <platforms> ;
SUPPORTED_PLATFORMS = $(1) ;
}
rule AddSubDirSupportedPlatforms
{
# AddSubDirSupportedPlatforms <platforms> ;
SUPPORTED_PLATFORMS += $(1) ;
}
rule SetSubDirSupportedPlatformsBeOSCompatible
{
# SetSubDirSupportedPlatformsBeOSCompatible ;
SUPPORTED_PLATFORMS = $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ;
}
rule IsPlatformSupportedForTarget
{
# IsPlatformSupportedForTarget <target> [ : <platform> ]
#
on $(1) {
if $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
return true ;
} else {
return ;
}
}
}
rule InheritPlatform
{
# InheritPlatform <children> : <parent> ;
# PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value
# on <parent>.
#
local children = $(1) ;
local parent = $(2) ;
on $(parent) {
PLATFORM on $(children) = $(PLATFORM) ;
SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ;
}
}
rule SubDirAsFlags
{
SUBDIRASFLAGS += $(<) ;
}