xref: /haiku/build/jam/MainBuildRules (revision 98057dd02a2411868fd4c35f7a48d20acfd92c23)
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 = libroot.so ;
13			local beginGlue ;
14			local endGlue ;
15			if $(2) = true {
16				beginGlue += $(HAIKU_EXECUTABLE_BEGIN_GLUE_CODE) ;
17				endGlue += $(HAIKU_EXECUTABLE_END_GLUE_CODE) ;
18			} else {
19				beginGlue += $(HAIKU_LIBRARY_BEGIN_GLUE_CODE) ;
20				endGlue += $(HAIKU_LIBRARY_END_GLUE_CODE) ;
21
22				# special case for libroot: don't link it against itself
23				if $(DONT_LINK_AGAINST_LIBROOT) {
24					stdLibs = ;
25				}
26			}
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 = -nostart $(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 Ld
185{
186	# Ld <name> : <objs> : <linkerscript> : <flags> ;
187	#
188	local target = $(1) ;
189	local objects = $(2) ;
190	local linkerScript = $(3) ;
191	local linkerFlags = $(4) ;
192
193	if $(linkerScript) {
194		linkerFlags += --script=$(linkerScript) ;
195	}
196
197	on $(target) {
198		if $(PLATFORM) = host {
199			LINK on $(target) = $(HOST_LD) ;
200			LINKFLAGS on $(target) = $(HOST_LDFLAGS) $(LINKFLAGS) $(linkerFlags) ;
201		} else {
202			LINK on $(target) = $(TARGET_LD) ;
203			LINKFLAGS on $(target) = $(TARGET_LDFLAGS) $(LINKFLAGS)
204				$(linkerFlags) ;
205		}
206
207		NEEDLIBS on $(target) = $(NEEDLIBS) ;
208		LINKLIBS on $(target) = $(LINKLIBS) ;
209	}
210
211	LocalClean clean : $(target) ;
212	LocalDepends all : $(target) ;
213	Depends $(target) : $(objects) ;
214
215	MakeLocateDebug $(target) ;
216
217	on $(1) XRes $(1) : $(RESFILES) ;
218	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
219		SetType $(1) ;
220		MimeSet $(1) ;
221		SetVersion $(1) ;
222	}
223}
224
225actions Ld
226{
227	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS)
228}
229
230rule CreateAsmStructOffsetsHeader header : source
231{
232	# CreateAsmStructOffsetsHeader header : source
233	#
234	# Grist will be added to both header and source.
235
236	header = [ FGristFiles $(header) ] ;
237	source = [ FGristFiles $(source) ] ;
238
239	# find out which headers, defines, etc. to use
240	local headers ;
241	local sysHeaders ;
242	local defines ;
243	local flags ;
244	local includesSeparator ;
245	local localIncludesOption ;
246	local systemIncludesOption ;
247
248	on $(header) { # use on $(1) variable values
249		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
250			return ;
251		}
252
253		# headers and defines
254		headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS)
255			$(HDRS) ;
256		sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ;
257		defines = $(DEFINES) ;
258
259		if $(PLATFORM) = host {
260			sysHeaders += $(HOST_HDRS) ;
261			defines += $(HOST_DEFINES) ;
262
263			if $(USES_BE_API) {
264				sysHeaders += $(HOST_BE_API_HEADERS) ;
265			}
266
267		} else {
268			sysHeaders += $(TARGET_HDRS) ;
269			defines += $(TARGET_DEFINES) ;
270		}
271
272		# optimization flags
273		if $(DEBUG) = 0 {
274			flags += $(OPTIM) ;
275		} else {
276			flags += -O0 ;
277		}
278
279		if $(PLATFORM) = host {
280			# warning flags
281			if $(WARNINGS) != 0 {
282				flags += $(HOST_WARNING_C++FLAGS) ;
283			}
284
285			# debug and other flags
286			flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS)
287				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
288
289			if $(USES_BE_API) {
290				flags += $(HOST_BE_API_C++FLAGS) ;
291			}
292
293			C++ on $(header) = $(HOST_C++) ;
294
295			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
296			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
297			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
298
299		} else {
300			# warning flags
301			if $(WARNINGS) != 0 {
302				flags += $(TARGET_WARNING_C++FLAGS) ;
303			}
304
305			# debug and other flags
306			flags += $(TARGET_C++FLAGS) $(TARGET_DEBUG_$(DEBUG)_C++FLAGS)
307				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
308
309			C++ on $(header) = $(TARGET_C++) ;
310
311			includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ;
312			localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ;
313			systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ;
314		}
315	}
316
317	# Turn off "invalid use of offsetof()" macro warning. We use offsetof() also
318	# for non-PODs. Since we're using the same compiler for the whole kernel and
319	# don't do virtual inheritence, that works well enough.
320	flags += -Wno-invalid-offsetof ;
321
322	# locate object, search for source, and set on target variables
323
324	Depends $(header) : $(source) ;
325	SEARCH on $(source) += $(SEARCH_SOURCE) ;
326	MakeLocateArch $(header) ;
327	LocalClean clean : $(header) ;
328
329	HDRRULE on $(source) = HdrRule ;
330	HDRSCAN on $(source) = $(HDRPATTERN) ;
331	HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ;
332	HDRGRIST on $(source) = $(HDRGRIST) ;
333
334	C++FLAGS on $(header) = $(flags) ;
335	CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ]
336		$(includesSeparator)
337		[ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ;
338	CCDEFS on $(header) = [ FDefines $(defines) ] ;
339
340	CreateAsmStructOffsetsHeader1 $(header) : $(source) ;
341}
342
343actions CreateAsmStructOffsetsHeader1
344{
345 	$(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \
346		| grep "#define" | sed -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)"
347}
348
349rule MergeObjectFromObjects
350{
351	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
352	# Merges object files to an object file.
353	# <name>: Name of the object file to create. No grist will be added.
354	# <objects>: Object files to be merged. Grist will be added.
355	# <other objects>: Object files or static libraries to be merged. No grist
356	#                  will be added.
357	#
358	local objects = [ FGristFiles $(2) ] ;
359
360	on $(1) {
361		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
362			return ;
363		}
364
365		if $(PLATFORM) = host {
366			LINK on $(1) = $(HOST_LD) ;
367			LINKFLAGS on $(target) = $(HOST_LDFLAGS) ;
368		} else {
369			LINK on $(1) = $(TARGET_LD) ;
370			LINKFLAGS on $(target) = $(TARGET_LDFLAGS) ;
371		}
372	}
373
374	MakeLocateDebug $(1) ;
375	Depends $(1) : $(objects) ;
376	Depends $(1) : $(3) ;
377	LocalDepends obj : $(1) ;
378	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
379}
380
381actions MergeObjectFromObjects1
382{
383	$(LINK) $(LINKFLAGS) -r $(2) -o $(1) ;
384}
385
386rule MergeObject
387{
388	# MergeObject <name> : <sources> : <other objects> ;
389	# Compiles source files and merges the object files to an object file.
390	# <name>: Name of the object file to create. No grist will be added.
391	# <sources>: Sources to be compiled. Grist will be added.
392	# <other objects>: Object files or static libraries to be merged. No grist
393	#                  will be added.
394	#
395	local target = $(1) ;
396	local sources = [ FGristFiles $(2) ] ;
397	local otherObjects = $(3) ;
398	local objects = $(sources:S=$(SUFOBJ)) ;
399
400	if ! [ IsPlatformSupportedForTarget $(1) ] {
401		return ;
402	}
403
404	InheritPlatform $(objects) : $(target) ;
405	Objects $(sources) ;
406	MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ;
407}
408
409rule SharedLibraryFromObjects
410{
411	# SharedLibraryFromObjects <lib> : <objects> : <libraries> ;
412	#
413	local _lib = $(1) ;
414
415	if ! [ IsPlatformSupportedForTarget $(1) ] {
416		return ;
417	}
418
419	local soname = [ on $(_lib) return $(HAIKU_SONAME) ] ;
420	soname ?= $(_lib:BS) ;
421
422	MainFromObjects $(_lib) : $(2) ;
423	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
424		-nostart -Xlinker -soname=\"$(soname)\" ;
425	LinkAgainst $(_lib) : $(3) ;
426
427	AddSharedObjectGlueCode $(_lib) : false ;
428}
429
430rule SharedLibrary
431{
432	# SharedLibrary <lib> : <sources> : <libraries> : <abiVersion> ;
433	local lib = $(1) ;
434	local sources = [ FGristFiles $(2) ] ;
435	local objects = $(sources:S=$(SUFOBJ)) ;
436	local libs = $(3) ;
437	local abiVersion = $(4) ;	# major ABI (soname) version for lib (if any)
438
439	if ! [ IsPlatformSupportedForTarget $(1) ] {
440		return ;
441	}
442
443	if $(abiVersion) {
444		HAIKU_SONAME on $(lib) = $(lib:BS).$(abiVersion) ;
445		HAIKU_LIB_ABI_VERSION on $(lib) = $(abiVersion) ;
446	}
447
448	InheritPlatform $(objects) : $(lib) ;
449	Objects $(sources) ;
450	SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ;
451}
452
453rule LinkAgainst
454{
455	# LinkAgainst <name> : <libs> [ : <mapLibs> ] ;
456	# Valid elements for <libs> are e.g. "be" or "libtranslation.so" or
457	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
458	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
459	# file will be bound!), otherwise it is prefixed "-l" and added to
460	# LINKLIBS. If you want to specify a target that isn't a library and
461	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
462	# grist; it will be stripped by this rule.
463	# <mapLibs> specifies whether the to translate library names (e.g. "be"
464	# to "libbe.so" in case of target platform "haiku"). Defaults to "true".
465	#
466	local target = $(1) ;
467	local libs = $(2) ;
468	local mapLibs = $(3:E=true) ;
469
470	on $(target) {
471		# map libraries, if desired and target platform is Haiku
472		if $(PLATFORM) != host && $(mapLibs) = true
473				&& $(TARGET_LIBRARY_NAME_MAP) {
474			local mappedLibs ;
475
476			for i in $(libs) {
477				local mapped = $($(TARGET_LIBRARY_NAME_MAP)_$(i)) ;
478				mapped ?= $(i) ;
479				mappedLibs += $(mapped) ;
480			}
481
482			libs = $(mappedLibs) ;
483		}
484
485		local linkLibs ;
486		local needLibs ;
487
488		for i in $(libs)
489		{
490			local isfile = ;
491			if $(i:D) || $(i:G) {
492				isfile = true ;
493				if $(i:G) = <nogrist> {
494					i = $(i:G=) ;
495				}
496			} else {
497				switch $(i:B)
498				{
499					# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
500					case _APP_ : isfile = true ;
501					case _KERNEL_ : isfile = true ;
502					case lib*	: isfile = true ;
503					case *	: isfile = ;
504				}
505				if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
506					isfile = true ;
507				}
508			}
509
510			if $(isfile) {
511				needLibs += $(i) ;
512			} else {
513				linkLibs += $(i) ;
514			}
515		}
516
517		NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ;
518		LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ;
519
520		if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) {
521			Depends $(1) : $(needLibs) ;
522		}
523	}
524}
525
526rule AddResources
527{
528	# AddResources <name> : <resourcefiles> ;
529
530	# add grist to the resource files which don't have any yet
531	local resfiles ;
532	local file ;
533	for file in $(2) {
534		if ! $(file:G) {
535			file = [ FGristFiles $(file) ] ;
536		}
537		resfiles += $(file) ;
538	}
539
540	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
541
542	for file in $(resfiles) {
543		if $(file:S) = .rdef {
544			local rdef = $(file) ;
545			file = $(rdef:S=.rsrc) ;
546			ResComp $(file) : $(rdef) ;
547		}
548		InheritPlatform $(file) : $(1) ;
549		RESFILES on $(1) += $(file) ;
550	}
551}
552
553rule SetVersionScript target : versionScript
554{
555	# SetVersionScript <target> : <versionScript>
556	#
557	# Sets the version script for <target>. Grist will be added to
558	# <versionScript> and SEARCH will be set on it.
559
560	versionScript = [ FGristFiles $(versionScript) ] ;
561
562	SEARCH on $(versionScript) += $(SEARCH_SOURCE) ;
563
564	VERSION_SCRIPT on $(target) = $(versionScript) ;
565	Depends $(target) : $(versionScript) ;
566}
567
568rule BuildPlatformObjects
569{
570	# Usage BuildPlatformObjects <sources> ;
571	# <sources> The sources.
572	#
573	local sources = [ FGristFiles $(1) ] ;
574	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
575
576	PLATFORM on $(objects) = host ;
577	SUPPORTED_PLATFORMS on $(objects) = host ;
578
579	Objects $(sources) ;
580}
581
582actions CygwinExtensionFix
583{
584	if test -f $(1).exe ; then
585		rm -f $(1)
586		mv $(1).exe $(1)
587	fi
588}
589
590rule BuildPlatformMain
591{
592	# Usage BuildPlatformMain <target> : <sources> : <libraries> ;
593	# <target> The executable/library.
594	# <sources> The sources.
595	# <libraries> Libraries to link against.
596	#
597	local target = $(1) ;
598	local sources = $(2) ;
599	local libs = $(3) ;
600	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
601
602	PLATFORM on $(target) = host ;
603	SUPPORTED_PLATFORMS on $(target) = host ;
604	DONT_USE_BEOS_RULES on $(target) = true ;
605
606	local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ;
607	if $(usesBeAPI) {
608		# propagate the flag to the objects
609		USES_BE_API on $(objects) = $(usesBeAPI) ;
610
611		# add the build libroot
612		if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) {
613			local libroot = [ on $(target) return $(HOST_LIBROOT) ] ;
614			Depends $(target) : $(libroot) ;
615			NEEDLIBS on $(target) += $(libroot) ;
616		}
617	}
618
619	Main $(target) : $(sources) ;
620	LinkAgainst $(target) : $(libs) ;
621	if $(HOST_PLATFORM) = cygwin {
622		# Cygwin gcc adds the ".exe" extension. We cannot force
623		# jam to use SUFEXE as haiku target executables are not
624		# supposed to have this extension, thus finding
625		# dependencies will fail for these.
626		# The hack is to remove the extension after a successful
627		# build of the Target.
628		CygwinExtensionFix $(target) ;
629	}
630}
631
632rule BuildPlatformSharedLibrary
633{
634	# Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ;
635	# <target> The library.
636	# <sources> The sources.
637	# <libraries> Libraries to link against.
638	#
639	local target = $(1) ;
640	local sources = $(2) ;
641	local libs = $(3) ;
642
643	BuildPlatformMain $(target) : $(sources) : $(libs) ;
644
645	if $(HOST_PLATFORM) = darwin {
646		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
647			-dynamic -dynamiclib -Xlinker -flat_namespace ;
648	} else if $(HOST_PLATFORM) = cygwin {
649		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
650			-shared -Xlinker --allow-multiple-definition ;
651	} else {
652		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
653			-shared -Xlinker -soname=\"$(target:G=)\" ;
654	}
655
656    local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
657	CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ;
658	C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ;
659}
660
661rule BuildPlatformMergeObject
662{
663	# BuildPlatformMergeObject <name> : <sources> : <other objects> ;
664	# Compiles source files and merges the object files to an object file.
665	# <name>: Name of the object file to create. No grist will be added.
666	# <sources>: Sources to be compiled. Grist will be added.
667	# <other objects>: Object files or static libraries to be merged. No grist
668	#                  will be added.
669	#
670	local target = $(1) ;
671	local sources = $(2) ;
672	local otherObjects = $(3) ;
673	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
674
675	PLATFORM on $(target) = host ;
676	SUPPORTED_PLATFORMS on $(target) = host ;
677
678	local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ;
679	if $(usesBeAPI) {
680		# propagate the flag to the objects
681		USES_BE_API on $(objects) = $(usesBeAPI) ;
682	}
683
684	MergeObject $(target) : $(sources) : $(otherObjects) ;
685}
686
687rule BuildPlatformMergeObjectPIC target : sources : otherObjects
688{
689	# BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ;
690	# Compiles source files and merges the object files to an object file.
691	# Same as BuildPlatformMergeObject rule but adds position-independent
692	# flags to the compiler (if any).
693	# <name>: Name of the object file to create. No grist will be added.
694	# <sources>: Sources to be compiled. Grist will be added.
695	# <other objects>: Object files or static libraries to be merged. No grist
696	#                  will be added.
697	#
698	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
699	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
700
701	BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ;
702}
703
704rule BuildPlatformStaticLibrary lib : sources : otherObjects
705{
706	# BuildPlatformStaticLibrary <lib> : <sources> ;
707	# Creates a static library from sources.
708	# <lib>: The static library to be built.
709	# <sources>: List of source files.
710	# <otherObjects>: List of additional object files.
711	#
712
713	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
714
715	PLATFORM on $(lib) = host ;
716	SUPPORTED_PLATFORMS on $(lib) = host ;
717
718	local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ;
719	if $(usesBeAPI) {
720		# propagate the flag to the objects
721		USES_BE_API on $(objects) = $(usesBeAPI) ;
722	}
723
724	StaticLibrary $(lib) : $(sources) : $(otherObjects) ;
725}
726
727rule BuildPlatformStaticLibraryPIC target : sources : otherObjects
728{
729	# Like BuildPlatformStaticLibrary, but producing position independent code.
730
731	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
732	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
733
734	BuildPlatformStaticLibrary $(target) : $(sources) : $(otherObjects) ;
735}
736