xref: /haiku/build/jam/MainBuildRules (revision 4b7e219688450694efc9d1890f83f816758c16d3)
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			}
295
296			# debug and other flags
297			flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS)
298				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
299
300			if $(USES_BE_API) {
301				flags += $(HOST_BE_API_C++FLAGS) ;
302			}
303
304			C++ on $(header) = $(HOST_C++) ;
305
306			includesSeparator = $(HOST_INCLUDES_SEPARATOR) ;
307			localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ;
308			systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ;
309
310		} else {
311			# warning flags
312			if $(WARNINGS) != 0 {
313				flags += $(TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)) ;
314			}
315
316			# debug and other flags
317			flags += $(TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH))
318				$(TARGET_DEBUG_$(DEBUG)_C++FLAGS_$(TARGET_PACKAGING_ARCH))
319				$(SUBDIRC++FLAGS) $(C++FLAGS) ;
320
321			C++ on $(header) = $(TARGET_C++_$(TARGET_PACKAGING_ARCH)) ;
322
323			includesSeparator
324				= $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ;
325			localIncludesOption
326				= $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
327			systemIncludesOption
328				= $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ;
329		}
330	}
331
332	# Turn off "invalid use of offsetof()" macro warning. We use offsetof() also
333	# for non-PODs. Since we're using the same compiler for the whole kernel and
334	# don't do virtual inheritence, that works well enough.
335	flags += -Wno-invalid-offsetof ;
336		# TODO: Rather get rid of the respective offsetof() instances.
337
338	# locate object, search for source, and set on target variables
339
340	Depends $(header) : $(source) ;
341	SEARCH on $(source) += $(SEARCH_SOURCE) ;
342	MakeLocateArch $(header) ;
343	LocalClean clean : $(header) ;
344
345	HDRRULE on $(source) = HdrRule ;
346	HDRSCAN on $(source) = $(HDRPATTERN) ;
347	HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ;
348	HDRGRIST on $(source) = $(HDRGRIST) ;
349
350	C++FLAGS on $(header) = $(flags) ;
351	CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ]
352		$(includesSeparator)
353		[ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ;
354	CCDEFS on $(header) = [ FDefines $(defines) ] ;
355
356	CreateAsmStructOffsetsHeader1 $(header) : $(source) ;
357}
358
359actions CreateAsmStructOffsetsHeader1
360{
361 	$(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \
362		| grep "#define" | sed -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)"
363}
364
365rule MergeObjectFromObjects
366{
367	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
368	# Merges object files to an object file.
369	# <name>: Name of the object file to create. No grist will be added.
370	# <objects>: Object files to be merged. Grist will be added.
371	# <other objects>: Object files or static libraries to be merged. No grist
372	#                  will be added.
373	#
374	local objects = [ FGristFiles $(2) ] ;
375
376	on $(1) {
377		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
378			return ;
379		}
380
381		if $(PLATFORM) = host {
382			LINK on $(1) = $(HOST_LD) ;
383			LINKFLAGS on $(target) = $(HOST_LDFLAGS) ;
384		} else {
385			LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
386			LINKFLAGS on $(target)
387				= $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) ;
388		}
389	}
390
391	MakeLocateDebug $(1) ;
392	Depends $(1) : $(objects) ;
393	Depends $(1) : $(3) ;
394	LocalDepends obj : $(1) ;
395	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
396}
397
398actions MergeObjectFromObjects1
399{
400	$(LINK) $(LINKFLAGS) -r $(2) -o $(1) ;
401}
402
403rule MergeObject
404{
405	# MergeObject <name> : <sources> : <other objects> ;
406	# Compiles source files and merges the object files to an object file.
407	# <name>: Name of the object file to create. No grist will be added.
408	# <sources>: Sources to be compiled. Grist will be added.
409	# <other objects>: Object files or static libraries to be merged. No grist
410	#                  will be added.
411	#
412	local target = $(1) ;
413	local sources = [ FGristFiles $(2) ] ;
414	local otherObjects = $(3) ;
415	local objects = $(sources:S=$(SUFOBJ)) ;
416
417	if ! [ IsPlatformSupportedForTarget $(1) ] {
418		return ;
419	}
420
421	InheritPlatform $(objects) : $(target) ;
422	Objects $(sources) ;
423	MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ;
424}
425
426rule SharedLibraryFromObjects
427{
428	# SharedLibraryFromObjects <lib> : <objects> : <libraries> ;
429	#
430	local _lib = $(1) ;
431
432	if ! [ IsPlatformSupportedForTarget $(1) ] {
433		return ;
434	}
435
436	local soname = [ on $(_lib) return $(HAIKU_SONAME) ] ;
437	soname ?= $(_lib:BS) ;
438
439	MainFromObjects $(_lib) : $(2) ;
440	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
441		-shared -Xlinker -soname=\"$(soname)\" ;
442	LinkAgainst $(_lib) : $(3) ;
443
444	AddSharedObjectGlueCode $(_lib) : false ;
445}
446
447rule SharedLibrary
448{
449	# SharedLibrary <lib> : <sources> : <libraries> : <abiVersion> ;
450	local lib = $(1) ;
451	local sources = [ FGristFiles $(2) ] ;
452	local objects = $(sources:S=$(SUFOBJ)) ;
453	local libs = $(3) ;
454	local abiVersion = $(4) ;	# major ABI (soname) version for lib (if any)
455
456	if ! [ IsPlatformSupportedForTarget $(1) ] {
457		return ;
458	}
459
460	if $(abiVersion) {
461		HAIKU_SONAME on $(lib) = $(lib:BS).$(abiVersion) ;
462		HAIKU_LIB_ABI_VERSION on $(lib) = $(abiVersion) ;
463	}
464
465	InheritPlatform $(objects) : $(lib) ;
466	Objects $(sources) ;
467	SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ;
468}
469
470rule LinkAgainst
471{
472	# LinkAgainst <name> : <libs> [ : <mapLibs> ] ;
473	# Valid elements for <libs> are e.g. "be" or "libtranslation.so" or
474	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
475	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
476	# file will be bound!), otherwise it is prefixed "-l" and added to
477	# LINKLIBS. If you want to specify a target that isn't a library and
478	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
479	# grist; it will be stripped by this rule.
480	# <mapLibs> specifies whether the to translate library names (e.g. "be"
481	# to "libbe.so" in case of target platform "haiku"). Defaults to "true".
482	#
483	local target = $(1) ;
484	local libs = $(2) ;
485	local mapLibs = $(3:E=true) ;
486
487	on $(target) {
488		# map libraries, if desired and target platform is Haiku
489		local map = $(TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH)) ;
490		if $(PLATFORM) != host && $(mapLibs) = true && $(map) {
491			local mappedLibs ;
492
493			for i in $(libs) {
494				local mapped = $($(map)_$(i)) ;
495				mapped ?= $(i) ;
496				mappedLibs += $(mapped) ;
497			}
498
499			libs = $(mappedLibs) ;
500		}
501
502		local linkLibs ;
503		local needLibs ;
504
505		for i in $(libs)
506		{
507			local isfile = ;
508			if $(i:D) || $(i:G) {
509				isfile = true ;
510				if $(i:G) = <nogrist> {
511					i = $(i:G=) ;
512				}
513			} else {
514				switch $(i:B)
515				{
516					# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
517					case _APP_ : isfile = true ;
518					case _KERNEL_ : isfile = true ;
519					case lib*	: isfile = true ;
520					case *	: isfile = ;
521				}
522				if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
523					isfile = true ;
524				}
525			}
526
527			if $(isfile) {
528				needLibs += $(i) ;
529			} else {
530				linkLibs += $(i) ;
531			}
532		}
533
534		NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ;
535		LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ;
536
537		if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) {
538			Depends $(1) : $(needLibs) ;
539		}
540	}
541}
542
543rule AddResources
544{
545	# AddResources <name> : <resourcefiles> ;
546
547	# add grist to the resource files which don't have any yet
548	local resfiles ;
549	local file ;
550	for file in $(2) {
551		if ! $(file:G) {
552			file = [ FGristFiles $(file) ] ;
553		}
554		resfiles += $(file) ;
555	}
556
557	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
558
559	for file in $(resfiles) {
560		if $(file:S) = .rdef {
561			local rdef = $(file) ;
562			file = $(rdef:S=.rsrc) ;
563			ResComp $(file) : $(rdef) ;
564		}
565		InheritPlatform $(file) : $(1) ;
566		RESFILES on $(1) += $(file) ;
567	}
568}
569
570rule SetVersionScript target : versionScript
571{
572	# SetVersionScript <target> : <versionScript>
573	#
574	# Sets the version script for <target>. Grist will be added to
575	# <versionScript> and SEARCH will be set on it.
576
577	versionScript = [ FGristFiles $(versionScript) ] ;
578
579	SEARCH on $(versionScript) += $(SEARCH_SOURCE) ;
580
581	VERSION_SCRIPT on $(target) = $(versionScript) ;
582	Depends $(target) : $(versionScript) ;
583}
584
585rule BuildPlatformObjects
586{
587	# Usage BuildPlatformObjects <sources> ;
588	# <sources> The sources.
589	#
590	local sources = [ FGristFiles $(1) ] ;
591	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
592
593	PLATFORM on $(objects) = host ;
594	SUPPORTED_PLATFORMS on $(objects) = host ;
595
596	Objects $(sources) ;
597}
598
599actions CygwinExtensionFix
600{
601	if test -f $(1).exe ; then
602		rm -f $(1)
603		mv $(1).exe $(1)
604	fi
605}
606
607rule BuildPlatformMain
608{
609	# Usage BuildPlatformMain <target> : <sources> : <libraries> ;
610	# <target> The executable/library.
611	# <sources> The sources.
612	# <libraries> Libraries to link against.
613	#
614	local target = $(1) ;
615	local sources = $(2) ;
616	local libs = $(3) ;
617	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
618
619	PLATFORM on $(target) = host ;
620	SUPPORTED_PLATFORMS on $(target) = host ;
621	DONT_USE_BEOS_RULES on $(target) = true ;
622
623	local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ;
624	if $(usesBeAPI) {
625		# propagate the flag to the objects
626		USES_BE_API on $(objects) = $(usesBeAPI) ;
627
628		# add the build libroot
629		if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) {
630			local libroot = [ on $(target) return $(HOST_LIBROOT) ] ;
631			Depends $(target) : $(libroot) ;
632			NEEDLIBS on $(target) += $(libroot) ;
633		}
634	}
635
636	Main $(target) : $(sources) ;
637	LinkAgainst $(target) : $(libs) ;
638	if $(HOST_PLATFORM) = cygwin {
639		# Cygwin gcc adds the ".exe" extension. We cannot force
640		# jam to use SUFEXE as haiku target executables are not
641		# supposed to have this extension, thus finding
642		# dependencies will fail for these.
643		# The hack is to remove the extension after a successful
644		# build of the Target.
645		CygwinExtensionFix $(target) ;
646	}
647}
648
649rule BuildPlatformSharedLibrary
650{
651	# Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ;
652	# <target> The library.
653	# <sources> The sources.
654	# <libraries> Libraries to link against.
655	#
656	local target = $(1) ;
657	local sources = $(2) ;
658	local libs = $(3) ;
659
660	BuildPlatformMain $(target) : $(sources) : $(libs) ;
661
662	if $(HOST_PLATFORM) = darwin {
663		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
664			-dynamic -dynamiclib -Xlinker -flat_namespace ;
665	} else if $(HOST_PLATFORM) = cygwin {
666		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
667			-shared -Xlinker --allow-multiple-definition ;
668	} else {
669		LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ]
670			-shared -Xlinker -soname=\"$(target:G=)\" ;
671	}
672
673    local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
674	CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ;
675	C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ;
676}
677
678rule BuildPlatformMergeObject
679{
680	# BuildPlatformMergeObject <name> : <sources> : <other objects> ;
681	# Compiles source files and merges the object files to an object file.
682	# <name>: Name of the object file to create. No grist will be added.
683	# <sources>: Sources to be compiled. Grist will be added.
684	# <other objects>: Object files or static libraries to be merged. No grist
685	#                  will be added.
686	#
687	local target = $(1) ;
688	local sources = $(2) ;
689	local otherObjects = $(3) ;
690	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
691
692	PLATFORM on $(target) = host ;
693	SUPPORTED_PLATFORMS on $(target) = host ;
694
695	local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ;
696	if $(usesBeAPI) {
697		# propagate the flag to the objects
698		USES_BE_API on $(objects) = $(usesBeAPI) ;
699	}
700
701	MergeObject $(target) : $(sources) : $(otherObjects) ;
702}
703
704rule BuildPlatformMergeObjectPIC target : sources : otherObjects
705{
706	# BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ;
707	# Compiles source files and merges the object files to an object file.
708	# Same as BuildPlatformMergeObject rule but adds position-independent
709	# flags to the compiler (if any).
710	# <name>: Name of the object file to create. No grist will be added.
711	# <sources>: Sources to be compiled. Grist will be added.
712	# <other objects>: Object files or static libraries to be merged. No grist
713	#                  will be added.
714	#
715	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
716	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
717
718	BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ;
719}
720
721rule BuildPlatformStaticLibrary lib : sources : otherObjects
722{
723	# BuildPlatformStaticLibrary <lib> : <sources> ;
724	# Creates a static library from sources.
725	# <lib>: The static library to be built.
726	# <sources>: List of source files.
727	# <otherObjects>: List of additional object files.
728	#
729
730	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
731
732	PLATFORM on $(lib) = host ;
733	SUPPORTED_PLATFORMS on $(lib) = host ;
734
735	local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ;
736	if $(usesBeAPI) {
737		# propagate the flag to the objects
738		USES_BE_API on $(objects) = $(usesBeAPI) ;
739	}
740
741	StaticLibrary $(lib) : $(sources) : $(otherObjects) ;
742}
743
744rule BuildPlatformStaticLibraryPIC target : sources : otherObjects
745{
746	# Like BuildPlatformStaticLibrary, but producing position independent code.
747
748	ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ;
749	ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ;
750
751	BuildPlatformStaticLibrary $(target) : $(sources) : $(otherObjects) ;
752}
753