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