xref: /haiku/build/jam/HelperRules (revision b6b0567fbd186f8ce8a0c90bdc7a7b5b4c649678)
1# Rules without side effects.
2
3# Vanilla Jam compatibility
4if ! $(INVOCATION_SUBDIR_SET) {
5	rule FIsPrefix
6	{
7		# FIsPrefix <a> : <b> ;
8		# Returns true, if list <a> is a prefix (a proper one or equal) of
9		# list <b>, an empty list otherwise.
10		local a = $(1) ;
11		local b = $(2) ;
12		while $(a) && $(a[1]) = $(b[1]) {
13			a = $(a[2-]) ;
14			b = $(b[2-]) ;
15		}
16
17		if $(a) {
18			return ;
19		} else {
20			return true ;
21		}
22	}
23
24	rule LocalClean { Clean $(1) : $(2) ; }
25
26	rule LocalDepends { Depends $(1) : $(2) ; }
27
28} # vanilla Jam compatibility
29
30rule FFilter
31{
32	# FFilter <list> : <excludes> ;
33	# Removes all occurrences of <excludes> in <list>.
34
35	local list = $(1) ;
36	local excludes = $(2) ;
37	local newList ;
38	local item ;
39	for item in $(list) {
40		local skip ;
41		local exclude ;
42		for exclude in $(excludes) {
43			if $(item) = $(exclude) {
44				skip = true ;
45			}
46		}
47		if ! $(skip) {
48			newList += $(item) ;
49		}
50	}
51	return $(newList) ;
52}
53
54rule FGetGrist
55{
56	# FGetGrist <target> ;
57	#
58	# Returns the grist of a target, not including leading "<" and trailing ">".
59
60	local grist = $(1[1]:G) ;
61	if ! $(grist) {
62		return ;
63	}
64
65	return [ Match <(.*)> : $(grist) ] ;
66}
67
68rule FSplitString string : delimiterChar
69{
70	local result ;
71
72	while $(string) {
73		local split = [ Match $(delimiterChar)*([^$(delimiterChar)]+)(.*)
74			: $(string) ] ;
75		result += $(split[1]) ;
76		string = $(split[2-]) ;
77	}
78
79	return $(result) ;
80}
81
82rule FSplitPath
83{
84	# SplitPath <path> ;
85	# Decomposes a path into its components.
86	local path = $(1:G=) ;
87	local components ;
88	# $(path:D) for "/" is "/". Therefore the second condition.
89	while $(path:D) && $(path:D) != $(path)
90	{
91		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
92		components = $(path:D=) $(components) ;
93		path = $(path:D) ;
94	}
95	components = $(path) $(components) ;
96	return $(components) ;
97}
98
99rule FTimeZoneBinaries
100{
101	local sources = $(1:G=timezone-source) ;
102	local locate = $(2) ;
103	local setRelativeTimezoneDir = $(3) ;
104
105	local gristedBinaries ;
106
107	local source ;
108	for source in $(sources) {
109		local binaries = [ on $(source) return $(TZ_OBJECTS) ] ;
110
111		local targetDir = [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR)
112			data etc timezones ] ;
113
114		local binary ;
115		for binary in $(binaries) {
116			local dir = $(binary:D) ;
117			if $(dir) {
118				binary = $(binary:BSG=timezone!$(dir)) ;
119				if $(locate) {
120					LOCATE on $(binary) = [ FDirName $(targetDir) $(dir) ] ;
121				}
122			} else {
123				binary = $(binary:BSG=timezone) ;
124				if $(locate) {
125					LOCATE on $(binary) = $(targetDir) ;
126				}
127			}
128
129			if $(setRelativeTimezoneDir) {
130				RELATIVE_TIMEZONE_DIR on $(binary) = $(dir) ;
131			}
132
133			gristedBinaries += $(binary) ;
134		}
135	}
136
137	return $(gristedBinaries) ;
138}
139
140
141rule SetPlatformCompatibilityFlagVariables
142{
143	# SetPlatformCompatibilityFlagVariables <platform var> : <var prefix>
144	#	: <platform kind> [ : other platforms ] ;
145
146	local platformVar = $(1) ;
147	local platform = $($(platformVar)) ;
148	local varPrefix = $(2) ;
149	local platformKind = $(3) ;
150	local otherPlatforms = $(4) ;
151
152	if ! $(platform) {
153		ECHO "Variable $(platformVar) not set. Please run ./configure or" ;
154		EXIT "specify it manually." ;
155	}
156
157	# special case: Haiku libbe.so built for testing under BeOS
158	if $(platform) = libbe_test {
159		platform = $(HOST_PLATFORM) ;
160	}
161
162	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = ;
163	$(varPrefix)_PLATFORM_BONE_COMPATIBLE = ;
164	$(varPrefix)_PLATFORM_DANO_COMPATIBLE = ;
165	$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ;
166
167	switch $(platform)
168	{
169		case r5 :
170		{
171			$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = true ;
172		}
173
174		case bone :
175		{
176			$(varPrefix)_PLATFORM_BONE_COMPATIBLE = true ;
177		}
178
179		case dano :
180		{
181			$(varPrefix)_PLATFORM_DANO_COMPATIBLE = true ;
182		}
183
184		case haiku_host :
185		{
186			$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
187		}
188
189		case haiku :
190		{
191			$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
192		}
193
194		case * :
195		{
196			if ! ( $(platform) in $(otherPlatforms) ) {
197				Exit Unsupported $(platformKind) platform: $(platform) ;
198			}
199		}
200	}
201
202	# set lesser flags, e.g. "DANO" for "HAIKU" and "BEOS" for "BONE"
203	$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE
204		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
205	$(varPrefix)_PLATFORM_DANO_COMPATIBLE
206		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
207	$(varPrefix)_PLATFORM_BONE_COMPATIBLE
208		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
209	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE
210		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
211
212	# set the machine friendly flags
213	$(varPrefix)_PLATFORM_(haiku)_COMPATIBLE
214		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
215	$(varPrefix)_PLATFORM_(haiku_host)_COMPATIBLE
216		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
217	$(varPrefix)_PLATFORM_(dano)_COMPATIBLE
218		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
219	$(varPrefix)_PLATFORM_(bone)_COMPATIBLE
220		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
221	$(varPrefix)_PLATFORM_(r5)_COMPATIBLE
222		?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
223
224	$(varPrefix)_PLATFORM_(libbe_test)_COMPATIBLE
225		?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
226}
227
228rule FAnalyzeGCCVersion
229{
230	# FAnalyzeGCCVersion <rawVersionVariable> ;
231	#
232	local varName = $(1) ;
233	local rawVersion = $($(varName)) ;
234
235	if ! $(rawVersion) {
236		ECHO "Variable $(varName) not set. Please run ./configure or" ;
237		EXIT "specify it manually." ;
238	}
239
240	local version = ;
241	# split the raw version string at `.' and `-' characters
242	while $(rawVersion) {
243		local split = [ Match "([^.-]*)[.-](.*)" : $(rawVersion) ] ;
244		if $(split) {
245			version += $(split[1]) ;
246			rawVersion = $(split[2]) ;
247		} else {
248			version += $(rawVersion) ;
249			rawVersion = ;
250		}
251	}
252
253	return $(version) ;
254}
255
256rule SetIncludePropertiesVariables
257{
258	# SetIncludePropertiesVariables <varPrefix> ;
259	#
260	local prefix = $(1) ;
261	if $($(prefix)_GCC_VERSION[1]) < 4 {
262		$(prefix)_INCLUDES_SEPARATOR = -I- ;
263		$(prefix)_LOCAL_INCLUDES_OPTION = -I ;
264		$(prefix)_SYSTEM_INCLUDES_OPTION = -I ;
265	} else {
266		$(prefix)_INCLUDES_SEPARATOR = ;
267		$(prefix)_LOCAL_INCLUDES_OPTION = "-iquote " ;
268		$(prefix)_SYSTEM_INCLUDES_OPTION = "-I " ;
269	}
270}
271
272
273#pragma mark -
274
275rule SetPlatformForTarget
276{
277	# SetPlatformForTarget <target> : <platform> ;
278
279	PLATFORM on $(1) = $(2) ;
280}
281
282rule SetSubDirPlatform
283{
284	# SetSubDirPlatform <platform> ;
285
286	PLATFORM = $(1) ;
287}
288
289rule SetSupportedPlatformsForTarget
290{
291	# SetSupportedPlatformsForTarget <target> : <platforms> ;
292
293	SUPPORTED_PLATFORMS on $(1) = $(2) ;
294}
295
296rule SetSubDirSupportedPlatforms
297{
298	# SetSubDirSupportedPlatforms <platforms> ;
299
300	SUPPORTED_PLATFORMS = $(1) ;
301}
302
303rule AddSubDirSupportedPlatforms
304{
305	# AddSubDirSupportedPlatforms <platforms> ;
306
307	SUPPORTED_PLATFORMS += $(1) ;
308}
309
310rule SetSubDirSupportedPlatformsBeOSCompatible
311{
312	# SetSubDirSupportedPlatformsBeOSCompatible ;
313
314	SUPPORTED_PLATFORMS = $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ;
315}
316
317rule IsPlatformSupportedForTarget
318{
319	# IsPlatformSupportedForTarget <target> [ : <platform> ]
320	#
321
322	on $(1) {
323		if $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
324			return true ;
325		} else {
326			return ;
327		}
328	}
329}
330
331rule InheritPlatform
332{
333	# InheritPlatform <children> : <parent> ;
334	# PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value
335	# on <parent>.
336	#
337	local children = $(1) ;
338	local parent = $(2) ;
339
340	on $(parent) {
341		PLATFORM on $(children) = $(PLATFORM) ;
342		SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ;
343	}
344}
345
346rule SubDirAsFlags
347{
348        SUBDIRASFLAGS += $(<) ;
349}
350
351