xref: /haiku/build/jam/ArchitectureRules (revision 68d37cfb3a755a7270d772b505ee15c8b18aa5e0)
1rule ArchitectureSetup architecture
2{
3	# ArchitectureSetup <architecture> ;
4	#
5	# Initializes all global packaging architecture dependent variables for the
6	# given packaging architecture. Also sets HAIKU_ARCH (to the primary
7	# architecture), if this is the first invocation of the rule, and adds
8	# the architecture to HAIKU_ARCHS, if not yet contained.
9
10	# enable GCC -pipe option, if requested
11	local ccBaseFlags ;
12	if $(HAIKU_USE_GCC_PIPE) = 1 {
13		ccBaseFlags = -pipe ;
14	}
15
16	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
17		# disable strict aliasing on anything newer than gcc 2 as it may lead to
18		# unexpected results.
19		# TODO: remove the -fno-strict-aliasing option when all code has been
20		#		analyzed/fixed with regard to aliasing.
21		ccBaseFlags += -fno-strict-aliasing ;
22
23		# Without this flag, GCC deletes many null-pointer checks that are
24		# technically undefined behavior (e.g. passing NULL to strdup, among
25		# others), which breaks both the kernel and various applications. See:
26		#  - https://freelists.org/post/haiku-development/hrev45320-Yet-another-nonobvious-effect-of-ftreevrp-optimization
27		#  - https://dev.haiku-os.org/ticket/13285#comment:8 (& subsequent comments)
28		#  - https://dev.haiku-os.org/ticket/10803#comment:4 (& subsequent comments)
29		# Note that the Linux also does the same:
30		#  - https://github.com/torvalds/linux/commit/a3ca86aea507904
31		ccBaseFlags += -fno-delete-null-pointer-checks ;
32
33		# disable some builtins that are incompatible with our definitions
34		ccBaseFlags += -fno-builtin-fork -fno-builtin-vfork ;
35	}
36
37	# default architecture tuning
38	local cpu = $(HAIKU_CPU_$(architecture)) ;
39	local archFlags ;
40	switch $(cpu) {
41		case ppc : archFlags += -mcpu=440fp ;
42		case arm : archFlags += -march=armv7-a -mfloat-abi=hard ;
43		case x86 : archFlags += -march=pentium ;
44	}
45	if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
46		# TODO: These should be included in Clang's compiler specs.
47		ccBaseFlags += -fPIC ;
48		HAIKU_LINKFLAGS_$(architecture) += -shared ;
49	}
50	ccBaseFlags += $(archFlags) ;
51
52	# activating graphite optimizations
53	if $(HAIKU_USE_GCC_GRAPHITE_$(architecture)) = 1 {
54		ccBaseFlags += -floop-nest-optimize -fgraphite-identity ;
55	}
56
57	# initial state for flags etc.
58	HAIKU_C++_$(architecture) ?= $(HAIKU_CC_$(architecture)) ;
59	HAIKU_LINK_$(architecture) ?= $(HAIKU_CC_$(architecture)) ;
60
61	HAIKU_CCFLAGS_$(architecture) += $(ccBaseFlags) -nostdinc ;
62	HAIKU_C++FLAGS_$(architecture) += $(ccBaseFlags) -nostdinc ;
63	HAIKU_LINKFLAGS_$(architecture) += $(ccBaseFlags) ;
64	HAIKU_ASFLAGS_$(architecture) += $(archFlags) -nostdinc ;
65
66	# strip is required
67	if ! $(HAIKU_STRIP_$(architecture)) {
68		Exit "HAIKU_STRIP_$(architecture) not set. Please re-run configure." ;
69	}
70
71	HAIKU_ARCH_$(architecture) = $(cpu) ;
72	HAIKU_ARCH ?= $(cpu) ;
73		# Set only, if not set yet. This way HAIKU_ARCH is set to the primary
74		# architecture.
75	if ! $(cpu) in $(HAIKU_ARCHS) {
76		HAIKU_ARCHS += $(cpu) ;
77	}
78	HAIKU_DEFINES_$(architecture) += ARCH_$(cpu) ;
79
80	# directories
81	HAIKU_ARCH_OBJECT_DIR_$(architecture)
82		= [ FDirName $(HAIKU_OBJECT_BASE_DIR) $(architecture) ] ;
83	HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture)
84		= [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture)) common ] ;
85	HAIKU_DEBUG_0_OBJECT_DIR_$(architecture)
86		= [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture)) release ] ;
87
88	local level ;
89	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
90		HAIKU_DEBUG_$(level)_OBJECT_DIR_$(architecture)
91			= [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture))
92				debug_$(level) ] ;
93	}
94
95	# set variables for gcc header options
96	SetIncludePropertiesVariables HAIKU : _$(architecture) ;
97
98	# warning flags
99	HAIKU_WARNING_CCFLAGS_$(architecture) = -Wall
100		-Wno-multichar
101		-Wpointer-arith -Wsign-compare
102		-Wmissing-prototypes ;
103	HAIKU_WARNING_C++FLAGS_$(architecture) = -Wall
104		-Wno-multichar
105		-Wpointer-arith -Wsign-compare
106		-Wno-ctor-dtor-privacy -Woverloaded-virtual ;
107
108	# disable some Clang warnings that are not very useful
109	if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
110		HAIKU_WARNING_CCFLAGS_$(architecture) += -Wno-address-of-packed-member
111			-Wno-unused-private-field -Wno-cast-align -Wno-gnu-designator
112			-Wno-builtin-requires-header ;
113		HAIKU_WARNING_C++FLAGS_$(architecture) += -Wno-address-of-packed-member
114			-Wno-unused-private-field -Wno-cast-align -Wno-gnu-designator
115			-Wno-builtin-requires-header ;
116	}
117
118	HAIKU_WERROR_FLAGS_$(architecture) = ;
119
120	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
121		# TODO: Remove all these.
122		HAIKU_WERROR_FLAGS_$(architecture) += -Wno-error=unused-but-set-variable
123			-Wno-error=deprecated -Wno-error=deprecated-declarations
124			-Wno-error=cpp -Wno-error=trigraphs ;
125		# But these can stay.
126		HAIKU_WERROR_FLAGS_$(architecture) += -Wno-error=cast-align
127			-Wno-error=format-truncation ;
128	}
129
130	# debug flags
131	local debugFlags = -ggdb ;
132
133	# debug 0: suppress asserts
134	HAIKU_DEBUG_0_CCFLAGS_$(architecture) = [ FDefines NDEBUG=$(NDEBUG) ] ;
135	HAIKU_DEBUG_0_C++FLAGS_$(architecture) = [ FDefines NDEBUG=$(NDEBUG) ] ;
136
137	local level ;
138	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
139		local flags = $(debugFlags) [ FDefines DEBUG=$(level) ] ;
140		HAIKU_DEBUG_$(level)_CCFLAGS_$(architecture) = $(flags) ;
141		HAIKU_DEBUG_$(level)_C++FLAGS_$(architecture) = $(flags) ;
142	}
143
144	# TODO: Temporary work-around. Should be defined in the compiler specs
145	HAIKU_LINKFLAGS_$(architecture) += -Xlinker --no-undefined ;
146
147	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 {
148		HAIKU_DEFINES_$(architecture) += _BEOS_R5_COMPATIBLE_ ;
149	}
150
151	# private shared kernel/libroot headers
152	HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture)
153		= [ PrivateHeaders $(DOT) system system/arch/$(cpu) ] ;
154
155	# library and executable glue code
156	local commonGlueCode =
157		<src!system!glue!$(architecture)>init_term_dyn.o
158		<src!system!glue!arch!$(cpu)!$(architecture)>crti.o
159		<src!system!glue!arch!$(cpu)!$(architecture)>crtn.o
160		;
161	HAIKU_LIBRARY_BEGIN_GLUE_CODE_$(architecture) =
162		<src!system!glue!arch!$(cpu)!$(architecture)>crti.o
163		<$(architecture)>crtbeginS.o
164		<src!system!glue!$(architecture)>init_term_dyn.o
165		;
166	HAIKU_LIBRARY_END_GLUE_CODE_$(architecture) =
167		<$(architecture)>crtendS.o
168		<src!system!glue!arch!$(cpu)!$(architecture)>crtn.o
169		;
170	HAIKU_EXECUTABLE_BEGIN_GLUE_CODE_$(architecture) =
171		<src!system!glue!arch!$(cpu)!$(architecture)>crti.o
172		<$(architecture)>crtbeginS.o
173		<src!system!glue!$(architecture)>start_dyn.o
174		<src!system!glue!$(architecture)>init_term_dyn.o
175		;
176	HAIKU_EXECUTABLE_END_GLUE_CODE_$(architecture)
177		= $(HAIKU_LIBRARY_END_GLUE_CODE_$(architecture)) ;
178
179	SEARCH on <$(architecture)>crtbeginS.o <$(architecture)>crtendS.o
180		= $(HAIKU_GCC_LIB_DIR_$(architecture)) ;
181
182	# init library name map
183	local libraryGrist = "" ;
184	if $(architecture) != $(HAIKU_PACKAGING_ARCHS[1]) {
185		libraryGrist = $(architecture) ;
186	}
187	local i ;
188	for i in be bnetapi debug device game locale mail media midi midi2
189			network package root screensaver textencoding tracker
190			translation z {
191		local library = lib$(i).so ;
192		HAIKU_LIBRARY_NAME_MAP_$(architecture)_$(i)
193			= $(library:G=$(libraryGrist)) ;
194	}
195	HAIKU_LIBRARY_NAME_MAP_$(architecture)_localestub
196		= <$(architecture)>liblocalestub.a ;
197	HAIKU_LIBRARY_NAME_MAP_$(architecture)_shared
198		= <$(architecture)>libshared.a ;
199	if $(architecture) = $(HAIKU_PACKAGING_ARCHS[1]) {
200		HAIKU_LIBRARY_NAME_MAP_$(architecture)_input_server
201			= <nogrist>input_server ;
202	} else {
203		HAIKU_LIBRARY_NAME_MAP_$(architecture)_input_server
204			= <$(architecture)>input_server ;
205	}
206}
207
208
209rule KernelArchitectureSetup architecture
210{
211	# KernelArchitectureSetup <architecture> ;
212	#
213	# Initializes the global kernel and boot loader related variables. Those
214	# don't have a packaging architecture suffix, since they are only set for
215	# the primary packaging architecture. <architecture> is the primary
216	# packaging architecture (supplied for convenience).
217
218	HAIKU_KERNEL_ARCH = $(HAIKU_ARCH) ;
219
220	local cpu = $(HAIKU_CPU_$(architecture)) ;
221
222	switch $(cpu) {
223		case ppc :
224			HAIKU_KERNEL_PLATFORM ?= openfirmware ;
225			HAIKU_BOOT_TARGETS += openfirmware ;
226
227			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
228			# offset in floppy image (>= sizeof(haiku_loader))
229			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB
230
231		case sparc :
232			HAIKU_KERNEL_PLATFORM ?= openfirmware ;
233			HAIKU_BOOT_TARGETS += openfirmware ;
234
235			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
236			# offset in floppy image (>= sizeof(haiku_loader))
237			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB
238
239		case arm :
240			HAIKU_KERNEL_PLATFORM ?= efi ;
241			HAIKU_BOOT_TARGETS += efi ;
242
243			# SOC's like allwinner need an offset to skip the hardcoded initial loader
244			HAIKU_BOOT_SDIMAGE_BEGIN = 20475 ; # in KiB
245
246			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
247			# offset in floppy image (>= sizeof(haiku_loader))
248			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
249			HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ;
250
251		case arm64 :
252			HAIKU_KERNEL_PLATFORM ?= efi ;
253			HAIKU_BOOT_TARGETS += efi ;
254
255			HAIKU_BOOT_SDIMAGE_BEGIN = 0 ; # in KiB
256
257			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
258			# offset in floppy image (>= sizeof(haiku_loader))
259			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
260			HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ;
261
262		case x86 :
263			HAIKU_KERNEL_PLATFORM ?= bios_ia32 ;
264			HAIKU_BOOT_TARGETS += bios_ia32 pxe_ia32 ;
265			HAIKU_ANYBOOT_LEGACY = 1 ;
266
267			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
268			# offset in floppy image (>= sizeof(haiku_loader))
269			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 320 ; # in kB
270
271			# nasm is required for target arch x86
272			if ! $(HAIKU_NASM) {
273				Exit "HAIKU_NASM not set. Please re-run configure." ;
274			}
275
276		case riscv64 :
277			HAIKU_KERNEL_PLATFORM ?= efi ;
278			HAIKU_BOOT_TARGETS += efi ;
279
280			HAIKU_BOOT_SDIMAGE_BEGIN = 0 ; # KiB
281
282			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
283			# offset in floppy image (>= sizeof(haiku_loader))
284			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
285			HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ;
286
287		case x86_64 :
288			# x86_64 completely shares the x86 bootloader for MBR.
289			HAIKU_KERNEL_PLATFORM ?= bios_ia32 ;
290			HAIKU_BOOT_TARGETS += bios_ia32 efi pxe_ia32 ;
291
292			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
293			# offset in floppy image (>= sizeof(haiku_loader))
294			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 320 ; # in kB
295
296			# x86_64 kernel source is under arch/x86.
297			HAIKU_KERNEL_ARCH = x86 ;
298
299			# nasm is required for target arch x86_64
300			if ! $(HAIKU_NASM) {
301				Exit "HAIKU_NASM not set. Please re-run configure." ;
302			}
303
304		case m68k :
305			HAIKU_KERNEL_PLATFORM ?= atari_m68k ;
306			HAIKU_BOOT_TARGETS += amiga_m68k atari_m68k next_m68k ;
307			switch $(HAIKU_KERNEL_PLATFORM) {
308				case atari_m68k :
309				{
310					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
311				}
312				case amiga_m68k :
313				{
314					# for now we have trouble reading from double-sided images
315					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 880 ; # in kB
316				}
317				case next_m68k :
318				{
319					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
320				}
321			}
322			# offset in floppy image (>= sizeof(haiku_loader))
323			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 260 ; # in kB
324			HAIKU_CONTAINER_STRIP_EXECUTABLES on
325				$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) = 1 ;
326
327		case * :
328			Exit "Currently unsupported target CPU:" $(cpu) ;
329	}
330
331	# private kernel headers to be used when compiling kernel code
332	HAIKU_PRIVATE_KERNEL_HEADERS =
333		[ PrivateHeaders $(DOT) kernel libroot shared
334			kernel/boot/platform/$(HAIKU_KERNEL_PLATFORM) ]
335		[ ArchHeaders $(HAIKU_KERNEL_ARCH) ]
336		[ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture)) system
337			kernel ]
338		$(HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture))
339		;
340
341	# C/C++ flags
342	local ccBaseFlags = -finline -fno-builtin ;
343
344	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
345		if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
346			# Clang does not yet understand this flag.
347			ccBaseFlags += -fno-semantic-interposition ;
348		}
349
350		ccBaseFlags += -ffreestanding ;
351	}
352
353	local c++BaseFlags = $(ccBaseFlags) -fno-exceptions ;
354
355	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1
356			&& $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
357		c++BaseFlags += -fno-use-cxa-atexit ;
358	}
359
360	HAIKU_KERNEL_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ;
361	HAIKU_KERNEL_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ;
362	HAIKU_KERNEL_PIC_CCFLAGS = ;
363	HAIKU_KERNEL_PIC_LINKFLAGS = ;
364	HAIKU_KERNEL_ADDON_LINKFLAGS = ;
365
366	# Common boot-related cflags which apply to all loaders
367	HAIKU_BOOT_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ;
368	HAIKU_BOOT_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ;
369	HAIKU_BOOT_LINKFLAGS = ;
370	HAIKU_BOOT_LDFLAGS = -Bstatic ;
371
372	# Remove -fPIC and other unwanted options from the BOOT flags (they are sometimes
373	# added to force PIC in general.)
374	local fixedBootCCFlags ;
375	local fixedBootC++Flags ;
376	for flag in $(HAIKU_BOOT_CCFLAGS) {
377		if $(flag) = "-fpic" || $(flag) = "-fPIC" {
378			continue ;
379		}
380		fixedBootCCFlags += $(flag) ;
381	}
382	for flag in $(HAIKU_BOOT_C++FLAGS) {
383		if $(flag) = "-fpic" || $(flag) = "-fPIC" {
384			continue ;
385		}
386		fixedBootC++Flags += $(flag) ;
387	}
388	HAIKU_BOOT_CCFLAGS = $(fixedBootCCFlags) ;
389	HAIKU_BOOT_C++FLAGS = $(fixedBootC++Flags) ;
390
391	# Any special kernel base addresses
392	if $(HAIKU_BOOT_LOADER_BASE) {
393		HAIKU_BOOT_LDFLAGS +=
394			--defsym BOOT_LOADER_BASE=$(HAIKU_BOOT_LOADER_BASE) ;
395	}
396
397	switch $(cpu) {
398		case arm :
399			HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ;
400			HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ;
401			HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
402
403		case arm64 :
404			HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ;
405			HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ;
406			HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
407
408		case m68k :
409			# We don't want to have to handle emulating missing FPU opcodes for
410			# 040 and 060 in the kernel.
411			HAIKU_KERNEL_CCFLAGS += -m68020-60 ;
412			HAIKU_KERNEL_C++FLAGS += -m68020-60 ;
413
414		case ppc :
415			# Build a position independent PPC kernel. We need to be able to
416			# relocate the kernel, since the virtual address space layout at
417			# boot time is not fixed.
418			HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ;
419			HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
420
421		case riscv64 :
422			# Kernel lives within any single 2 GiB address space.
423			# Default is medlow (-2GiB / +2GiB)
424			HAIKU_KERNEL_CCFLAGS += -mcmodel=medany ;
425			HAIKU_KERNEL_C++FLAGS += -mcmodel=medany ;
426
427		case sparc :
428			# The medlow code model is enough (64-bit addresses, programs must
429			# be linked in the low 32 bits of memory. Programs can be
430			# statically or dynamically linked.)
431			HAIKU_KERNEL_CCFLAGS += -mcmodel=medlow ;
432			HAIKU_KERNEL_C++FLAGS += -mcmodel=medlow ;
433
434			# Unfortunately it's not easy to make the kernel be
435			# position-independant, on sparc, that requires relocation support
436			# in the ELF loader to fill in the plt section.
437			HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ;
438			HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
439
440		case x86 :
441			HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
442			HAIKU_KERNEL_CCFLAGS += -march=pentium ;
443			HAIKU_KERNEL_C++FLAGS += -march=pentium ;
444
445		case x86_64 :
446			# Kernel lives in the top 2GB of the address space, use kernel code
447			# model.
448			HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic -mcmodel=kernel ;
449
450			# Disable the red zone, which cannot be used in kernel code due to
451			# interrupts, and always enable the frame pointer so stack traces
452			# are correct.
453			HAIKU_KERNEL_CCFLAGS += -mno-red-zone -fno-omit-frame-pointer ;
454			HAIKU_KERNEL_C++FLAGS += -mno-red-zone -fno-omit-frame-pointer ;
455			HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ;
456			HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ;
457
458			if x86 in $(HAIKU_ARCHS[2-]) || x86_gcc2 in $(HAIKU_ARCHS[2-]) {
459				Echo "Enable kernel ia32 compatibility" ;
460				HAIKU_KERNEL_DEFINES += _COMPAT_MODE ;
461				HAIKU_KERNEL_COMPAT_MODE = 1 ;
462			}
463	}
464
465	# bootloader-centric flags
466	local bootTarget ;
467	for bootTarget in $(HAIKU_BOOT_TARGETS) {
468		switch $(bootTarget) {
469			case efi :
470				# efi bootloader is PIC
471				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fpic -fno-stack-protector
472					-fPIC -fshort-wchar -Wno-error=unused-variable -Wno-error=main ;
473				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fpic -fno-stack-protector
474					-fPIC -fshort-wchar -Wno-error=unused-variable -Wno-error=main ;
475				switch $(cpu) {
476					case x86 :
477						if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
478							HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -maccumulate-outgoing-args ;
479							HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -maccumulate-outgoing-args ;
480						}
481					case x86_64 :
482						HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -mno-red-zone ;
483						HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -mno-red-zone ;
484						if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
485							HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -maccumulate-outgoing-args ;
486							HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -maccumulate-outgoing-args ;
487						}
488				}
489				HAIKU_BOOT_$(bootTarget:U)_LDFLAGS = -Bstatic -Bsymbolic
490					-nostdlib -znocombreloc -no-undefined ;
491			case bios_ia32 :
492				# bios_ia32 is non-PIC
493				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ;
494				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ;
495				if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
496					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ;
497				} else {
498					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ;
499				}
500				if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
501					HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ;
502					HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ;
503				}
504			case pxe_ia32 :
505				# pxe_ia32 is non-PIC
506				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ;
507				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ;
508				if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
509					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ;
510				} else {
511					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ;
512				}
513				if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
514					HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ;
515					HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ;
516				}
517			case *_m68k :
518				# TODO: make sure all m68k bootloaders are non-PIC
519				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -Wno-error=main ;
520				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -Wno-error=main ;
521				switch $(cpu) {
522					case m68k :
523						# use only common instructions by default
524						HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -m68020-60 ;
525						HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -m68020-60 ;
526					# TODO: coldfire (FireBee)
527				}
528			case * :
529				# all other bootloaders are non-PIC
530				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -Wno-error=main ;
531				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -Wno-error=main ;
532		}
533	}
534
535	# warning flags
536	HAIKU_KERNEL_WARNING_CCFLAGS = $(HAIKU_WARNING_CCFLAGS_$(architecture)) ;
537	HAIKU_KERNEL_WARNING_C++FLAGS = $(HAIKU_WARNING_C++FLAGS_$(architecture)) ;
538
539	# debug flags
540	local level ;
541	for level in $(HAIKU_DEBUG_LEVELS) {
542		local flags = $(HAIKU_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
543		HAIKU_KERNEL_DEBUG_$(level)_CCFLAGS
544			= $(HAIKU_DEBUG_$(level)_CCFLAGS_$(architecture)) ;
545		HAIKU_KERNEL_DEBUG_$(level)_C++FLAGS
546			= $(HAIKU_DEBUG_$(level)_C++FLAGS_$(architecture)) ;
547	}
548
549	# defines
550	HAIKU_KERNEL_DEFINES += _KERNEL_MODE ;
551
552	HAIKU_DEFINES_$(architecture)
553		+= BOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
554		# TODO: That doesn't need to be a general define. It's just needed for
555		# compiling (part of) the boot loader.
556
557	# kernel add-on glue code
558	HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbeginS.o
559		<src!system!glue!$(architecture)>haiku_version_glue.o ;
560	HAIKU_KERNEL_ADDON_END_GLUE_CODE = <$(architecture)>crtendS.o ;
561}
562
563
564rule ArchitectureSetupWarnings architecture
565{
566	# ArchitectureSetupWarnings <architecture> ;
567	#
568	# Sets up compiler warnings and error flags for various subdirectories for
569	# the given packaging architecture.
570
571	if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
572		AppendToConfigVar CCFLAGS :
573			HAIKU_TOP src system libroot posix glibc :
574			-fgnu89-inline -fheinous-gnu-extensions : global ;
575	}
576
577	local cpu = $(HAIKU_CPU_$(architecture)) ;
578	switch $(cpu) {
579		case arm :
580			return ;
581				# we use #warning as placeholders for things to write...
582		case m68k :
583			return ;
584				# we use #warning as placeholders for things to write...
585		case ppc :
586			return ;
587				# we use #warning as placeholders for things to write...
588	}
589
590	# enable -Werror for certain parts of the source tree
591	HAIKU_WERROR_ARCH = $(architecture) ;
592
593	rule EnableWerror dirTokens : scope {
594		# Clang gives way more warnings than GCC, so that code won't compile
595		# with -Werror when using Clang.
596		if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
597			SetConfigVar WARNINGS : HAIKU_TOP $(dirTokens) : treatAsErrors
598				: $(scope) ;
599		}
600	}
601
602	# Work-around for GCC 2 problem -- despite -Wno-multichar it reports
603	# multichar warnings in headers/private/kernel/debugger_keymaps.h included
604	# by src/system/kernel/arch/x86/arch_debug_console.cpp.
605	if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 {
606		local file = <src!system!kernel!arch!x86>arch_debug_console.o ;
607		WARNINGS on $(file) = $(WARNINGS) ;
608	}
609
610	EnableWerror src add-ons accelerants ;
611	EnableWerror src add-ons bluetooth ;
612	EnableWerror src add-ons decorators ;
613	EnableWerror src add-ons disk_systems ;
614	EnableWerror src add-ons input_server devices ;
615	EnableWerror src add-ons input_server filters ;
616#	EnableWerror src add-ons input_server methods pen ;
617	EnableWerror src add-ons input_server methods t9 ;
618	EnableWerror src add-ons kernel bluetooth ;
619	EnableWerror src add-ons kernel bus_managers acpi ;
620	EnableWerror src add-ons kernel bus_managers agp_gart ;
621	EnableWerror src add-ons kernel bus_managers ata ;
622	EnableWerror src add-ons kernel bus_managers config_manager ;
623#	EnableWerror src add-ons kernel bus_managers firewire ;
624	EnableWerror src add-ons kernel bus_managers ide ;
625	EnableWerror src add-ons kernel bus_managers isa ;
626	EnableWerror src add-ons kernel bus_managers pci ;
627	EnableWerror src add-ons kernel bus_managers ps2 ;
628	EnableWerror src add-ons kernel bus_managers random ;
629	EnableWerror src add-ons kernel bus_managers scsi ;
630	EnableWerror src add-ons kernel bus_managers tty ;
631	EnableWerror src add-ons kernel bus_managers usb ;
632	EnableWerror src add-ons kernel bus_managers virtio ;
633	EnableWerror src add-ons kernel busses agp_gart ;
634	EnableWerror src add-ons kernel busses ata ;
635	EnableWerror src add-ons kernel busses scsi ;
636	EnableWerror src add-ons kernel busses usb ;
637	EnableWerror src add-ons kernel console ;
638	EnableWerror src add-ons kernel cpu ;
639#	EnableWerror src add-ons kernel debugger ; # gcc2
640#	EnableWerror src add-ons kernel drivers audio ;
641	EnableWerror src add-ons kernel drivers bluetooth ;
642#	EnableWerror src add-ons kernel drivers bus ;
643	EnableWerror src add-ons kernel drivers common ;
644#	EnableWerror src add-ons kernel drivers disk ;
645	EnableWerror src add-ons kernel drivers dvb ;
646#	EnableWerror src add-ons kernel drivers graphics ;
647	EnableWerror src add-ons kernel drivers graphics intel_extreme ;
648#	EnableWerror src add-ons kernel drivers input ;
649	EnableWerror src add-ons kernel drivers joystick ;
650	EnableWerror src add-ons kernel drivers midi ;
651	EnableWerror src add-ons kernel drivers misc ;
652#	EnableWerror src add-ons kernel drivers network ;
653	EnableWerror src add-ons kernel drivers ports ;
654#	EnableWerror src add-ons kernel drivers power ;
655	EnableWerror src add-ons kernel drivers printer ;
656	EnableWerror src add-ons kernel drivers random ;
657	EnableWerror src add-ons kernel drivers tty ;
658	EnableWerror src add-ons kernel drivers video ;
659	EnableWerror src add-ons kernel file_systems bfs ;
660	EnableWerror src add-ons kernel file_systems cdda ;
661#	EnableWerror src add-ons kernel file_systems ext2 ;
662#	EnableWerror src add-ons kernel file_systems fat ;
663#	EnableWerror src add-ons kernel file_systems googlefs ;
664	EnableWerror src add-ons kernel file_systems iso9660 ;
665	EnableWerror src add-ons kernel file_systems layers ;
666#	EnableWerror src add-ons kernel file_systems netfs ;
667#	EnableWerror src add-ons kernel file_systems nfs ;
668	EnableWerror src add-ons kernel file_systems nfs4 ;
669#	EnableWerror src add-ons kernel file_systems ntfs ;
670	EnableWerror src add-ons kernel file_systems packagefs ;
671#	EnableWerror src add-ons kernel file_systems ramfs ;
672#	EnableWerror src add-ons kernel file_systems reiserfs ;
673	EnableWerror src add-ons kernel file_systems udf ;
674	EnableWerror src add-ons kernel file_systems userlandfs ;
675	EnableWerror src add-ons kernel generic ;
676#	EnableWerror src add-ons kernel network datalink_protocols ;
677	EnableWerror src add-ons kernel network devices ;
678	EnableWerror src add-ons kernel network dns_resolver ;
679	EnableWerror src add-ons kernel network notifications ;
680	EnableWerror src add-ons kernel network ppp ;
681	EnableWerror src add-ons kernel network protocols ;
682#	EnableWerror src add-ons kernel network stack ;
683	EnableWerror src add-ons kernel partitioning_systems ;
684	EnableWerror src add-ons kernel power ;
685	EnableWerror src add-ons locale ;
686	EnableWerror src add-ons mail_daemon ;
687	EnableWerror src add-ons media media-add-ons demultiplexer ;
688	EnableWerror src add-ons media media-add-ons dvb ;
689	EnableWerror src add-ons media media-add-ons esound_sink ;
690	EnableWerror src add-ons media media-add-ons finepix_webcam ;
691	EnableWerror src add-ons media media-add-ons firewire_dv ;
692	EnableWerror src add-ons media media-add-ons legacy ;
693	EnableWerror src add-ons media media-add-ons mixer ;
694	EnableWerror src add-ons media media-add-ons multi_audio ;
695	EnableWerror src add-ons media media-add-ons opensound ;
696	EnableWerror src add-ons media media-add-ons radeon ;
697	EnableWerror src add-ons media media-add-ons reader ;
698	EnableWerror src add-ons media media-add-ons tone_producer_demo ;
699	EnableWerror src add-ons media media-add-ons usb_vision ;
700#	EnableWerror src add-ons media media-add-ons usb_webcam ;
701	EnableWerror src add-ons media media-add-ons video_mixer ;
702#	EnableWerror src add-ons media media-add-ons video_producer_demo ;
703	EnableWerror src add-ons media media-add-ons videowindow ;
704	EnableWerror src add-ons media media-add-ons writer ;
705	EnableWerror src add-ons media plugins ape_reader ;
706	EnableWerror src add-ons media plugins au_reader ;
707#	EnableWerror src add-ons media plugins ffmpeg ;
708#	EnableWerror src add-ons media plugins raw_decoder ;
709	EnableWerror src add-ons print ;
710	EnableWerror src add-ons screen_savers ;
711	EnableWerror src add-ons tracker ;
712	EnableWerror src add-ons translators bmp ;
713	EnableWerror src add-ons translators exr ;
714	EnableWerror src add-ons translators gif ;
715	EnableWerror src add-ons translators hvif ;
716	EnableWerror src add-ons translators ico ;
717	EnableWerror src add-ons translators jpeg ;
718#	EnableWerror src add-ons translators jpeg2000 ;
719	EnableWerror src add-ons translators pcx ;
720	EnableWerror src add-ons translators png ;
721	EnableWerror src add-ons translators ppm ;
722	EnableWerror src add-ons translators raw ;
723	EnableWerror src add-ons translators rtf ;
724	EnableWerror src add-ons translators sgi ;
725	EnableWerror src add-ons translators shared ;
726	EnableWerror src add-ons translators stxt ;
727	EnableWerror src add-ons translators tga ;
728	EnableWerror src add-ons translators tiff ;
729	EnableWerror src add-ons translators wonderbrush ;
730	EnableWerror src add-ons print ;
731	EnableWerror src bin desklink ;
732	EnableWerror src bin multiuser ;
733	EnableWerror src bin package ;
734	EnableWerror src bin package_repo ;
735	EnableWerror src bin pkgman ;
736	EnableWerror src libs bsd ;
737	EnableWerror src apps ;
738	EnableWerror src kits ;
739	EnableWerror src preferences ;
740	EnableWerror src servers ;
741	EnableWerror src system boot ;
742	EnableWerror src system kernel ;
743	EnableWerror src system libroot add-ons ;
744	EnableWerror src system libroot os ;
745	EnableWerror src system libroot posix locale ;
746	EnableWerror src system libroot posix wchar ;
747	EnableWerror src system runtime_loader ;
748}
749
750
751rule MultiArchIfPrimary ifValue : elseValue : architecture
752{
753	# MultiArchIfPrimary <ifValue> : <elseValue>
754	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
755	#
756	# Returns one of the two given values depending on whether
757	# <architecture> is the primary packaging architecture.
758
759	architecture ?= $(TARGET_PACKAGING_ARCH) ;
760
761	if $(architecture) = $(TARGET_PACKAGING_ARCHS[1]) {
762		return $(ifValue) ;
763	}
764	return $(elseValue) ;
765}
766
767
768rule MultiArchConditionalGristFiles files : primaryGrist : secondaryGrist
769	: architecture
770{
771	# MultiArchConditionalGristFiles <files> : <primaryGrist>
772	#	: <secondaryGrist> [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
773	#
774	# Returns <files> with their grist set to either <primaryGrist> or
775	# <secondaryGrist> depending on whether <architecture> is the primary
776	# packaging architecture.
777
778	architecture ?= $(TARGET_PACKAGING_ARCH) ;
779
780	local grist = [ MultiArchIfPrimary $(primaryGrist) : $(secondaryGrist)
781		: $(architecture) ] ;
782	return $(files:G=$(grist:E=)) ;
783}
784
785
786rule MultiArchDefaultGristFiles files : gristPrefix : architecture
787{
788	# MultiArchDefaultGristFiles <files> : <gristPrefix>
789	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
790	#
791	# Convenient shorthand for MultiArchConditionalGristFiles for the common
792	# case that for a secondary packaging architecture the packaging
793	# architecture name shall be appended to the grist while it shall be omitted
794	# for the primary packaging architecture. IOW, if architecture is the
795	# primary packaging architecture, <files> are returned with their grist set
796	# to <gristPrefix>, otherwise <files> are returned with their grist set to
797	# <gristPrefix>!<architecture> respectively <architecture> (if <gristPrefix>
798	# is empty).
799
800	architecture ?= $(TARGET_PACKAGING_ARCH) ;
801
802	local secondaryGrist = $(gristPrefix)!$(architecture) ;
803	secondaryGrist ?= $(architecture) ;
804
805	return [ MultiArchConditionalGristFiles $(files) : $(gristPrefix) :
806		$(secondaryGrist) : $(architecture) ] ;
807}
808
809
810rule MultiArchSubDirSetup architectures
811{
812	# MultiArchSubDirSetup <architectures> ;
813	#
814	# For each of the given packaging architectures <architectures> that are
815	# in the packaging architectures configured for the build (or all configured
816	# packaging architectures, if <architectures> is empty) an object is
817	# prepared that can be used for an "on ... { ... }" block to set up subdir
818	# variables for the respective packaging architecture. Most notably
819	# TARGET_PACKAGING_ARCH, TARGET_ARCH are set to the values for the
820	# respective packaging architecture. The per-subdir variables SOURCE_GRIST,
821	# LOCATE_TARGET, LOCATE_SOURCE, SEARCH_SOURCE, *_LOCATE_TARGET, are reset.
822	# All SUBDIR* and config variables are set to the values they had when this
823	# rule was invoked.
824
825	local result ;
826	architectures ?= $(TARGET_PACKAGING_ARCHS) ;
827	local architecture ;
828	for architecture in $(architectures) {
829		if ! $(architecture) in $(TARGET_PACKAGING_ARCHS) {
830			continue ;
831		}
832
833		local architectureObject = $(architecture:G=<arch-object>) ;
834		result += $(architectureObject) ;
835
836		# Set the variables that default to the values of the respective
837		# variables for the primary architecture.
838		TARGET_PACKAGING_ARCH on $(architectureObject) = $(architecture) ;
839
840		local var ;
841		for var in TARGET_ARCH {
842			$(var) on $(architectureObject) = $($(var)_$(architecture)) ;
843		}
844
845		# Clone the current config variable values and the variables SubDir
846		# resets.
847		for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) {
848			$(var) on $(architectureObject) = $($(var)) ;
849		}
850
851		# adjust SOURCE_GRIST and HDRGRIST
852		SOURCE_GRIST on $(architectureObject)
853			= $(SOURCE_GRIST:E=)!$(architecture) ;
854
855		HDRGRIST on $(architectureObject)
856			= $(HDRGRIST:E=)!$(architecture) ;
857
858		# Adjust the subdir's object dirs that are architecture dependent. To
859		# avoid duplicating the code from SetupObjectsDir, we call it. Since it
860		# sets global variables, we set these variables on our object, call
861		# SetupObjectsDir in an "on" block, and grab the new variable values.
862		local hostTarget = HOST TARGET ;
863		local objectDirVars =
864			COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS)
865			;
866		objectDirVars =
867			COMMON_PLATFORM_LOCATE_TARGET
868			$(hostTarget)_$(objectDirVars)_LOCATE_TARGET
869			LOCATE_TARGET
870			LOCATE_SOURCE
871			SEARCH_SOURCE
872			;
873
874		for var in $(objectDirVars) {
875			$(var) on $(architectureObject) = ;
876		}
877
878		on $(architectureObject) {
879			SetupObjectsDir ;
880
881			for var in $(objectDirVars) {
882				$(var) on $(architectureObject) = $($(var)) ;
883			}
884		}
885	}
886
887	return $(result) ;
888}
889