xref: /haiku/build/jam/HelperRules (revision 683cbefe9ec156fe9587b9a64a5e1b666a21654d)
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	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = ;
130	$(varPrefix)_PLATFORM_BONE_COMPATIBLE = ;
131	$(varPrefix)_PLATFORM_DANO_COMPATIBLE = ;
132	$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ;
133
134	switch $(platform)
135	{
136		case r5 :
137		{
138			$(varPrefix)_PLATFORM_BEOS_COMPATIBLE = true ;
139		}
140
141		case bone :
142		{
143			$(varPrefix)_PLATFORM_BONE_COMPATIBLE = true ;
144		}
145
146		case dano :
147		{
148			$(varPrefix)_PLATFORM_DANO_COMPATIBLE = true ;
149		}
150
151		case haiku :
152		{
153			$(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ;
154		}
155
156		case * :
157		{
158			if ! ( $(platform) in $(otherPlatforms) ) {
159				Exit Unsupported $(platformKind) platform: $(platform) ;
160			}
161		}
162	}
163
164	# set lesser flags, e.g. "DANO" for "HAIKU" and "BEOS" for "BONE"
165	$(varPrefix)_PLATFORM_DANO_COMPATIBLE
166		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
167	$(varPrefix)_PLATFORM_BONE_COMPATIBLE
168		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
169	$(varPrefix)_PLATFORM_BEOS_COMPATIBLE
170		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
171
172	# set the machine friendly flags
173	$(varPrefix)_PLATFORM_(haiku)_COMPATIBLE
174		?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ;
175	$(varPrefix)_PLATFORM_(dano)_COMPATIBLE
176		?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ;
177	$(varPrefix)_PLATFORM_(bone)_COMPATIBLE
178		?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ;
179	$(varPrefix)_PLATFORM_(r5)_COMPATIBLE
180		?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ;
181}
182
183
184#pragma mark -
185
186rule SetPlatformForTarget
187{
188	# SetPlatformForTarget <target> : <platform> ;
189
190	PLATFORM on $(1) = $(2) ;
191}
192
193rule SetSubDirPlatform
194{
195	# SetSubDirPlatform <platform> ;
196
197	PLATFORM = $(1) ;
198}
199
200rule SetSupportedPlatformsForTarget
201{
202	# SetSupportedPlatformsForTarget <target> : <platforms> ;
203
204	SUPPORTED_PLATFORMS on $(1) = $(2) ;
205}
206
207rule SetSubDirSupportedPlatforms
208{
209	# SetSubDirSupportedPlatforms <platforms> ;
210
211	SUPPORTED_PLATFORMS = $(1) ;
212}
213
214rule SetSubDirSupportedPlatformsBeOSCompatible
215{
216	# SetSubDirSupportedPlatformsBeOSCompatible ;
217
218	SUPPORTED_PLATFORMS = $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ;
219}
220
221rule IsPlatformSupportedForTarget
222{
223	# IsPlatformSupportedForTarget <target> [ : <platform> ]
224	#
225
226	on $(1) {
227		if $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
228			return true ;
229		} else {
230			return ;
231		}
232	}
233}
234
235rule InheritPlatform
236{
237	# InheritPlatform <children> : <parent> ;
238	# PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value
239	# on <parent>.
240	#
241	local children = $(1) ;
242	local parent = $(2) ;
243
244	on $(parent) {
245		PLATFORM on $(children) = $(PLATFORM) ;
246		SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ;
247	}
248}
249