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