xref: /haiku/build/jam/OverriddenJamRules (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1#-------------------------------------------------------------------------------
2# Link rule/action are overwritten as they don't handle linking files who's name
3# contain spaces very well. Also adds resources and version to executable.
4#-------------------------------------------------------------------------------
5rule Link
6{
7	# Note: RESFILES must be set before invocation.
8
9	local architecture = [ on $(1) return $(TARGET_PACKAGING_ARCH) ] ;
10	if [ on $(1) return $(PLATFORM) ] = host {
11		LINK on $(1) = $(HOST_LINK) ;
12	 	LINKFLAGS on $(1) = $(HOST_LINKFLAGS) [ on $(1) return $(LINKFLAGS) ] ;
13	} else {
14		LINK on $(1) = $(TARGET_LINK_$(architecture)) ;
15		LINKFLAGS on $(1) = $(TARGET_LINKFLAGS_$(architecture))
16			[ on $(1) return $(LINKFLAGS) ] ;
17	}
18
19	HAIKU_TARGET_IS_EXECUTABLE on $(1) = 1 ;
20
21 	NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] ;
22 	LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] ;
23
24	MODE on $(<) = $(EXEMODE) ;
25	on $(1) XRes $(1) : $(RESFILES) ;
26	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
27		SetType $(1) ;
28		MimeSet $(1) : sharedObject ;
29		SetVersion $(1) ;
30
31		# For applications for the target also generate the MIME DB entries.
32		if [ on $(1) return $(PLATFORM) ] != host
33			&& [ on $(1) return $(RESFILES) ] {
34			CreateAppMimeDBEntries $(1) ;
35		}
36
37		# If the generic attribute emulation is enabled, make sure the tool to
38		# remove the attributes is built first.
39		if $(HOST_RM_ATTRS_TARGET) {
40			Depends $(1) : $(HOST_RM_ATTRS_TARGET) ;
41		}
42	}
43	Chmod $(<) ;
44}
45
46# When using "real" attributes (i.e. BeOS attributes or xattr/extattr) on the
47# host platform, unlinking the main target by gcc will also automatically get
48# rid of the attributes. When using the generic attribute emulation, which
49# uses separate files, we need to remove the target explicitely first, so that
50# the attributes won't be "leaked".
51if $(HAIKU_HOST_USE_XATTR) = 1 {
52	actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE VERSION_SCRIPT
53	{
54		$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" \
55			"$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" \
56			-Wl,--version-script,$(VERSION_SCRIPT)
57	}
58} else {
59	actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE VERSION_SCRIPT
60	{
61		$(RM) "$(1)"
62		$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" \
63			"$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" \
64			-Wl,--version-script,$(VERSION_SCRIPT)
65	}
66}
67
68rule Object
69{
70	# find out which headers and defines to use
71	local headers ;
72	local sysHeaders ;
73	local defines ;
74
75	on $(1) { # use on $(1) variable values
76		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
77			return ;
78		}
79
80		# Save HDRS for -I$(HDRS) on compile.
81		# We shouldn't need -I$(SEARCH_SOURCE) as cc can find headers
82		# in the .c file's directory, but generated .c files (from
83		# yacc, lex, etc) are located in $(LOCATE_TARGET), possibly
84		# different from $(SEARCH_SOURCE).
85
86		headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS)
87			$(HDRS) ;
88		sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ;
89		defines = $(DEFINES) ;
90
91		if $(PLATFORM) = host {
92			sysHeaders += $(HOST_HDRS) ;
93			defines += $(HOST_DEFINES) ;
94
95			if $(USES_BE_API) {
96				sysHeaders += $(HOST_BE_API_HEADERS) ;
97			}
98
99		} else {
100			sysHeaders += [ FStandardHeaders $(TARGET_PACKAGING_ARCH) ]
101				$(TARGET_HDRS_$(TARGET_PACKAGING_ARCH)) ;
102			defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH))
103				$(TARGET_DEFINES) ;
104		}
105	}
106
107	# locate object and search for source
108
109	LocalClean clean : $(<) ;
110
111	MakeLocateDebug $(<) ;
112	SEARCH on $(>) = $(SEARCH_SOURCE) ;
113
114	HDRS on $(<) = $(headers) ;
115	SYSHDRS on $(<) = $(sysHeaders) ;
116
117	# handle #includes for source: Jam scans for headers with
118	# the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE)
119	# with the scanned file as the target and the found headers
120	# as the sources. HDRSEARCH is the value of SEARCH used for
121	# the found header files. Finally, if jam must deal with
122	# header files of the same name in different directories,
123	# they can be distinguished with HDRGRIST.
124
125	# $(SEARCH_SOURCE:E) is where cc first looks for #include
126	# "foo.h" files. If the source file is in a distant directory,
127	# look there. Else, look in "" (the current directory).
128
129	HDRRULE on $(>) = HdrRule ;
130	HDRSCAN on $(>) = $(HDRPATTERN) ;
131	HDRSEARCH on $(>) = $(headers) $(sysHeaders) $(STDHDRS) ;
132	HDRGRIST on $(>) = $(HDRGRIST) ;
133
134	# propagate target specific-defines
135
136	DEFINES on $(1) = $(defines) ;
137
138	# if source is not .c, generate .c with specific rule
139
140	switch $(>:S)
141	{
142		case .asm : As $(<) : $(>) ;
143		case .nasm : AssembleNasm $(<) : $(>) ;
144		case .c :	Cc $(<) : $(>) ;
145		case .C :	C++ $(<) : $(>) ;
146		case .cc :	C++ $(<) : $(>) ;
147		case .cpp : C++ $(<) : $(>) ;
148		case .f :	Fortran $(<) : $(>) ;
149		case .l :	if [ on $(2) return $(GENERATE_C++) ] {
150						InheritPlatform $(<:S=.cpp) : $(1) ;
151						C++ $(<) : $(<:S=.cpp) ;
152						Lex $(<:S=.cpp) : $(>) ;
153					} else {
154						InheritPlatform $(<:S=.c) : $(1) ;
155						Cc $(<) : $(<:S=.c) ;
156						Lex $(<:S=.c) : $(>) ;
157					}
158		case *.o :	return ;
159		case .s :	As $(<) : $(>) ;
160		case .S :	As $(<) : $(>) ;
161		case .y :	if [ on $(2) return $(GENERATE_C++) ] {
162						InheritPlatform $(1:S=.cpp) $(1:S=.hpp) : $(1) ;
163						C++ $(1) : $(1:S=.cpp) ;
164						Yacc $(1:S=.cpp) $(1:S=.hpp) : $(2) ;
165					} else {
166						InheritPlatform $(1:S=.c) $(1:S=.h) : $(1) ;
167						Cc $(1) : $(1:S=.c) ;
168						Yacc $(1:S=.c) $(1:S=.h) : $(2) ;
169					}
170		case * :	UserObject $(<) : $(>) ;
171	}
172}
173
174rule As
175{
176	local flags ;
177	local includesSeparator ;
178	local localIncludesOption ;
179	local systemIncludesOption ;
180	if [ on $(1) return $(PLATFORM) ] = host {
181		flags = [ on $(1) return $(HOST_ASFLAGS) $(ASFLAGS) ] ;
182
183		CC on $(1) = $(HOST_CC) ;
184
185		includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
186		localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
187		systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
188	} else {
189		flags = [ on $(1) return $(TARGET_ASFLAGS_$(TARGET_PACKAGING_ARCH))
190			$(ASFLAGS) ] ;
191
192		CC on $(1) = $(TARGET_CC_$(TARGET_PACKAGING_ARCH)) ;
193
194		includesSeparator
195			= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
196		localIncludesOption
197			= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
198		systemIncludesOption
199			= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
200	}
201
202	Depends $(<) : $(>) [ on $(1) return $(PLATFORM) ] ;
203	ASFLAGS on $(<) += $(flags) $(SUBDIRASFLAGS) ;
204	ASHDRS on $(<) = [ on $(<) FIncludes $(HDRS) : $(localIncludesOption) ]
205		$(includesSeparator)
206		[ on $(<) FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ;
207	ASDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
208}
209
210actions As
211{
212	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(ASDEFS) $(ASHDRS) -o "$(1)"
213}
214
215rule Lex
216{
217	Depends $(1) : $(2) [ on $(1) return $(PLATFORM) ] ;
218	MakeLocateArch $(1) ;
219	LocalClean clean : $(1) ;
220}
221
222actions Lex
223{
224	$(LEX) $(LEXFLAGS) -o$(1) $(2)
225}
226
227rule Yacc
228{
229	local source = $(1[1]) ;
230	local header = $(1[2]) ;
231	local yaccSource = $(2) ;
232
233	MakeLocateArch $(source) $(header) ;
234
235	Depends $(source) $(header)
236		: $(yaccSource) [ on $(source) return $(PLATFORM) ] ;
237	Yacc1 $(source) $(header) : $(yaccSource) ;
238	LocalClean clean : $(source) $(header) ;
239
240	# make sure someone includes $(header) else it will be
241	# a deadly independent target
242
243	Includes $(source) : $(header) ;
244}
245
246actions Yacc1
247{
248	bison $(YACCFLAGS) -o $(1[1]) $(2)
249	[ -f $(1[1]).h ] && mv $(1[1]).h $(1[2]) || true
250}
251
252rule Cc
253{
254	Depends $(<) : $(>) [ on $(1) return $(PLATFORM) ] ;
255
256	on $(1) {
257		local flags ;
258		local includesSeparator ;
259		local localIncludesOption ;
260		local systemIncludesOption ;
261
262		# optimization flags
263		if $(DEBUG) = 0 {
264			flags += $(OPTIM) ;
265		} else {
266			flags += -O0 ;
267		}
268
269		if $(PLATFORM) = host {
270			# warning flags
271			if $(WARNINGS) != 0 {
272				flags += $(HOST_WARNING_CCFLAGS) ;
273				if $(WARNINGS) = treatAsErrors {
274					flags += -Werror $(HOST_WERROR_FLAGS) ;
275				}
276			}
277
278			# debug and other flags
279			flags += $(HOST_CCFLAGS) $(HOST_DEBUG_$(DEBUG)_CCFLAGS)
280				$(SUBDIRCCFLAGS) $(CCFLAGS) ;
281
282			if $(USES_BE_API) {
283				flags += $(HOST_BE_API_CCFLAGS) ;
284			}
285
286			CC on $(1) = $(HOST_CC) ;
287
288			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
289			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
290			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
291		} else {
292			# warning flags
293			if $(WARNINGS) != 0 {
294				flags += $(TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH)) ;
295				if $(WARNINGS) = treatAsErrors {
296					flags += -Werror
297						$(TARGET_WERROR_FLAGS_$(TARGET_PACKAGING_ARCH)) ;
298				}
299			}
300
301			# debug and other flags
302			flags += $(TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH))
303				$(TARGET_DEBUG_$(DEBUG)_CCFLAGS_$(TARGET_PACKAGING_ARCH))
304				$(SUBDIRCCFLAGS) $(CCFLAGS) ;
305
306			CC on $(1) = $(TARGET_CC_$(TARGET_PACKAGING_ARCH)) ;
307
308			includesSeparator
309				= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
310			localIncludesOption
311				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
312			systemIncludesOption
313				= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
314		}
315
316		CCFLAGS on $(<) = $(flags) ;
317		CCHDRS on $(<) = [ FIncludes $(HDRS) : $(localIncludesOption) ]
318			$(includesSeparator)
319			[ FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ;
320		CCDEFS on $(<) = [ FDefines $(DEFINES) ] ;
321	}
322}
323
324actions Cc
325{
326	$(CC) $(CCFLAGS) -c "$(2)" $(CCDEFS) $(CCHDRS) -o "$(1)"
327}
328
329rule C++
330{
331	Depends $(<) : $(>) [ on $(1) return $(PLATFORM) ] ;
332
333	on $(1) {
334		local flags ;
335		local includesSeparator ;
336		local localIncludesOption ;
337		local systemIncludesOption ;
338
339		# optimization flags
340		if $(DEBUG) = 0 {
341			flags += $(OPTIM) ;
342		} else {
343			flags += -O0 ;
344		}
345
346		if $(PLATFORM) = host {
347			# warning flags
348			if $(WARNINGS) != 0 {
349				flags += $(HOST_WARNING_C++FLAGS) ;
350				if $(WARNINGS) = treatAsErrors {
351					flags += -Werror $(HOST_WERROR_FLAGS) ;
352				}
353			}
354
355			# debug and other flags
356			flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS)
357				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
358
359			if $(USES_BE_API) {
360				flags += $(HOST_BE_API_C++FLAGS) ;
361			}
362
363			C++ on $(1) = $(HOST_C++) ;
364
365			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
366			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
367			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
368		} else {
369			# warning flags
370			if $(WARNINGS) != 0 {
371				flags += $(TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)) ;
372				if $(WARNINGS) = treatAsErrors {
373					flags += -Werror
374						$(TARGET_WERROR_FLAGS_$(TARGET_PACKAGING_ARCH)) ;
375				}
376			}
377
378			# debug and other flags
379			flags += $(TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH))
380				$(TARGET_DEBUG_$(DEBUG)_C++FLAGS_$(TARGET_PACKAGING_ARCH))
381				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
382
383			C++ on $(1) = $(TARGET_C++_$(TARGET_PACKAGING_ARCH)) ;
384
385			includesSeparator
386				= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
387			localIncludesOption
388				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
389			systemIncludesOption
390				= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
391		}
392
393		C++FLAGS on $(<) = $(flags) ;
394		CCHDRS on $(<) = [ FIncludes $(HDRS) : $(localIncludesOption) ]
395			$(includesSeparator)
396			[ FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ;
397		CCDEFS on $(<) = [ FDefines $(DEFINES) ] ;
398	}
399}
400
401actions C++
402{
403	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)"
404}
405
406# Force recreation of the archive to avoid build errors caused by
407# stale dependencies after renaming or deleting object files.
408actions together Archive
409{
410	$(RM) $(<)
411	$(AR) $(<) $(>)
412}
413
414rule Library
415{
416	local lib = $(1) ;
417	local sources = [ FGristFiles $(2) ] ;
418	local objects = $(sources:S=$(SUFOBJ)) ;
419
420	InheritPlatform $(objects) : $(lib) ;
421	LibraryFromObjects $(lib) : $(objects) ;
422	Objects $(sources) ;
423}
424
425rule LibraryFromObjects
426{
427	local _i _l _s ;
428
429	# Add grist to file names
430	# bonefish: No, don't. The Library rule does that anyway, and when we
431	# have an object from another dir, we certainly don't want that.
432
433	_s = $(>) ;
434	_l = $(<:S=$(SUFLIB)) ;
435
436	on $(_l) {
437		# set the tools according to the platform
438		if $(PLATFORM) = host {
439			AR on $(_l) = $(HOST_AR) $(HOST_ARFLAGS) ;
440			RANLIB on $(_l) = $(HOST_RANLIB) ;
441		} else {
442			AR on $(_l) = $(TARGET_AR_$(TARGET_PACKAGING_ARCH))
443				$(TARGET_ARFLAGS_$(TARGET_PACKAGING_ARCH)) ;
444			RANLIB on $(_l) = $(TARGET_RANLIB_$(TARGET_PACKAGING_ARCH)) ;
445		}
446
447		# library depends on its member objects
448
449		if $(KEEPOBJS) {
450			LocalDepends obj : $(_s) ;
451		}
452
453		LocalDepends lib : $(_l) ;
454
455		# Set LOCATE for the library and its contents. The bound
456		# value shows up as $(NEEDLIBS) on the Link actions.
457		# For compatibility, we only do this if the library doesn't
458		# already have a path.
459
460		if ! $(_l:D) {
461			# locate the library only, if it hasn't been located yet
462			local dir = $(LOCATE[1]) ;
463			if ! $(dir) {
464				MakeLocateDebug $(_l) ;
465				dir = [ on $(_l) return $(LOCATE[1]) ] ;
466					# Note: The "on ..." is necessary, since our environment
467					# isn't changed by MakeLocateDebug.
468			}
469			MakeLocate $(_l)($(_s:BS)) : $(dir) ;
470		}
471
472		if $(NOARSCAN) {
473			# If we can't scan the library to timestamp its contents,
474			# we have to just make the library depend directly on the
475			# on-disk object files.
476
477			Depends $(_l) : $(_s) ;
478		} else {
479			# If we can scan the library, we make the library depend
480			# on its members and each member depend on the on-disk
481			# object file.
482
483			Depends $(_l) : $(_l)($(_s:BS)) ;
484
485			for _i in $(_s)
486			{
487			Depends $(_l)($(_i:BS)) : $(_i) ;
488			}
489		}
490
491		LocalClean clean : $(_l) ;
492
493		Archive $(_l) : $(_s) ;
494
495		if $(RANLIB) { Ranlib $(_l) ; }
496
497		# If we can't scan the library, we have to leave the .o's around.
498
499		if ! ( $(KEEPOBJS) || $(NOARSCAN) || $(NOARUPDATE) ) {
500			RmTemps $(_l) : $(_s) ;
501		}
502	}
503}
504
505rule Main
506{
507	local target = $(1) ;
508	local sources = [ FGristFiles $(2) ] ;
509	local objects = $(sources:S=$(SUFOBJ)) ;
510
511	InheritPlatform $(objects) : $(target) ;
512	MainFromObjects $(target) : $(objects) ;
513	Objects $(sources) ;
514}
515
516rule MainFromObjects
517{
518	local _s _t ;
519
520	# Add grist to file names
521	# Add suffix to exe
522
523	_s = [ FGristFiles $(>) ] ;
524	_t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
525
526	# so 'jam foo' works when it's really foo.exe
527
528	if $(_t) != $(<)
529	{
530		Depends $(<) : $(_t) ;
531		NotFile $(<) ;
532	}
533
534	# make compiled sources a dependency of target
535
536	LocalDepends exe : $(_t) ;
537	Depends $(_t) : $(_s) ;
538	MakeLocateDebug $(_t) ;
539
540	LocalClean clean : $(_t) ;
541
542	Link $(_t) : $(_s) ;
543}
544
545# Override Jam 2.5rc3 MakeLocate and MkDir to deal more intelligently
546# with grist set on the supplied directory name. Also do nothing for already
547# located files.
548rule MakeLocate
549{
550	local dir = $(2[1]) ;
551
552	if $(dir) {
553		if ! $(dir:G) {
554			dir = $(dir:G=dir) ;
555		}
556
557		local target ;
558		for target in $(1) {
559			# don't relocate once located
560			LOCATE on $(target) += $(dir:G=) ;
561			if [ on $(target) return $(LOCATE) ] = $(dir:G=) {
562				Depends $(target) : $(dir) ;
563				MkDir $(dir) ;
564			}
565		}
566	}
567}
568
569# Overridden to use "-p", as Jam does not properly normalize
570# paths passed to NoUpdate, and so tries to make some directories
571# twice: once for the relative path, and once for the absolute path.
572actions MkDir1
573{
574	$(MKDIR) -p "$(<)"
575}
576
577rule MkDir
578{
579	local dir = $(<) ;
580	if ! $(dir:G) {
581		dir = $(dir:G=dir) ;
582	}
583
584	# make this and all super directories
585	while true {
586		# If dir exists, don't update it
587		# Do this even for $(DOT).
588		NoUpdate $(dir) ;
589
590		# Bail out when reaching the CWD (".") or a directory we've already
591		# made.
592		if $(dir:G=) = $(DOT) || $($(dir:G=)-mkdir) {
593			return ;
594		}
595
596		local s ;
597
598		# Cheesy gate to prevent multiple invocations on same dir
599		# MkDir1 has the actions
600		# Arrange for jam dirs
601
602		$(dir:G=)-mkdir = true ;
603		MkDir1 $(dir) ;
604		LocalDepends dirs : $(dir) ;
605
606		# Recursively make parent directories.
607		# $(dir:P) = $(dir)'s parent, & we recurse until root
608
609		s = $(dir:P) ;	# parent keeps grist
610
611		if $(s:G=) && $(s) != $(dir) {
612			Depends $(dir) : $(s) ;
613			dir = $(s) ;
614		} else if $(s) {
615			NotFile $(s) ;
616			break ;
617		}
618	}
619}
620
621rule ObjectCcFlags
622{
623	# supports inheriting the global variable value
624
625	local file ;
626	for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] {
627		CCFLAGS on $(file) = [ on $(file) return $(CCFLAGS) ] $(2) ;
628	}
629}
630
631rule ObjectC++Flags
632{
633	# supports inheriting the global variable value
634
635	local file ;
636	for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] {
637		C++FLAGS on $(file) = [ on $(file) return $(C++FLAGS) ] $(2) ;
638	}
639}
640
641rule ObjectDefines
642{
643	# supports inheriting the global variable value and multiple files
644
645	if $(2) {
646		local file ;
647		for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] {
648			DEFINES on $(file) = [ on $(file) return $(DEFINES) ] $(2) ;
649			CCDEFS on $(file) = [ on $(file) FDefines $(DEFINES) ] ;
650		}
651	}
652}
653
654rule ObjectHdrs
655{
656	# ObjectHdrs <sources or objects> : <headers> : <gristed objects>
657	# Note: Parameter 3 <gristed objects> is an extension.
658
659	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] $(3) ;
660	local headers = $(2) ;
661
662	local file ;
663	for file in $(objects) {
664		on $(file) {
665			local localHeaders = $(HDRS) $(headers) ;
666			SYSHDRS on $(file) = $(localHeaders) ;
667
668			# reformat ASHDRS and CCHDRS
669			local fileHeaders ;
670
671			if $(PLATFORM) = host {
672				fileHeaders =
673					[ FIncludes $(localHeaders) : $(HOST_LOCAL_INCLUDES_OPTION) ]
674					$(HOST_INCLUDES_SEPARATOR)
675					[ FSysIncludes $(SYSHDRS)
676						: $(HOST_SYSTEM_INCLUDES_OPTION) ] ;
677			} else {
678				local architecture = $(TARGET_PACKAGING_ARCH) ;
679				fileHeaders =
680					[ FIncludes $(localHeaders)
681						: $(TARGET_LOCAL_INCLUDES_OPTION_$(architecture)) ]
682					$(TARGET_INCLUDES_SEPARATOR_$(architecture))
683					[ FSysIncludes $(SYSHDRS)
684						: $(TARGET_SYSTEM_INCLUDES_OPTION_$(architecture)) ] ;
685			}
686
687			ASHDRS on $(file) = $(fileHeaders) ;
688			CCHDRS on $(file) = $(fileHeaders) ;
689		}
690	}
691}
692
693# Overridden to avoid calling SubDir for a directory twice (in SubInclude
694# and from the Jamfile in the directory).
695rule SubInclude
696{
697	# SubInclude TOP d1 ... ;
698	#
699	# Include a subdirectory's Jamfile.
700
701	if ! $($(<[1]))
702	{
703		Exit SubInclude $(<[1]) without prior SubDir $(<[1]) ;
704	}
705
706	# Set up the config variables for the subdirectory.
707	local config = [ ConfigObject $(1) ] ;
708
709	__configured = ;
710	if ! [ on $(config) return $(__configured) ] {
711		# No custom configuration defined for the subdir. We use the variable
712		# values inherited by the closest ancestor.
713		config = $(HAIKU_INHERITED_SUBDIR_CONFIG) ;
714	}
715
716	# store SUBDIR_TOKENS
717	local oldSubDirTokens = $(SUBDIR_TOKENS) ;
718
719	on $(config) {
720		include [ FDirName $($(1[1])) $(1[2-) $(JAMFILE) ] ;
721	}
722
723	# restore SUBDIR_TOKENS
724	SUBDIR_TOKENS = $(oldSubDirTokens) ;
725}
726