xref: /haiku/build/jam/HelperRules (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 FSplitPath
55{
56	# SplitPath <path> ;
57	# Decomposes a path into its components.
58	local path = $(1:G=) ;
59	local components ;
60	# $(path:D) for "/" is "/". Therefore the second condition.
61	while $(path:D) && $(path:D) != $(path)
62	{
63		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
64		components = $(path:D=) $(components) ;
65		path = $(path:D) ;
66	}
67	components = $(path) $(components) ;
68	return $(components) ;
69}
70
71rule FTimeZoneBinaries
72{
73	local sources = $(1:G=timezone-source) ;
74	local locate = $(2) ;
75	local setRelativeTimezoneDir = $(3) ;
76
77	local gristedBinaries ;
78
79	local source ;
80	for source in $(sources) {
81		local binaries = [ on $(source) return $(TZ_OBJECTS) ] ;
82
83		local targetDir = [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR)
84			data etc timezones ] ;
85
86		local binary ;
87		for binary in $(binaries) {
88			local dir = $(binary:D) ;
89			if $(dir) {
90				binary = $(binary:BSG=timezone!$(dir)) ;
91				if $(locate) {
92					LOCATE on $(binary) = [ FDirName $(targetDir) $(dir) ] ;
93				}
94			} else {
95				binary = $(binary:BSG=timezone) ;
96				if $(locate) {
97					LOCATE on $(binary) = $(targetDir) ;
98				}
99			}
100
101			if $(setRelativeTimezoneDir) {
102				RELATIVE_TIMEZONE_DIR on $(binary) = $(dir) ;
103			}
104
105			gristedBinaries += $(binary) ;
106		}
107	}
108
109	return $(gristedBinaries) ;
110}
111
112
113rule SetPlatformCompatibilityFlagVariables
114{
115	# SetPlatformCompatibilityFlagVariables <platform var> : <var prefix>
116	#	: <platform kind> [ : other platforms ] ;
117
118	local platformVar = $(1) ;
119	local platform = $($(platformVar)) ;
120	local varPrefix = $(2) ;
121	local platformKind = $(3) ;
122	local otherPlatforms = $(4) ;
123
124	if ! $(platform) {
125		ECHO "Variable $(platformVar) not set. Please run ./configure or" ;
126		EXIT "specify it manually." ;
127	}
128
129	# special case: Haiku libbe.so built for testing under BeOS
130	if $(platform) = libbe_test {
131		platform = haiku ;
132	}
133
134	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = ;
135	$(varPrefix)_PLATFORM_BONE_COMPATIBLE = ;
136	$(varPrefix)_PLATFORM_DANO_COMPATIBLE = ;
137	$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ;
138
139	switch $(platform)
140	{
141		case r5 :
142		{
143			$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = true ;
144		}
145
146		case bone :
147		{
148			$(varPrefix)_PLATFORM_BONE_COMPATIBLE = true ;
149		}
150
151		case dano :
152		{
153			$(varPrefix)_PLATFORM_DANO_COMPATIBLE = true ;
154		}
155
156		case haiku :
157		{
158			$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
159		}
160
161		case * :
162		{
163			if ! ( $(platform) in $(otherPlatforms) ) {
164				Exit Unsupported $(platformKind) platform: $(platform) ;
165			}
166		}
167	}
168
169	# set lesser flags, e.g. "DANO" for "HAIKU" and "BEOS" for "BONE"
170	$(varPrefix)_PLATFORM_DANO_COMPATIBLE
171		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
172	$(varPrefix)_PLATFORM_BONE_COMPATIBLE
173		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
174	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE
175		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
176
177	# set the machine friendly flags
178	$(varPrefix)_PLATFORM_(haiku)_COMPATIBLE
179		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
180	$(varPrefix)_PLATFORM_(dano)_COMPATIBLE
181		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
182	$(varPrefix)_PLATFORM_(bone)_COMPATIBLE
183		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
184	$(varPrefix)_PLATFORM_(r5)_COMPATIBLE
185		?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
186
187	$(varPrefix)_PLATFORM_(libbe_test)_COMPATIBLE
188		?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
189}
190
191rule FAnalyzeGCCVersion
192{
193	# FAnalyzeGCCVersion <rawVersionVariable> ;
194	#
195	local varName = $(1) ;
196	local rawVersion = $($(varName)) ;
197
198	if ! $(rawVersion) {
199		ECHO "Variable $(varName) not set. Please run ./configure or" ;
200		EXIT "specify it manually." ;
201	}
202
203	local version = ;
204	# split the raw version string at `.' and `-' characters
205	while $(rawVersion) {
206		local split = [ Match "([^.-]*)[.-](.*)" : $(rawVersion) ] ;
207		if $(split) {
208			version += $(split[1]) ;
209			rawVersion = $(split[2]) ;
210		} else {
211			version += $(rawVersion) ;
212			rawVersion = ;
213		}
214	}
215
216	return $(version) ;
217}
218
219rule SetIncludePropertiesVariables
220{
221	# SetIncludePropertiesVariables <varPrefix> ;
222	#
223	local prefix = $(1) ;
224	if $($(prefix)_GCC_VERSION[1]) < 4 {
225		$(prefix)_INCLUDES_SEPARATOR = -I- ;
226		$(prefix)_LOCAL_INCLUDES_OPTION = -I ;
227		$(prefix)_SYSTEM_INCLUDES_OPTION = -I ;
228	} else {
229		$(prefix)_INCLUDES_SEPARATOR = ;
230		$(prefix)_LOCAL_INCLUDES_OPTION = "-iquote " ;
231		$(prefix)_SYSTEM_INCLUDES_OPTION = "-idirafter " ;
232	}
233}
234
235
236#pragma mark -
237
238rule SetPlatformForTarget
239{
240	# SetPlatformForTarget <target> : <platform> ;
241
242	PLATFORM on $(1) = $(2) ;
243}
244
245rule SetSubDirPlatform
246{
247	# SetSubDirPlatform <platform> ;
248
249	PLATFORM = $(1) ;
250}
251
252rule SetSupportedPlatformsForTarget
253{
254	# SetSupportedPlatformsForTarget <target> : <platforms> ;
255
256	SUPPORTED_PLATFORMS on $(1) = $(2) ;
257}
258
259rule SetSubDirSupportedPlatforms
260{
261	# SetSubDirSupportedPlatforms <platforms> ;
262
263	SUPPORTED_PLATFORMS = $(1) ;
264}
265
266rule AddSubDirSupportedPlatforms
267{
268	# AddSubDirSupportedPlatforms <platforms> ;
269
270	SUPPORTED_PLATFORMS += $(1) ;
271}
272
273rule SetSubDirSupportedPlatformsBeOSCompatible
274{
275	# SetSubDirSupportedPlatformsBeOSCompatible ;
276
277	SUPPORTED_PLATFORMS = $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ;
278}
279
280rule IsPlatformSupportedForTarget
281{
282	# IsPlatformSupportedForTarget <target> [ : <platform> ]
283	#
284
285	on $(1) {
286		if $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
287			return true ;
288		} else {
289			return ;
290		}
291	}
292}
293
294rule InheritPlatform
295{
296	# InheritPlatform <children> : <parent> ;
297	# PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value
298	# on <parent>.
299	#
300	local children = $(1) ;
301	local parent = $(2) ;
302
303	on $(parent) {
304		PLATFORM on $(children) = $(PLATFORM) ;
305		SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ;
306	}
307}
308