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