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