xref: /haiku/build/jam/HeadersRules (revision 99d027cd0238c1d86da86d7c3f4200509ccc61a6)
1
2# FIncludes <dirs> ;
3#
4# Overridden to support a second argument, the option to be used.
5#
6rule FIncludes
7{
8	return $(2:E="--bad-include-option ")$(1) ;
9}
10
11
12# FSysIncludes <dirs> ;
13#
14# Counterpart of FIncludes for system include search paths.
15#
16rule FSysIncludes
17{
18	return $(2:E="--bad-include-option ")$(1) ;
19}
20
21
22rule SubDirSysHdrs
23{
24	# SubDirSysHdrs <dirs> ;
25	#
26	# Adds directories to the system include search paths for the current
27	# subdirectory. Counterpart of SubDirHdrs which adds non-system include
28	# search paths.
29	#
30	# <dirs>: The directories to be added to the current subdir's system
31	#         include search paths.
32	#
33	SUBDIRSYSHDRS += [ FDirName $(1) ] ;
34}
35
36
37rule ObjectSysHdrs
38{
39	# ObjectSysHdrs <sources or objects> : <headers> : <gristed objects>
40	#
41	# Adds directories to the system include search paths for the given
42	# sources or objects. Counterpart of ObjectHdrs which adds non-system
43	# include search paths.
44	#
45	# NOTE: With this incarnation of the Haiku build system this rule doesn't
46	# need to be invoked *after* the rule that generates the objects anymore.
47	# Actually it is even encouraged to do that *before*. Same for ObjectHdrs.
48	#
49	# <sources or objects>: The targets for which to add system include
50	#                       search paths.
51	# <dirs>: The directories to be added to the given objects' system
52	#         include search paths.
53	#
54
55	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] $(3) ;
56	local headers = $(2) ;
57
58	local file ;
59	for file in $(objects) {
60		on $(file) {
61			local sysHeaders = $(SYSHDRS) $(headers) ;
62			SYSHDRS on $(file) = $(sysHeaders) ;
63
64			# reformat ASHDRS and CCHDRS
65			local fileHeaders ;
66
67			if $(PLATFORM) = host {
68				fileHeaders =
69					[ FIncludes $(HDRS) : $(HOST_LOCAL_INCLUDES_OPTION) ]
70					$(HOST_INCLUDES_SEPARATOR)
71					[ FSysIncludes $(sysHeaders)
72						: $(HOST_SYSTEM_INCLUDES_OPTION) ] ;
73			} else {
74				fileHeaders =
75					[ FIncludes $(HDRS) : $(TARGET_LOCAL_INCLUDES_OPTION) ]
76					$(TARGET_INCLUDES_SEPARATOR)
77					[ FSysIncludes $(sysHeaders)
78						: $(TARGET_SYSTEM_INCLUDES_OPTION) ] ;
79			}
80
81			ASHDRS on $(file) = $(fileHeaders) ;
82			CCHDRS on $(file) = $(fileHeaders) ;
83		}
84	}
85}
86
87
88rule SourceHdrs
89{
90	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
91	#
92	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
93	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
94	# done by ObjectHdrs).
95
96	local sources = [ FGristFiles $(1) ] ;
97	local headers = $(2) ;
98	local objects = $(3) ;
99
100	ObjectHdrs $(sources) : $(headers) : $(objects) ;
101
102	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
103	# will be listed after the STDHDRS (if any), but that's better than not
104	# being listed at all.
105	HDRSEARCH on $(sources) += $(headers) ;
106}
107
108
109rule SourceSysHdrs
110{
111	# SourceSysHdrs <sources> : <headers> [ : <gristed objects> ] ;
112	#
113	# Is a wrapper for ObjectSysHdrs, that passes <sources> and <headers> or,
114	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
115	# done by ObjectSysHdrs).
116
117	local sources = [ FGristFiles $(1) ] ;
118	local headers = $(2) ;
119	local objects = $(3) ;
120
121	ObjectSysHdrs $(sources) : $(headers) : $(objects) ;
122
123	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
124	# will be listed after the STDHDRS (if any), but that's better than not
125	# being listed at all.
126	HDRSEARCH on $(sources) += $(headers) ;
127}
128
129
130rule PublicHeaders
131{
132	# PublicHeaders <group list>
133	#
134	# Returns the directory names for the public header dirs identified by
135	# <group list>.
136
137	local list = $(1) ;
138	local dirs ;
139
140	for i in $(list) {
141		dirs += [ FDirName $(HAIKU_TOP) headers os $(i) ] ;
142	}
143	return $(dirs) ;
144}
145
146
147rule PrivateHeaders
148{
149	# PrivateHeaders <group list>
150	#
151	# Returns the directory names for the private header dirs identified by
152	# <group list>.
153
154	local list = $(1) ;
155	local dirs ;
156	for i in $(list) {
157		dirs += [ FDirName $(HAIKU_TOP) headers private $(i) ] ;
158	}
159	return $(dirs) ;
160}
161
162
163rule PrivateBuildHeaders
164{
165	# PrivateBuildHeaders <group list>
166	#
167	# Returns the directory names for the private build header dirs identified
168	# by <group list>.
169
170	local list = $(1) ;
171	local dirs ;
172	for i in $(list) {
173		dirs += [ FDirName $(HAIKU_TOP) headers build private $(i) ] ;
174	}
175	return $(dirs) ;
176}
177
178
179rule LibraryHeaders
180{
181	# LibraryHeaders <group list>
182	#
183	# Returns the directory names for the library header dirs identified by
184	# <group list>.
185
186	local list = $(1) ;
187	local dirs ;
188	for i in $(list) {
189		dirs += [ FDirName $(HAIKU_TOP) headers libs $(i) ] ;
190	}
191	return $(dirs) ;
192}
193
194
195rule ArchHeaders
196{
197	# usage: ArchHeaders <arch> ;
198	#
199	# <arch> specifies the architecture (e.g. x86).
200
201	return [ FDirName $(HAIKU_TOP) headers private kernel arch $(1) ] ;
202}
203
204
205rule UseHeaders
206{
207	# UseHeaders <headers> [ : <system> ] ;
208	#
209	# Adds the C header dirs <headers> to the header search
210	# dirs of the subdirectory.
211	# If <system> is "true", the dirs are added as system otherwise local
212	# search dirs.
213	# NOTE: This rule must be invoked *before* the rule that builds the objects.
214
215	local header ;
216	if $(2) = true {
217		for header in $(1) {
218			SubDirSysHdrs $(header) ;
219		}
220	} else {
221		for header in $(1) {
222			SubDirHdrs $(header) ;
223		}
224	}
225}
226
227
228rule UsePublicHeaders
229{
230	# UsePublicHeaders <group list> ;
231	#
232	# Adds the public C header dirs given by <group list> to the header search
233	# dirs of the subdirectory.
234	# NOTE: This rule must be invoked *before* the rule that builds the
235	# objects.
236
237	UseHeaders [ PublicHeaders $(1) ] : true ;
238}
239
240
241rule UsePublicObjectHeaders
242{
243	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
244	#
245	# Adds the public C header dirs given by <group list> to the header search
246	# dirs of either the object targets of <sources> or if supplied to
247	# <objects>. Also adjusts HDRSEARCH of <sources>.
248
249	SourceSysHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
250}
251
252
253rule UsePrivateHeaders
254{
255	# UsePrivateHeaders <group list> [ : <system> ] ;
256	#
257	# Adds the private C header dirs given by <group list> to the header search
258	# dirs of the subdirectory.
259	# <system> specifies whether to add the dirs as system or local header
260	# search dirs. Defaults to "true".
261	# NOTE: This rule must be invoked *before* the rule that builds the objects.
262
263	local system = $(2) ;
264	system ?= true ;
265
266	UseHeaders [ PrivateHeaders $(1) ] : $(system) ;
267}
268
269
270rule UsePrivateObjectHeaders
271{
272	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects>
273	#	[ : <system> ] ] ;
274	#
275	# Adds the private C header dirs given by <group list> to the header search
276	# dirs of either the object targets of <sources> or if supplied to
277	# <objects>. Also adjusts HDRSEARCH of <sources>.
278	# <system> specifies whether to add the dirs as system or local header
279	# search dirs. Defaults to "true".
280
281	local system = $(4) ;
282	system ?= true ;
283
284	if $(system) = true {
285		SourceSysHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
286	} else {
287		SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
288	}
289}
290
291
292rule UsePrivateBuildHeaders
293{
294	# UsePrivateBuildHeaders <group list> [ : <system> ] ;
295	#
296	# Adds the private build C header dirs given by <group list> to the header
297	# search dirs of the subdirectory.
298	# <system> specifies whether to add the dirs as system or local header
299	# search dirs. Defaults to "true".
300	# NOTE: This rule must be invoked *before* the rule that builds the objects.
301
302	local system = $(2) ;
303	system ?= true ;
304
305	UseHeaders [ PrivateBuildHeaders $(1) ] : $(system) ;
306}
307
308
309rule UseCppUnitHeaders
310{
311	SubDirSysHdrs [ FDirName $(HAIKU_TOP) headers tools cppunit ] ;
312}
313
314
315rule UseCppUnitObjectHeaders
316{
317	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
318	SourceSysHdrs $(1) : [ FDirName $(HAIKU_TOP) headers tools cppunit ]
319		: $(2) ;
320}
321
322
323rule UseArchHeaders
324{
325	# usage: UseArchHeaders <arch> ;
326	#
327	# <arch> specifies the architecture (e.g. x86).
328	# NOTE: This rule must be invoked *before* the rule that builds the objects.
329
330	local headers = [ ArchHeaders $(1) ] ;
331
332	UseHeaders $(headers) : true ;
333}
334
335
336rule UseArchObjectHeaders
337{
338	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
339	#
340	# <arch> specifies the architecture (e.g. x86).
341	# <sources_or_objects> Source or object files.
342
343	local sources = $(1) ;
344	local headers = [ ArchHeaders $(2) ] ;
345	local objects = $(3) ;
346	local targets ;
347	if $(objects) {
348		targets = $(objects) ;
349	} else {
350		targets = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
351	}
352
353	SourceSysHdrs $(sources) : $(headers) : $(objects) ;
354}
355
356
357rule UsePosixObjectHeaders
358{
359	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
360	#
361	# Adds the POSIX header dir to the header search
362	# dirs of either the object targets of <sources> or if supplied to
363	# <objects>. Also adjusts HDRSEARCH of <sources>.
364
365	SourceSysHdrs $(1) : [ FDirName $(HAIKU_TOP) headers posix ] : $(2) ;
366}
367
368
369rule UseLibraryHeaders
370{
371	# UseLibraryHeaders <group list> ;
372	#
373	# Adds the library header dirs given by <group list> to the header search
374	# dirs of the subdirectory.
375	# NOTE: This rule must be invoked *before* the rule that builds the objects.
376
377	UseHeaders [ LibraryHeaders $(1) ] : true ;
378}
379
380
381rule UseLegacyHeaders
382{
383	# usage: UseLegacyHeaders <group list> ;
384	#
385	# NOTE: This rule must be invoked *before* the rule that builds the objects.
386
387	UseHeaders [ FDirName $(HAIKU_TOP) headers legacy $(1) ] : true ;
388}
389
390
391rule UseLegacyObjectHeaders
392{
393	# UseLegacyObjectHeaders <sources> [ : <objects> ] ;
394	#
395	# Adds the legacy header dir to the header search
396	# dirs of either the object targets of <sources> or if supplied to
397	# <objects>. Also adjusts HDRSEARCH of <sources>.
398
399	SourceSysHdrs $(1) : [ FDirName $(HAIKU_TOP) headers legacy ] : $(2) ;
400}
401
402
403rule UsePrivateKernelHeaders
404{
405	UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ;
406}
407
408
409rule UsePrivateSystemHeaders
410{
411	UseHeaders $(TARGET_PRIVATE_SYSTEM_HEADERS) : true ;
412}
413
414
415rule FStandardOSHeaders
416{
417	local osIncludes = add-ons add-ons/file_system add-ons/graphics
418					   add-ons/input_server add-ons/registrar
419					   add-ons/screen_saver
420					   add-ons/tracker app device drivers game interface
421					   kernel locale media mail midi midi2 net opengl storage
422					   support translation ;
423
424	return [ FDirName $(HAIKU_TOP) headers os ]
425		[ PublicHeaders $(osIncludes) ] ;
426}
427
428
429rule FStandardHeaders
430{
431	local osIncludes = add-ons add-ons/file_system add-ons/graphics
432					   add-ons/input_server add-ons/registrar
433					   add-ons/screen_saver
434					   add-ons/tracker app device drivers game interface
435					   kernel locale media mail midi midi2 net opengl storage
436					   support translation ;
437
438	local headers = ;
439
440	# The C++ headers. If specified, we use the compiler headers, otherwise
441	# the ones that come with our libstdc++.
442	if $(HAIKU_C++_HEADERS_DIR) {
443		headers += $(HAIKU_C++_HEADERS_DIR) ;
444	} else {
445		headers += [ FDirName $(HAIKU_TOP) headers cpp ] ;
446	}
447
448	# GCC headers
449	headers += $(HAIKU_GCC_HEADERS_DIR) ;
450
451	# Use headers directory, to allow to do things like include <posix/string.h>
452	headers += [ FDirName $(HAIKU_TOP) headers ] ;
453
454	# Use posix headers directory
455	headers += [ FDirName $(HAIKU_TOP) headers posix ] ;
456
457	# Use glibc headers
458	headers += [ FDirName $(HAIKU_TOP) headers glibc ] ;
459
460	# Use public OS header directories
461	headers += [ FDirName $(HAIKU_TOP) headers os ] ;
462	headers += [ PublicHeaders $(osIncludes) ] ;
463
464	# Use the root of the private headers -- not so nice, but simplifies things.
465	headers += [ PrivateHeaders $(DOT) ] ;
466
467	return $(headers) ;
468}
469
470
471# SUBDIRSYSHDRS shall be reset automatically for each subdir
472SUBDIRRESET += SYSHDRS ;
473