xref: /haiku/build/jam/TestsRules (revision 683cbefe9ec156fe9587b9a64a5e1b666a21654d)
1# test pseudo targets
2NOTFILE obostests ;
3NOTFILE r5tests ;
4
5rule CommonTestLib
6{
7	# CommonTestLib <target> : <sources> : <obos libraries>
8	#	: <r5 libraries> : <test libraries> : <public headers>;
9	# Builds a unit test for both OBOS and R5 modules.
10	# <target> The name of the target.
11	# <sources> The list of sources.
12	# <obos libraries> A list of link libraries for the OBOS tests (as passed
13	# to LinkAgainst).
14	# <r5 libraries> A list of link libraries for the R5 tests (as passed
15	# to LinkAgainst).
16	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
17	# that have a common name (i.e. specify libx.so and the OBOS tests will link
18	# to libx.so and the R5 tests will link to libx_r5.so).
19	# <public headers> A list of public header dirs (as passed to
20	# UsePublicHeaders).
21
22	TestLib $(1) : $(2) : [ FDirName $(HAIKU_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
23	R5TestLib $(1) : $(2) : [ FDirName $(HAIKU_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
24}
25
26rule TestLib
27{
28	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
29	# Builds a unit test library for an OBOS module.
30	# <target> The name of the target.
31	# <sources> The list of sources.
32	# <dest> The directory for the target (as passed to FDirName).
33	# <libraries> A list of link libraries (as passed to LinkAgainst).
34	# <public headers> A list of public header dirs (as passed to
35	# UsePublicHeaders).
36
37	local target = $(1) ;
38	local sources = $(2) ;
39	local dest = $(3) ;
40	local libraries = $(4) ;
41	local headerDirs = $(5) ;
42	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
43
44	# Our Main replacement.
45	MakeLocate $(target) : $(dest) ;
46	MainFromObjects $(target) : $(objects) ;
47	TestObjects $(sources) : $(headerDirs) ;
48
49	Depends $(target) : libcppunit.so ;
50	Depends obostests : $(target) ;
51	LinkAgainst $(target) : libcppunit.so $(libraries) ;
52	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
53}
54
55rule R5TestLib
56{
57	# R5TestLib <target> : <sources> : <dest> : <libraries>
58	# Builds a unit test for an R5 module. "_r5" is appended to the object
59	# and the target name.
60	# <target> The name of the target.
61	# <sources> The list of sources.
62	# <dest> The directory for the target (as passed to FDirName).
63	# <libraries> A list of link libraries (as passed to LinkAgainst).
64
65	local target = $(1:B)_r5$(1:S) ;
66	local sources = $(2) ;
67	local dest = $(3) ;
68	local libraries = $(4) ;
69	local objects = [ R5ObjectNames $(sources) ] ;
70
71	# Our Main replacement.
72	MakeLocate $(target) : $(dest) ;
73	MainFromObjects $(target) : $(objects) ;
74	TestObjects $(sources) : : true ;
75
76	Depends $(target) : libcppunit.so ;
77	Depends r5tests : $(target) ;
78	LinkAgainst $(target) : libcppunit.so $(libraries) ;
79	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
80}
81
82rule CommonUnitTest
83{
84	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
85	#	: <r5 libraries> : <public headers>;
86	# Builds a unit test for both OBOS and R5 modules.
87	# <target> The name of the target.
88	# <sources> The list of sources.
89	# <dest> The directory for the target (as passed to FDirName).
90	# <obos libraries> A list of link libraries for the OBOS tests (as passed
91	# to LinkAgainst).
92	# <r5 libraries> A list of link libraries for the R5 tests (as passed
93	# to LinkAgainst).
94	# <public headers> A list of public header dirs (as passed to
95	# UsePublicHeaders).
96
97	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
98	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
99}
100
101rule UnitTest
102{
103	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
104	# Builds a unit test for an OBOS module.
105	# <target> The name of the target.
106	# <sources> The list of sources.
107	# <dest> The directory for the target (as passed to FDirName).
108	# <libraries> A list of link libraries (as passed to LinkAgainst).
109	# <public headers> A list of public header dirs (as passed to
110	# UsePublicHeaders).
111
112	local target = $(1) ;
113	local sources = $(2) ;
114	local dest = $(3) ;
115	local libraries = $(4) ;
116	local headerDirs = $(5) ;
117	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
118
119	# Our Main replacement.
120	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(dest) ] ;
121	MainFromObjects $(target) : $(objects) ;
122	TestObjects $(sources) : $(headerDirs) ;
123
124	Depends $(target) : libcppunit.so ;
125	Depends obostests : $(target) ;
126	LinkAgainst $(target) : libcppunit.so $(libraries) ;
127}
128
129rule R5UnitTest
130{
131	# R5UnitTest <target> : <sources> : <dest> : <libraries>
132	# Builds a unit test for an R5 module. "_r5" is appended to the object
133	# and the target name.
134	# <target> The name of the target.
135	# <sources> The list of sources.
136	# <dest> The directory for the target (as passed to FDirName).
137	# <libraries> A list of link libraries (as passed to LinkAgainst).
138
139	local target = $(1)_r5 ;
140	local sources = $(2) ;
141	local dest = $(3) ;
142	local libraries = $(4) ;
143	local objects = [ R5ObjectNames $(sources) ] ;
144
145	# Our Main replacement.
146	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(dest) ] ;
147	MainFromObjects $(target) : $(objects) ;
148	TestObjects $(sources) : : true ;
149
150	Depends $(target) : libcppunit.so ;
151	Depends r5tests : $(target) ;
152	LinkAgainst $(target) : libcppunit.so $(libraries) ;
153}
154
155rule R5ObjectNames
156{
157	# R5ObjectNames <sources> ;
158	# Returns a list of gristed object names given a list of source file names.
159	# Moreover each object names gets "_r5" inserted before the object suffix.
160	local objects = $(1:S=)_r5 ;
161	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
162}
163
164rule R5Objects
165{
166	# R5Objects <sources>
167	# Similar to Objects, but appends "_r5" to the object file names and
168	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
169	# <sources> The source files.
170
171	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
172	local oldCCFLAGS = $(CCFLAGS) ;
173	local oldC++FLAGS = $(C++FLAGS) ;
174	CCFLAGS = [ FFilter $(CCFLAGS) : -nostdinc ] ;
175	C++FLAGS = [ FFilter $(C++FLAGS) : -nostdinc ] ;
176
177	local sources = $(1) ;
178	local source ;
179	for source in [ FGristFiles $(sources) ]
180	{
181		local object = [ R5ObjectNames $(source) ] ;
182		Object $(object) : $(source) ;
183		LocalDepends obj : $(object) ;
184	}
185
186	# Reset CCFLAGS and C++FLAGS to original values.
187	CCFLAGS = $(oldCCFLAGS) ;
188	C++FLAGS = $(oldC++FLAGS) ;
189}
190
191rule TestObjects
192{
193	# TestLib <sources> : <public headers> : <r5>
194	# Compiles objects for tests.
195	# <sources> The list of sources.
196	# <public headers> A list of public header dirs (as passed to
197	# UsePublicHeaders).
198	# <r5> If set, "_r5" is appended to the object file names and
199	# <public headers> is ignored. Furthermore the pre-processor macro
200	# TEST_R5 is defined, TEST_OBOS otherwise.
201
202	local sources = $(1) ;
203	local headerDirs = $(2) ;
204	local r5 = $(3) ;
205	local objects ;
206
207	if $(r5) {
208		objects = [ R5ObjectNames $(sources) ] ;
209	} else {
210		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
211	}
212
213	# Turn optimization off, if desired.
214	if ! $(NO_TEST_DEBUG) {
215		OPTIM on $(objects) = ;
216	}
217
218	# set headers/defines
219	UseCppUnitObjectHeaders $(sources) : $(objects) ;
220	if $(r5) {
221		ObjectDefines $(sources) : TEST_R5 ;
222	} else {
223		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
224		ObjectDefines $(sources) : TEST_OBOS ;
225	}
226
227	if ! $(NO_TEST_DEBUG) {
228		# Turn debugging on. That is usually desired for test code.
229		ObjectCcFlags $(objects) : $(DEBUG_FLAGS) ;
230		ObjectC++Flags $(objects) : $(DEBUG_FLAGS) ;
231	}
232
233	# compile
234	if $(r5) {
235		R5Objects $(sources) ;
236	} else {
237		Objects $(sources) ;
238	}
239}
240
241rule R5SharedLibraryNames
242{
243	# R5SharedLibraryNames <sources> ;
244	# Returns a list of shared library names given a list of file names. NO
245	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
246	# before the shared lib suffix.
247	return $(1:S=)_r5.so ;
248}
249
250rule SimpleTest
251{
252	# UnitTest <target> : <sources> : <libraries>
253	# Builds a unit test for an OBOS module.
254	# <target> The name of the target.
255	# <sources> The list of sources.
256	# <dest> The directory for the target (as passed to FDirName).
257	# <libraries> A list of link libraries (as passed to LinkAgainst).
258	# <public headers> A list of public header dirs (as passed to
259	# UsePublicHeaders).
260
261	local target = $(1) ;
262	local sources = $(2) ;
263	local libraries = $(3) ;
264	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
265
266	# Turn optimization off.
267	if ! $(NO_TEST_DEBUG) {
268		local optim = $(OPTIM) ;
269		OPTIM = ;
270	}
271
272	ObjectDefines $(sources) : TEST_OBOS ;
273	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ;
274	Main $(target) : $(sources) ;
275	Depends obostests : $(target) ;
276	LinkAgainst $(target) : $(libraries) ;
277	if ! $(NO_TEST_DEBUG) {
278		# Turn debugging on. That is usually desired for test code.
279		ObjectCcFlags $(sources) : $(DEBUG_FLAGS) ;
280		ObjectC++Flags $(sources) : $(DEBUG_FLAGS) ;
281
282		# Turn optimization on again.
283		OPTIM = $(optim) ;
284	}
285}
286
287rule BuildPlatformTest
288{
289	# Usage BuildPlatformTest <target> : <sources> ;
290
291	local target = $(1) ;
292	local sources = $(2) ;
293
294	local relPath ;
295	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
296		relPath = $(SUBDIR_TOKENS[3-]) ;
297	} else {
298		relPath = $(SUBDIR_TOKENS[2-]) ;
299	}
300	MakeLocate $(target) : [ FDirName $(HAIKU_TEST_DIR) $(relPath) ] ;
301
302	BuildPlatformMain $(target) : $(sources) ;
303}
304