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