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