xref: /haiku/build/jam/MiscRules (revision 56eb8e78cc702792e3b032e3f5f45da9e5dbea9e)
1
2rule SetupObjectsDir
3{
4	local relPath = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
5	if $(relPath) = . {
6		relPath = ;
7	}
8	COMMON_PLATFORM_LOCATE_TARGET =
9		[ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) $(relPath) ] ;
10
11	local var ;
12	for var in COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) {
13		HOST_$(var)_LOCATE_TARGET
14			= [ FDirName $(HOST_$(var)_OBJECT_DIR) $(relPath) ] ;
15		TARGET_$(var)_LOCATE_TARGET
16			= [ FDirName $(TARGET_$(var)_OBJECT_DIR) $(relPath) ] ;
17	}
18
19	LOCATE_TARGET = $(COMMON_PLATFORM_LOCATE_TARGET) ;
20	LOCATE_SOURCE = $(LOCATE_TARGET) ;
21	SEARCH_SOURCE = $(SUBDIR) $(LOCATE_SOURCE)
22		$(HOST_COMMON_DEBUG_LOCATE_TARGET)		# Also add the standard output
23		$(TARGET_COMMON_DEBUG_LOCATE_TARGET)	# dirs for generated sources.
24	;
25}
26
27rule SubIncludeGPL
28{
29	# SubInclude rule that can be used to conditionally include GPL licensed
30	# add-ons
31	if $(INCLUDE_GPL_ADDONS) = 1 {
32		SubInclude $(1) ;
33	}
34}
35
36
37# pragma mark - MakeLocate variants
38
39
40rule MakeLocateCommonPlatform
41{
42	MakeLocate $(1) : $(COMMON_PLATFORM_LOCATE_TARGET) ;
43}
44
45rule MakeLocatePlatform
46{
47	local files = $(1) ;
48	local file ;
49	for file in $(files) {
50		if [ on $(file) return $(PLATFORM) ] = host {
51			MakeLocate $(file) : $(HOST_COMMON_ARCH_LOCATE_TARGET) ;
52		} else {
53			MakeLocate $(file) : $(TARGET_COMMON_ARCH_LOCATE_TARGET) ;
54		}
55	}
56}
57
58rule MakeLocateArch
59{
60	local files = $(1) ;
61	local file ;
62	for file in $(files) {
63		if [ on $(file) return $(PLATFORM) ] = host {
64			MakeLocate $(file) : $(HOST_COMMON_DEBUG_LOCATE_TARGET) ;
65		} else {
66			MakeLocate $(file) : $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ;
67		}
68	}
69}
70
71rule MakeLocateDebug
72{
73	local files = $(1) ;
74	local file ;
75	for file in $(files) {
76		on $(file) {
77			if $(PLATFORM) = host {
78				MakeLocate $(file) : $(HOST_DEBUG_$(DEBUG)_LOCATE_TARGET) ;
79			} else {
80				MakeLocate $(file) : $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) ;
81			}
82		}
83	}
84}
85
86
87# pragma mark - Deferred SubIncludes
88
89
90# The variable used to collect the deferred SubIncludes.
91HAIKU_DEFERRED_SUB_INCLUDES = ;
92
93rule DeferredSubInclude params
94{
95	# DeferredSubInclude <subdir tokens> ;
96	#
97	# Takes the same parameter as SubInclude. The the subdirectory referred to
98	# by <subdir tokens> will be included when ExecuteDeferredSubIncludes is
99	# invoked, i.e. at the end of the root Jamfile.
100
101	HAIKU_DEFERRED_SUB_INCLUDES += "/" $(params) ;
102}
103
104rule ExecuteDeferredSubIncludes
105{
106	# ExecuteDeferredSubIncludes ;
107	#
108	# Performs the deferred SubIncludes scheduled by DeferredSubInclude.
109
110	local tokensList = $(HAIKU_DEFERRED_SUB_INCLUDES) ;
111	while $(tokensList) {
112		# chop off leading "/"
113		tokensList = $(tokensList[2-]) ;
114
115		# get the tokens for the next include
116		local tokens ;
117		while $(tokensList) && $(tokensList[1]) != "/" {
118			tokens += $(tokensList[1]) ;
119			tokensList = $(tokensList[2-]) ;
120		}
121
122		# perform the include
123		if $(tokens) {
124			SubInclude $(tokens) ;
125		}
126	}
127}
128
129rule HaikuSubInclude tokens
130{
131	# HaikuSubInclude <tokens> ;
132	#
133	# Current subdir relative SubInclude.
134	# <tokens> - subdir tokens specifying the subdirectory to be include
135	#            (relative to the current subdir)
136
137	if $(tokens) {
138		SubInclude HAIKU_TOP $(SUBDIR_TOKENS) $(tokens) ;
139	}
140}
141
142
143# pragma mark - Unique IDs/targets
144
145
146# private to NextID; incremented with each NextID invocation
147HAIKU_NEXT_ID = 0 ;
148
149rule NextID
150{
151	# NextID ;
152
153	local result = $(HAIKU_NEXT_ID:J=) ;
154	HAIKU_NEXT_ID = [ AddNumAbs $(HAIKU_NEXT_ID) : 1 ] ;
155	return $(result) ;
156}
157
158rule NewUniqueTarget basename
159{
160	# NewUniqueTarget [ basename ] ;
161
162	local id = [ NextID ] ;
163	return $(basename[1]:E=_target:G=unique!target)_$(id) ;
164}
165
166
167# pragma mark - RunCommandLine
168
169
170rule RunCommandLine commandLine
171{
172	# RunCommandLine <commandLine>
173	#
174	# Creates a pseudo target that, when made by jam, causes the supplied shell
175	# command line to be executed. Elements of <commandLine> with the prefix ":"
176	# are replaced by the rule. After stripping the prefix such a string specifies
177	# a build system target and the finally executed command line will contain
178	# a path to the target instead.
179	# The pseudo target will depend on all targets thus identified. Each
180	# invocation of this rule creates a different pseudo target, which is
181	# returned to the caller.
182
183	# collect the targets in the command line and replace them by $targetX*
184	# variables
185	local substitutedCommandLine ;
186	local targets ;
187
188	local targetVarName = target ;
189	local i ;
190	for i in $(commandLine)  {
191		# targets are marked by the ":" prefix
192		local target = [ Match ^:(.*) : $(i) ] ;
193		if $(target) {
194			targets += $(target) ;
195			targetVarName = $(targetVarName)X ;
196			i = "$"$(targetVarName) ;
197		}
198
199		substitutedCommandLine += $(i) ;
200	}
201
202	# define the "run" target
203	local run = [ NewUniqueTarget run ] ;
204	COMMAND_LINE on $(run) = $(substitutedCommandLine) ;
205	NotFile $(run) ;
206	Always $(run) ;
207	Depends $(run) : $(targets) ;
208	RunCommandLine1 $(run) : $(targets) ;
209
210	return $(run) ;
211}
212
213actions RunCommandLine1 {
214	target=target;
215	for t in $(2) ; do
216		target=${target}X
217		eval "${target}=${t}"
218	done
219	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
220	$(COMMAND_LINE)
221}
222
223