xref: /haiku/build/jam/MainBuildRules (revision f8da8f3477d3c18142e59d17d05a545982faa5a8)
1
2rule AddSharedObjectGlueCode
3{
4	# AddSharedObjectGlueCode <target> : <isExecutable> ;
5
6	# we link with -nostdlib and add the required libs manually, when building
7	# for Haiku
8	local platform ;
9	on $(1) {
10		platform = $(PLATFORM) ;
11		if $(platform) = haiku {
12			local stdLibs = [ MultiArchDefaultGristFiles libroot.so ] ;
13			local type = EXECUTABLE ;
14			if $(2) != true {
15				type = LIBRARY ;
16
17				# special case for libroot: don't link it against itself
18				if $(DONT_LINK_AGAINST_LIBROOT) {
19					stdLibs = ;
20				}
21			}
22
23			local beginGlue
24				= $(HAIKU_$(type)_BEGIN_GLUE_CODE_$(TARGET_PACKAGING_ARCH)) ;
25			local endGlue
26				= $(HAIKU_$(type)_END_GLUE_CODE_$(TARGET_PACKAGING_ARCH)) ;
27
28			LINK_BEGIN_GLUE on $(1) = $(beginGlue) ;
29			LINK_END_GLUE on $(1) = $(endGlue) ;
30
31			NEEDLIBS on $(1) =  [ on $(1) return $(NEEDLIBS) ] $(stdLibs) ;
32			Depends $(1) : $(stdLibs) $(beginGlue) $(endGlue) ;
33			LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib
34				-Xlinker --no-undefined ;
35		}
36	}
37
38	# link against the compatibility libraries needed for the target
39	if $(platform) != host && $(TARGET_HAIKU_COMPATIBILITY_LIBS) {
40		LinkAgainst $(1) : $(TARGET_HAIKU_COMPATIBILITY_LIBS) ;
41	}
42}
43
44rule Executable
45{
46	# Executable <name> : <sources> : <libraries> : <res> ;
47	#
48	if ! [ IsPlatformSupportedForTarget $(1) ] {
49		return ;
50	}
51
52	AddResources $(1) : $(4) ;
53	Main $(1) : $(2) ;
54	LinkAgainst $(1) : $(3) ;
55	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
56		-Xlinker -soname=_APP_  ;
57
58	# we link with -nostdlib and add the required libs manually, when building
59	# for Haiku
60	AddSharedObjectGlueCode $(1) : true ;
61}
62
63rule Application
64{
65	# Application <name> : <sources> : <libraries> : <res> ;
66	Executable $(1) : $(2) : $(3) : $(4) ;
67}
68
69rule BinCommand
70{
71	# BinCommand <name> : <sources> : <libraries> : <res> ;
72	Executable $(1) : $(2) : $(3) : $(4) ;
73}
74
75rule StdBinCommands
76{
77	# StdBinCommands <sources> : <libs> : <res> ;
78	local libs = $(2) ;
79	local ress = $(3) ;
80	local source ;
81	for source in $(1)
82	{
83		local target = $(source:S=) ;
84
85		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
86	}
87}
88
89rule Preference
90{
91	# Preference <name> : <sources> : <libraries> : <res> ;
92	Executable $(1) : $(2) : $(3) : $(4) ;
93}
94
95rule Server
96{
97	# Server <name> : <sources> : <libraries> : <res> ;
98
99	Executable $(1) : $(2) : $(3) : $(4) ;
100}
101
102rule Addon target : sources : libraries : isExecutable
103{
104	# Addon <target> : <sources> : <is executable> : <libraries> ;
105	# <target>: The add-on.
106	# <sources>: Source files.
107	# <libraries>: Libraries to be linked against.
108	# <isExecutable>: true, if the target shall be executable as well.
109
110	if ! [ IsPlatformSupportedForTarget $(target) ] {
111		return ;
112	}
113
114	Main $(target) : $(sources) ;
115
116	local linkFlags = -Xlinker -soname=\"$(target:G=)\" ;
117	if $(isExecutable) != true {
118		linkFlags = -shared $(linkFlags) ;
119	}
120	LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ;
121	LinkAgainst $(target) : $(libraries) ;
122
123	AddSharedObjectGlueCode $(target) : $(isExecutable) ;
124}
125
126rule Translator target : sources : libraries : isExecutable
127{
128	# Translator <target> : <sources> : <libraries> : <isExecutable> ;
129	Addon $(target) : $(sources) : $(libraries) : $(isExecutable) ;
130}
131
132rule ScreenSaver target : sources : libraries
133{
134	# ScreenSaver <target> : <sources> : <libraries> ;
135	Addon $(target) : $(sources) : $(libraries) : false ;
136}
137
138rule StaticLibrary
139{
140	# StaticLibrary <lib> : <sources> : <otherObjects> ;
141	# Creates a static library from sources.
142	# <lib>: The static library to be built.
143	# <sources>: List of source files.
144	# <otherObjects>: List of additional object files.
145	#
146	local lib = $(1) ;
147	local sources = [ FGristFiles $(2) ] ;
148	local otherObjects = $(3) ;
149	local objects = $(sources:S=$(SUFOBJ)) ;
150
151	if ! [ IsPlatformSupportedForTarget $(1) ] {
152		return ;
153	}
154
155	InheritPlatform $(objects) : $(lib) ;
156
157	StaticLibraryFromObjects $(lib) : $(objects) $(otherObjects) ;
158	Objects $(2) ;
159}
160
161rule StaticLibraryFromObjects
162{
163	if ! [ IsPlatformSupportedForTarget $(1) ] {
164		return ;
165	}
166
167	LibraryFromObjects $(1) : $(2) ;
168}
169
170rule AssembleNasm
171{
172	Depends $(<) : $(>) ;
173}
174
175actions AssembleNasm
176{
177	if test $(ASFLAGS) ; then
178		$(HAIKU_YASM) -d $(ASFLAGS) -f elf32 -o $(1) $(2);
179	else
180		$(HAIKU_YASM) -f elf32 -o $(1) $(2);
181	fi
182}
183
184rule CompileDTS
185{
186	Depends $(<) : $(>) ;
187}
188
189actions CompileDTS
190{
191	dtc -O dtb -o $(1) $(2);
192}
193
194rule Ld
195{
196	# Ld <name> : <objs> : <linkerscript> : <flags> ;
197	#
198	local target = $(1) ;
199	local objects = $(2) ;
200	local linkerScript = $(3) ;
201	local linkerFlags = $(4) ;
202
203	if $(linkerScript) {
204		linkerFlags += --script=$(linkerScript) ;
205	}
206
207	on $(target) {
208		if $(PLATFORM) = host {
209			LINK on $(target) = $(HOST_LD) ;
210			LINKFLAGS on $(target) = $(HOST_LDFLAGS) $(LINKFLAGS) $(linkerFlags) ;
211		} else {
212			LINK on $(target) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
213			LINKFLAGS on $(target) = $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH))
214				$(LINKFLAGS) $(linkerFlags) ;
215		}
216
217		NEEDLIBS on $(target) = $(NEEDLIBS) ;
218		LINKLIBS on $(target) = $(LINKLIBS) ;
219	}
220
221	LocalClean clean : $(target) ;
222	LocalDepends all : $(target) ;
223	Depends $(target) : $(objects) ;
224
225	MakeLocateDebug $(target) ;
226
227	on $(1) XRes $(1) : $(RESFILES) ;
228	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
229		SetType $(1) ;
230		MimeSet $(1) ;
231		SetVersion $(1) ;
232	}
233}
234
235actions Ld
236{
237	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS)
238}
239
240rule CreateAsmStructOffsetsHeader header : source
241{
242	# CreateAsmStructOffsetsHeader header : source
243	#
244	# Grist will be added to both header and source.
245
246	header = [ FGristFiles $(header) ] ;
247	source = [ FGristFiles $(source) ] ;
248
249	# find out which headers, defines, etc. to use
250	local headers ;
251	local sysHeaders ;
252	local defines ;
253	local flags ;
254	local includesSeparator ;
255	local localIncludesOption ;
256	local systemIncludesOption ;
257
258	on $(header) { # use on $(1) variable values
259		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
260			return ;
261		}
262
263		# headers and defines
264		headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS)
265			$(HDRS) ;
266		sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ;
267		defines = $(DEFINES) ;
268
269		if $(PLATFORM) = host {
270			sysHeaders += $(HOST_HDRS) ;
271			defines += $(HOST_DEFINES) ;
272
273			if $(USES_BE_API) {
274				sysHeaders += $(HOST_BE_API_HEADERS) ;
275			}
276
277		} else {
278			sysHeaders += $(TARGET_HDRS_$(TARGET_PACKAGING_ARCH)) ;
279			defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH))
280				$(TARGET_DEFINES) ;
281		}
282
283		# optimization flags
284		if $(DEBUG) = 0 {
285			flags += $(OPTIM) ;
286		} else {
287			flags += -O0 ;
288		}
289
290		if $(PLATFORM) = host {
291			# warning flags
292			if $(WARNINGS) != 0 {
293				flags += $(HOST_WARNING_C++FLAGS) ;
294				if $(WARNINGS) = treatAsErrors {
295					flags += -Werror $(HOST_WERROR_FLAGS) ;
296				}
297			}
298
299			# debug and other flags
300			flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS)
301				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
302
303			if $(USES_BE_API) {
304				flags += $(HOST_BE_API_C++FLAGS) ;
305			}
306
307			C++ on $(header) = $(HOST_C++) ;
308
309			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
310			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
311			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
312
313		} else {
314			# warning flags
315			if $(WARNINGS) != 0 {
316				flags += $(TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)) ;
317				if $(WARNINGS) = treatAsErrors {
318					flags += -Werror
319						$(TARGET_WERROR_FLAGS_$(TARGET_PACKAGING_ARCH)) ;
320				}
321			}
322
323			# debug and other flags
324			flags += $(TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH))
325				$(TARGET_DEBUG_$(DEBUG)_C++FLAGS_$(TARGET_PACKAGING_ARCH))
326				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
327
328			C++ on $(header) = $(TARGET_C++_$(TARGET_PACKAGING_ARCH)) ;
329
330			includesSeparator
331				= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
332			localIncludesOption
333				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
334			systemIncludesOption
335				= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
336		}
337	}
338
339	# Turn off "invalid use of offsetof()" macro warning. We use offsetof() also
340	# for non-PODs. Since we're using the same compiler for the whole kernel and
341	# don't do virtual inheritence, that works well enough.
342	flags += -Wno-invalid-offsetof ;
343		# TODO: Rather get rid of the respective offsetof() instances.
344
345	# locate object, search for source, and set on target variables
346
347	Depends $(header) : $(source) ;
348	SEARCH on $(source) += $(SEARCH_SOURCE) ;
349	MakeLocateArch $(header) ;
350	LocalClean clean : $(header) ;
351
352	HDRRULE on $(source) = HdrRule ;
353	HDRSCAN on $(source) = $(HDRPATTERN) ;
354	HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ;
355	HDRGRIST on $(source) = $(HDRGRIST) ;
356
357	C++FLAGS on $(header) = $(flags) ;
358	CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ]
359		$(includesSeparator)
360		[ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ;
361	CCDEFS on $(header) = [ FDefines $(defines) ] ;
362
363	CreateAsmStructOffsetsHeader1 $(header) : $(source) ;
364}
365
366actions CreateAsmStructOffsetsHeader1
367{
368 	$(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \
369		| grep "#define" | sed -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)"
370}
371
372rule MergeObjectFromObjects
373{
374	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
375	# Merges object files to an object file.
376	# <name>: Name of the object file to create. No grist will be added.
377	# <objects>: Object files to be merged. Grist will be added.
378	# <other objects>: Object files or static libraries to be merged. No grist
379	#                  will be added.
380	#
381	local objects = [ FGristFiles $(2) ] ;
382
383	on $(1) {
384		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
385			return ;
386		}
387
388		if $(PLATFORM) = host {
389			LINK on $(1) = $(HOST_LD) ;
390			LINKFLAGS on $(target) = $(HOST_LDFLAGS) ;
391		} else {
392			LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
393			LINKFLAGS on $(target)
394				= $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) ;
395		}
396	}
397
398	MakeLocateDebug $(1) ;
399	Depends $(1) : $(objects) ;
400	Depends $(1) : $(3) ;
401	LocalDepends obj : $(1) ;
402	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
403}
404
405actions MergeObjectFromObjects1
406{
407	$(LINK) $(LINKFLAGS) -r $(2) -o $(1) ;
408}
409
410rule MergeObject
411{
412	# MergeObject <name> : <sources> : <other objects> ;
413	# Compiles source files and merges the object files to an object file.
414	# <name>: Name of the object file to create. No grist will be added.
415	# <sources>: Sources to be compiled. Grist will be added.
416	# <other objects>: Object files or static libraries to be merged. No grist
417	#                  will be added.
418	#
419	local target = $(1) ;
420	local sources = [ FGristFiles $(2) ] ;
421	local otherObjects = $(3) ;
422	local objects = $(sources:S=$(SUFOBJ)) ;
423
424	if ! [ IsPlatformSupportedForTarget $(1) ] {
425		return ;
426	}
427
428	InheritPlatform $(objects) : $(target) ;
429	Objects $(sources) ;
430	MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ;
431}
432
433rule SharedLibraryFromObjects
434{
435	# SharedLibraryFromObjects <lib> : <objects> : <libraries> ;
436	#
437	local _lib = $(1) ;
438
439	if ! [ IsPlatformSupportedForTarget $(1) ] {
440		return ;
441	}
442
443	local soname = [ on $(_lib) return $(HAIKU_SONAME) ] ;
444	soname ?= $(_lib:BS) ;
445
446	MainFromObjects $(_lib) : $(2) ;
447	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
448		-shared -Xlinker -soname=\"$(soname)\" ;
449	LinkAgainst $(_lib) : $(3) ;
450
451	AddSharedObjectGlueCode $(_lib) : false ;
452}
453
454rule SharedLibrary
455{
456	# SharedLibrary <lib> : <sources> : <libraries> : <abiVersion> ;
457	local lib = $(1) ;
458	local sources = [ FGristFiles $(2) ] ;
459	local objects = $(sources:S=$(SUFOBJ)) ;
460	local libs = $(3) ;
461	local abiVersion = $(4) ;	# major ABI (soname) version for lib (if any)
462
463	if ! [ IsPlatformSupportedForTarget $(1) ] {
464		return ;
465	}
466
467	if $(abiVersion) {
468		HAIKU_SONAME on $(lib) = $(lib:BS).$(abiVersion) ;
469		HAIKU_LIB_ABI_VERSION on $(lib) = $(abiVersion) ;
470	}
471
472	InheritPlatform $(objects) : $(lib) ;
473	Objects $(sources) ;
474	SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ;
475}
476
477rule LinkAgainst
478{
479	# LinkAgainst <name> : <libs> [ : <mapLibs> ] ;
480	# Valid elements for <libs> are e.g. "be" or "libtranslation.so" or
481	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
482	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
483	# file will be bound!), otherwise it is prefixed "-l" and added to
484	# LINKLIBS. If you want to specify a target that isn't a library and
485	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
486	# grist; it will be stripped by this rule.
487	# <mapLibs> specifies whether the to translate library names (e.g. "be"
488	# to "libbe.so" in case of target platform "haiku"). Defaults to "true".
489	#
490	local target = $(1) ;
491	local libs = $(2) ;
492	local mapLibs = $(3:E=true) ;
493
494	on $(target) {
495		# map libraries, if desired and target platform is Haiku
496		local map = $(TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH)) ;
497		if $(PLATFORM) != host && $(mapLibs) = true && $(map) {
498			local mappedLibs ;
499
500			for i in $(libs) {
501				local mapped = $($(map)_$(i)) ;
502				mapped ?= $(i) ;
503				mappedLibs += $(mapped) ;
504			}
505
506			libs = $(mappedLibs) ;
507		}
508
509		local linkLibs ;
510		local needLibs ;
511
512		for i in $(libs)
513		{
514			local isfile = ;
515			if $(i:D) || $(i:G) {
516				isfile = true ;
517				if $(i:G) = <nogrist> {
518					i = $(i:G=) ;
519				}
520			} else {
521				switch $(i:B)
522				{
523					# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
524					case _APP_ : isfile = true ;
525					case _KERNEL_ : isfile = true ;
526					case lib*	: isfile = true ;
527					case *	: isfile = ;
528				}
529				if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
530					isfile = true ;
531				}
532			}
533
534			if $(isfile) {
535				needLibs += $(i) ;
536			} else {
537				linkLibs += $(i) ;
538			}
539		}
540
541		NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ;
542		LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ;
543
544		if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) {
545			Depends $(1) : $(needLibs) ;
546		}
547	}
548}
549
550rule AddResources
551{
552	# AddResources <name> : <resourcefiles> ;
553
554	# add grist to the resource files which don't have any yet
555	local resfiles ;
556	local file ;
557	for file in $(2) {
558		if ! $(file:G) {
559			file = [ FGristFiles $(file) ] ;
560		}
561		resfiles += $(file) ;
562	}
563
564	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
565
566	for file in $(resfiles) {
567		if $(file:S) = .rdef {
568			local rdef = $(file) ;
569			file = $(rdef:S=.rsrc) ;
570			ResComp $(file) : $(rdef) ;
571		}
572		InheritPlatform $(file) : $(1) ;
573		RESFILES on $(1) += $(file) ;
574	}
575}
576
577rule SetVersionScript target : versionScript
578{
579	# SetVersionScript <target> : <versionScript>
580	#
581	# Sets the version script for <target>. Grist will be added to
582	# <versionScript> and SEARCH will be set on it.
583
584	versionScript = [ FGristFiles $(versionScript) ] ;
585
586	SEARCH on $(versionScript) += $(SEARCH_SOURCE) ;
587
588	VERSION_SCRIPT on $(target) = $(versionScript) ;
589	Depends $(target) : $(versionScript) ;
590}
591
592rule BuildPlatformObjects
593{
594	# Usage BuildPlatformObjects <sources> ;
595	# <sources> The sources.
596	#
597	local sources = [ FGristFiles $(1) ] ;
598	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
599
600	PLATFORM on $(objects) = host ;
601	SUPPORTED_PLATFORMS on $(objects) = host ;
602
603	Objects $(sources) ;
604}
605
606actions CygwinExtensionFix
607{
608	if test -f $(1).exe ; then
609		rm -f $(1)
610		mv $(1).exe $(1)
611	fi
612}
613
614rule BuildPlatformMain
615{
616	# Usage BuildPlatformMain <target> : <sources> : <libraries> ;
617	# <target> The executable/library.
618	# <sources> The sources.
619	# <libraries> Libraries to link against.
620	#
621	local target = $(1) ;
622	local sources = $(2) ;
623	local libs = $(3) ;
624	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
625
626	PLATFORM on $(target) = host ;
627	SUPPORTED_PLATFORMS on $(target) = host ;
628	DONT_USE_BEOS_RULES on $(target) = true ;
629
630	local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ;
631	if $(usesBeAPI) {
632		# propagate the flag to the objects
633		USES_BE_API on $(objects) = $(usesBeAPI) ;
634
635		# add the build libroot
636		if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) {
637			local libroot = [ on $(target) return $(HOST_LIBROOT) ] ;
638			Depends $(target) : $(libroot) ;
639			NEEDLIBS on $(target) += $(libroot) ;
640		}
641	}
642
643	Main $(target) : $(sources) ;
644	LinkAgainst $(target) : $(libs) ;
645	if $(HOST_PLATFORM) = cygwin {
646		# Cygwin gcc adds the ".exe" extension. We cannot force
647		# jam to use SUFEXE as haiku target executables are not
648		# supposed to have this extension, thus finding
649		# dependencies will fail for these.
650		# The hack is to remove the extension after a successful
651		# build of the Target.
652		CygwinExtensionFix $(target) ;
653	}
654}
655
656rule BuildPlatformSharedLibrary
657{
658	# Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ;
659	# <target> The library.
660	# <sources> The sources.
661	# <libraries> Libraries to link against.
662	#
663	local target = $(1) ;
664	local sources = $(2) ;
665	local libs = $(3) ;
666
667	BuildPlatformMain $(target) : $(sources) : $(libs) ;
668
669	if $(HOST_PLATFORM) = darwin {
670		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
671			-dynamic -dynamiclib -Xlinker -flat_namespace ;
672	} else if $(HOST_PLATFORM) = cygwin {
673		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
674			-shared -Xlinker --allow-multiple-definition ;
675	} else {
676		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
677			-shared -Xlinker -soname=\"$(target:G=)\" ;
678	}
679
680    local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
681	CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ;
682	C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ;
683}
684
685rule BuildPlatformMergeObject
686{
687	# BuildPlatformMergeObject <name> : <sources> : <other objects> ;
688	# Compiles source files and merges the object files to an object file.
689	# <name>: Name of the object file to create. No grist will be added.
690	# <sources>: Sources to be compiled. Grist will be added.
691	# <other objects>: Object files or static libraries to be merged. No grist
692	#                  will be added.
693	#
694	local target = $(1) ;
695	local sources = $(2) ;
696	local otherObjects = $(3) ;
697	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
698
699	PLATFORM on $(target) = host ;
700	SUPPORTED_PLATFORMS on $(target) = host ;
701
702	local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ;
703	if $(usesBeAPI) {
704		# propagate the flag to the objects
705		USES_BE_API on $(objects) = $(usesBeAPI) ;
706	}
707
708	MergeObject $(target) : $(sources) : $(otherObjects) ;
709}
710
711rule BuildPlatformMergeObjectPIC target : sources : otherObjects
712{
713	# BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ;
714	# Compiles source files and merges the object files to an object file.
715	# Same as BuildPlatformMergeObject rule but adds position-independent
716	# flags to the compiler (if any).
717	# <name>: Name of the object file to create. No grist will be added.
718	# <sources>: Sources to be compiled. Grist will be added.
719	# <other objects>: Object files or static libraries to be merged. No grist
720	#                  will be added.
721	#
722	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
723	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
724
725	BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ;
726}
727
728rule BuildPlatformStaticLibrary lib : sources : otherObjects
729{
730	# BuildPlatformStaticLibrary <lib> : <sources> ;
731	# Creates a static library from sources.
732	# <lib>: The static library to be built.
733	# <sources>: List of source files.
734	# <otherObjects>: List of additional object files.
735	#
736
737	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
738
739	PLATFORM on $(lib) = host ;
740	SUPPORTED_PLATFORMS on $(lib) = host ;
741
742	local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ;
743	if $(usesBeAPI) {
744		# propagate the flag to the objects
745		USES_BE_API on $(objects) = $(usesBeAPI) ;
746	}
747
748	StaticLibrary $(lib) : $(sources) : $(otherObjects) ;
749}
750
751rule BuildPlatformStaticLibraryPIC target : sources : otherObjects
752{
753	# Like BuildPlatformStaticLibrary, but producing position independent code.
754
755	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
756	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
757
758	BuildPlatformStaticLibrary $(target) : $(sources) : $(otherObjects) ;
759}
760