ArchitectureRules revision dd45d433
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 debug device game locale mail media midi midi2
206			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
288			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
289			# offset in floppy image (>= sizeof(haiku_loader))
290			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 320 ; # in kB
291
292			# nasm is required for target arch x86
293			if ! $(HAIKU_NASM) {
294				Exit "HAIKU_NASM not set. Please re-run configure." ;
295			}
296
297		case x86_64 :
298			# x86_64 completely shares the x86 bootloader for MBR.
299			HAIKU_KERNEL_PLATFORM ?= bios_ia32 ;
300			HAIKU_BOOT_TARGETS += bios_ia32 efi pxe_ia32 ;
301
302			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
303			# offset in floppy image (>= sizeof(haiku_loader))
304			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 320 ; # in kB
305
306			# x86_64 kernel source is under arch/x86.
307			HAIKU_KERNEL_ARCH = x86 ;
308
309			# nasm is required for target arch x86_64
310			if ! $(HAIKU_NASM) {
311				Exit "HAIKU_NASM not set. Please re-run configure." ;
312			}
313
314		case m68k :
315			HAIKU_KERNEL_PLATFORM ?= atari_m68k ;
316			HAIKU_BOOT_TARGETS += atari_m68k ;
317			switch $(HAIKU_KERNEL_PLATFORM) {
318				case atari_m68k :
319				{
320					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
321				}
322				case amiga_m68k :
323				{
324					# for now we have trouble reading from double-sided images
325					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 880 ; # in kB
326				}
327			}
328			# offset in floppy image (>= sizeof(haiku_loader))
329			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 260 ; # in kB
330			HAIKU_CONTAINER_STRIP_EXECUTABLES on
331				$(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) = 1 ;
332
333		case * :
334			Exit "Currently unsupported target CPU:" $(cpu) ;
335	}
336
337	# private kernel headers to be used when compiling kernel code
338	HAIKU_PRIVATE_KERNEL_HEADERS =
339		[ PrivateHeaders $(DOT) kernel libroot shared
340			kernel/boot/platform/$(HAIKU_KERNEL_PLATFORM) ]
341		[ ArchHeaders $(HAIKU_KERNEL_ARCH) ]
342		[ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture)) system
343			kernel ]
344		$(HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture))
345		;
346
347	# C/C++ flags
348	local ccBaseFlags = $(HAIKU_GCC_BASE_FLAGS_$(architecture))
349		-finline -fno-builtin ;
350
351	if $(gccVersion[1]) >= 4 {
352		ccBaseFlags += -ffreestanding ;
353	}
354
355	local c++BaseFlags = $(ccBaseFlags) -fno-exceptions ;
356
357	if $(gccVersion[1]) >= 3 && $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
358		c++BaseFlags += -fno-use-cxa-atexit ;
359	}
360
361	HAIKU_KERNEL_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ;
362	HAIKU_KERNEL_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ;
363	HAIKU_BOOT_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ;
364	HAIKU_BOOT_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ;
365	HAIKU_BOOT_LINKFLAGS = ;
366	HAIKU_BOOT_LDFLAGS = -Bstatic ;
367
368	HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
369	HAIKU_KERNEL_PIC_LINKFLAGS = ;
370	HAIKU_KERNEL_ADDON_LINKFLAGS = ;
371
372	# Any special kernel base addresses
373	if $(HAIKU_BOOT_LOADER_BASE) {
374		HAIKU_BOOT_LDFLAGS +=
375			--defsym BOOT_LOADER_BASE=$(HAIKU_BOOT_LOADER_BASE) ;
376	}
377
378	switch $(cpu) {
379		case arm :
380			# Workaround for ld using 32k for alignment despite forcing it in the config...
381			# should definitely not be needed!
382			HAIKU_KERNEL_LINKFLAGS +=
383				-Wl,-z -Wl,max-page-size=0x1000
384				-Wl,-z -Wl,common-page-size=0x1000 ;
385
386		case ppc :
387			# Build a position independent PPC kernel. We need to be able to
388			# relocate the kernel, since the virtual address space layout at
389			# boot time is not fixed.
390			HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ;
391			HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
392
393		case m68k :
394			# We don't want to have to handle emulating missing FPU opcodes for
395			# 040 and 060 in the kernel.
396			HAIKU_KERNEL_CCFLAGS += -mtune=68020-60 ;
397			HAIKU_KERNEL_C++FLAGS += -mtune=68020-60 ;
398
399		case x86 :
400			HAIKU_KERNEL_CCFLAGS += -march=pentium ;
401			HAIKU_KERNEL_C++FLAGS += -march=pentium ;
402
403		case x86_64 :
404			# Kernel lives in the top 2GB of the address space, use kernel code
405			# model.
406			HAIKU_KERNEL_PIC_CCFLAGS += -mcmodel=kernel ;
407
408			# Disable the red zone, which cannot be used in kernel code due to
409			# interrupts, and always enable the frame pointer so stack traces
410			# are correct.
411			HAIKU_KERNEL_CCFLAGS += -mno-red-zone -fno-omit-frame-pointer ;
412			HAIKU_KERNEL_C++FLAGS += -mno-red-zone -fno-omit-frame-pointer ;
413			HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ;
414			HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ;
415
416			if x86 in $(HAIKU_ARCHS[2-]) || x86_gcc2 in $(HAIKU_ARCHS[2-]) {
417				Echo "Enable kernel ia32 compatibility" ;
418				HAIKU_KERNEL_DEFINES += _COMPAT_MODE ;
419				HAIKU_KERNEL_COMPAT_MODE = 1 ;
420			}
421	}
422
423	local bootTarget ;
424	for bootTarget in $(HAIKU_BOOT_TARGETS) {
425		switch $(bootTarget) {
426			case efi :
427				# efi bootloader is PIC
428				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fpic -fno-stack-protector
429					-fPIC -fshort-wchar -mno-red-zone -maccumulate-outgoing-args
430					-Wno-error=unused-variable -Wno-error=main ;
431				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fpic -fno-stack-protector
432					-fPIC -fshort-wchar -mno-red-zone -maccumulate-outgoing-args
433					-Wno-error=unused-variable -Wno-error=main ;
434				HAIKU_BOOT_$(bootTarget:U)_LDFLAGS = -Bstatic -Bsymbolic
435					-nostdlib -znocombreloc -nostartfiles -no-undefined ;
436			case bios_ia32 :
437				# bios_ia32 is non-PIC
438				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ;
439				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ;
440				if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
441					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ;
442				} else {
443					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ;
444				}
445				if $(gccVersion[1]) >= 3 {
446					HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ;
447					HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ;
448				}
449			case pxe_ia32 :
450				# pxe_ia32 is non-PIC
451				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ;
452				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ;
453				if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
454					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ;
455				} else {
456					HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ;
457				}
458				if $(gccVersion[1]) >= 3 {
459					HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ;
460					HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ;
461				}
462			case * :
463				# all other bootloaders are non-PIC
464				HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -Wno-error=main ;
465				HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -Wno-error=main ;
466		}
467	}
468
469	# warning flags
470	HAIKU_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes
471		-Wno-multichar ;
472	HAIKU_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-multichar ;
473
474	# debug flags
475	local level ;
476	for level in $(HAIKU_DEBUG_LEVELS) {
477		local flags = $(HAIKU_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
478		HAIKU_KERNEL_DEBUG_$(level)_CCFLAGS
479			= $(HAIKU_DEBUG_$(level)_CCFLAGS_$(architecture)) ;
480		HAIKU_KERNEL_DEBUG_$(level)_C++FLAGS
481			= $(HAIKU_DEBUG_$(level)_C++FLAGS_$(architecture)) ;
482	}
483
484	# defines
485	HAIKU_KERNEL_DEFINES += _KERNEL_MODE ;
486
487	HAIKU_DEFINES_$(architecture)
488		+= BOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
489		# TODO: That doesn't need to be a general define. It's just needed for
490		# compiling (part of) the boot loader.
491
492	# kernel add-on glue code
493	HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbeginS.o
494		<src!system!glue!$(architecture)>haiku_version_glue.o ;
495	HAIKU_KERNEL_ADDON_END_GLUE_CODE = <$(architecture)>crtendS.o ;
496}
497
498
499rule ArchitectureSetupWarnings architecture
500{
501	# ArchitectureSetupWarnings <architecture> ;
502	#
503	# Sets up compiler warnings and error flags for various subdirectories for
504	# the given packaging architecture.
505
506	if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
507		AppendToConfigVar CCFLAGS :
508			HAIKU_TOP src system libroot posix glibc :
509			-fgnu89-inline -fheinous-gnu-extensions : global ;
510	}
511
512	local cpu = $(HAIKU_CPU_$(architecture)) ;
513	switch $(cpu) {
514		case arm :
515			return ;
516				# we use #warning as placeholders for things to write...
517		case m68k :
518			return ;
519				# we use #warning as placeholders for things to write...
520		case ppc :
521			return ;
522				# we use #warning as placeholders for things to write...
523	}
524
525	# enable -Werror for certain parts of the source tree
526	HAIKU_WERROR_ARCH = $(architecture) ;
527
528	rule EnableWerror dirTokens : scope {
529		# Clang gives way more warnings than GCC, so that code won't compile
530		# with -Werror when using Clang.
531		if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
532			SetConfigVar WARNINGS : HAIKU_TOP $(dirTokens) : treatAsErrors
533				: $(scope) ;
534		}
535	}
536
537	# Work-around for GCC 2 problem -- despite -Wno-multichar it reports
538	# multichar warnings in headers/private/kernel/debugger_keymaps.h included
539	# by src/system/kernel/arch/x86/arch_debug_console.cpp.
540	local gccVersion = $(HAIKU_GCC_VERSION_$(architecture)) ;
541	if $(gccVersion[1]) = 2 {
542		local file = <src!system!kernel!arch!x86>arch_debug_console.o ;
543		WARNINGS on $(file) = $(WARNINGS) ;
544	}
545
546	EnableWerror src add-ons accelerants ;
547	EnableWerror src add-ons bluetooth ;
548	EnableWerror src add-ons decorators ;
549	EnableWerror src add-ons disk_systems ;
550	EnableWerror src add-ons input_server devices ;
551	EnableWerror src add-ons input_server filters ;
552#	EnableWerror src add-ons input_server methods pen ;
553	EnableWerror src add-ons input_server methods t9 ;
554	EnableWerror src add-ons kernel bluetooth ;
555	EnableWerror src add-ons kernel bus_managers acpi ;
556	EnableWerror src add-ons kernel bus_managers agp_gart ;
557	EnableWerror src add-ons kernel bus_managers ata ;
558	EnableWerror src add-ons kernel bus_managers config_manager ;
559#	EnableWerror src add-ons kernel bus_managers firewire ;
560	EnableWerror src add-ons kernel bus_managers ide ;
561	EnableWerror src add-ons kernel bus_managers isa ;
562	EnableWerror src add-ons kernel bus_managers pci ;
563	EnableWerror src add-ons kernel bus_managers ps2 ;
564	EnableWerror src add-ons kernel bus_managers random ;
565	EnableWerror src add-ons kernel bus_managers scsi ;
566	EnableWerror src add-ons kernel bus_managers tty ;
567	EnableWerror src add-ons kernel bus_managers usb ;
568	EnableWerror src add-ons kernel bus_managers virtio ;
569	EnableWerror src add-ons kernel busses agp_gart ;
570	EnableWerror src add-ons kernel busses ata ;
571	EnableWerror src add-ons kernel busses scsi ;
572	EnableWerror src add-ons kernel busses usb ;
573	EnableWerror src add-ons kernel console ;
574	EnableWerror src add-ons kernel cpu ;
575#	EnableWerror src add-ons kernel debugger ; # gcc2
576#	EnableWerror src add-ons kernel drivers audio ;
577	EnableWerror src add-ons kernel drivers bluetooth ;
578	EnableWerror src add-ons kernel drivers bus ;
579	EnableWerror src add-ons kernel drivers common ;
580	EnableWerror src add-ons kernel drivers disk ;
581	EnableWerror src add-ons kernel drivers dvb ;
582#	EnableWerror src add-ons kernel drivers graphics ;
583	EnableWerror src add-ons kernel drivers graphics intel_extreme ;
584#	EnableWerror src add-ons kernel drivers input ;
585	EnableWerror src add-ons kernel drivers joystick ;
586	EnableWerror src add-ons kernel drivers midi ;
587	EnableWerror src add-ons kernel drivers misc ;
588#	EnableWerror src add-ons kernel drivers network ;
589	EnableWerror src add-ons kernel drivers ports ;
590#	EnableWerror src add-ons kernel drivers power ;
591	EnableWerror src add-ons kernel drivers printer ;
592	EnableWerror src add-ons kernel drivers random ;
593	EnableWerror src add-ons kernel drivers tty ;
594	EnableWerror src add-ons kernel drivers video ;
595	EnableWerror src add-ons kernel file_systems bfs ;
596	EnableWerror src add-ons kernel file_systems cdda ;
597#	EnableWerror src add-ons kernel file_systems ext2 ;
598#	EnableWerror src add-ons kernel file_systems fat ;
599#	EnableWerror src add-ons kernel file_systems googlefs ;
600	EnableWerror src add-ons kernel file_systems iso9660 ;
601	EnableWerror src add-ons kernel file_systems layers ;
602	EnableWerror src add-ons kernel file_systems netfs ;
603	EnableWerror src add-ons kernel file_systems nfs ;
604	EnableWerror src add-ons kernel file_systems nfs4 ;
605#	EnableWerror src add-ons kernel file_systems ntfs ;
606	EnableWerror src add-ons kernel file_systems packagefs ;
607#	EnableWerror src add-ons kernel file_systems ramfs ;
608#	EnableWerror src add-ons kernel file_systems reiserfs ;
609	EnableWerror src add-ons kernel file_systems udf ;
610	EnableWerror src add-ons kernel file_systems userlandfs ;
611	EnableWerror src add-ons kernel generic ;
612#	EnableWerror src add-ons kernel network datalink_protocols ;
613	EnableWerror src add-ons kernel network devices ;
614	EnableWerror src add-ons kernel network dns_resolver ;
615	EnableWerror src add-ons kernel network notifications ;
616	EnableWerror src add-ons kernel network ppp ;
617	EnableWerror src add-ons kernel network protocols ;
618#	EnableWerror src add-ons kernel network stack ;
619	EnableWerror src add-ons kernel partitioning_systems ;
620	EnableWerror src add-ons kernel power ;
621	EnableWerror src add-ons locale ;
622	EnableWerror src add-ons mail_daemon ;
623	EnableWerror src add-ons media media-add-ons demultiplexer ;
624	EnableWerror src add-ons media media-add-ons dvb ;
625	EnableWerror src add-ons media media-add-ons esound_sink ;
626	EnableWerror src add-ons media media-add-ons finepix_webcam ;
627	EnableWerror src add-ons media media-add-ons firewire_dv ;
628	EnableWerror src add-ons media media-add-ons legacy ;
629	EnableWerror src add-ons media media-add-ons mixer ;
630	EnableWerror src add-ons media media-add-ons multi_audio ;
631	EnableWerror src add-ons media media-add-ons opensound ;
632	EnableWerror src add-ons media media-add-ons radeon ;
633	EnableWerror src add-ons media media-add-ons reader ;
634	EnableWerror src add-ons media media-add-ons tone_producer_demo ;
635	EnableWerror src add-ons media media-add-ons usb_vision ;
636#	EnableWerror src add-ons media media-add-ons usb_webcam ;
637	EnableWerror src add-ons media media-add-ons video_mixer ;
638#	EnableWerror src add-ons media media-add-ons video_producer_demo ;
639	EnableWerror src add-ons media media-add-ons videowindow ;
640	EnableWerror src add-ons media media-add-ons writer ;
641	EnableWerror src add-ons media plugins aiff_reader ;
642	EnableWerror src add-ons media plugins ape_reader ;
643#	EnableWerror src add-ons media plugins asf_reader ;
644	EnableWerror src add-ons media plugins au_reader ;
645#	EnableWerror src add-ons media plugins avi_reader ;
646#	EnableWerror src add-ons media plugins ffmpeg ;
647#	EnableWerror src add-ons media plugins matroska ;
648#	EnableWerror src add-ons media plugins mov_reader ;
649	EnableWerror src add-ons media plugins mp3_decoder ;
650#	EnableWerror src add-ons media plugins mp3_reader ;
651	EnableWerror src add-ons media plugins mp4_reader ;
652	EnableWerror src add-ons media plugins musepack ;
653#	EnableWerror src add-ons media plugins ogg ;
654#	EnableWerror src add-ons media plugins raw_decoder ;
655#	EnableWerror src add-ons media plugins speex ;
656	EnableWerror src add-ons media plugins theora ;
657	EnableWerror src add-ons media plugins vorbis ;
658#	EnableWerror src add-ons media plugins wav_reader ;
659	EnableWerror src add-ons print ;
660	EnableWerror src add-ons screen_savers ;
661	EnableWerror src add-ons tracker ;
662	EnableWerror src add-ons translators bmp ;
663	EnableWerror src add-ons translators exr ;
664	EnableWerror src add-ons translators gif ;
665	EnableWerror src add-ons translators hvif ;
666	EnableWerror src add-ons translators ico ;
667	EnableWerror src add-ons translators jpeg ;
668#	EnableWerror src add-ons translators jpeg2000 ;
669	EnableWerror src add-ons translators pcx ;
670	EnableWerror src add-ons translators png ;
671	EnableWerror src add-ons translators ppm ;
672	EnableWerror src add-ons translators raw ;
673	EnableWerror src add-ons translators rtf ;
674	EnableWerror src add-ons translators sgi ;
675	EnableWerror src add-ons translators shared ;
676	EnableWerror src add-ons translators stxt ;
677	EnableWerror src add-ons translators tga ;
678	EnableWerror src add-ons translators tiff ;
679	EnableWerror src add-ons translators wonderbrush ;
680	EnableWerror src add-ons print ;
681	EnableWerror src bin desklink ;
682	EnableWerror src bin multiuser ;
683	EnableWerror src bin package ;
684	EnableWerror src bin package_repo ;
685	EnableWerror src bin pkgman ;
686	EnableWerror src libs bsd ;
687	EnableWerror src apps ;
688	EnableWerror src kits ;
689	EnableWerror src preferences ;
690	EnableWerror src servers ;
691	EnableWerror src system boot ;
692#	EnableWerror src system kernel ;
693	EnableWerror src system libroot add-ons ;
694	EnableWerror src system libroot os ;
695	EnableWerror src system libroot posix locale ;
696	EnableWerror src system libroot posix wchar ;
697	EnableWerror src system runtime_loader ;
698}
699
700
701rule MultiArchIfPrimary ifValue : elseValue : architecture
702{
703	# MultiArchIfPrimary <ifValue> : <elseValue>
704	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
705	#
706	# Returns one of the two given values depending on whether
707	# <architecture> is the primary packaging architecture.
708
709	architecture ?= $(TARGET_PACKAGING_ARCH) ;
710
711	if $(architecture) = $(TARGET_PACKAGING_ARCHS[1]) {
712		return $(ifValue) ;
713	}
714	return $(elseValue) ;
715}
716
717
718rule MultiArchConditionalGristFiles files : primaryGrist : secondaryGrist
719	: architecture
720{
721	# MultiArchConditionalGristFiles <files> : <primaryGrist>
722	#	: <secondaryGrist> [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
723	#
724	# Returns <files> with their grist set to either <primaryGrist> or
725	# <secondaryGrist> depending on whether <architecture> is the primary
726	# packaging architecture.
727
728	architecture ?= $(TARGET_PACKAGING_ARCH) ;
729
730	local grist = [ MultiArchIfPrimary $(primaryGrist) : $(secondaryGrist)
731		: $(architecture) ] ;
732	return $(files:G=$(grist:E=)) ;
733}
734
735
736rule MultiArchDefaultGristFiles files : gristPrefix : architecture
737{
738	# MultiArchDefaultGristFiles <files> : <gristPrefix>
739	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
740	#
741	# Convenient shorthand for MultiArchConditionalGristFiles for the common
742	# case that for a secondary packaging architecture the packaging
743	# architecture name shall be appended to the grist while it shall be omitted
744	# for the primary packaging architecture. IOW, if architecture is the
745	# primary packaging architecture, <files> are returned with their grist set
746	# to <gristPrefix>, otherwise <files> are returned with their grist set to
747	# <gristPrefix>!<architecture> respectively <architecture> (if <gristPrefix>
748	# is empty).
749
750	architecture ?= $(TARGET_PACKAGING_ARCH) ;
751
752	local secondaryGrist = $(gristPrefix)!$(architecture) ;
753	secondaryGrist ?= $(architecture) ;
754
755	return [ MultiArchConditionalGristFiles $(files) : $(gristPrefix) :
756		$(secondaryGrist) : $(architecture) ] ;
757}
758
759
760rule MultiArchSubDirSetup architectures
761{
762	# MultiArchSubDirSetup <architectures> ;
763	#
764	# For each of the given packaging architectures <architectures> that are
765	# in the packaging architectures configured for the build (or all configured
766	# packaging architectures, if <architectures> is empty) an object is
767	# prepared that can be used for an "on ... { ... }" block to set up subdir
768	# variables for the respective packaging architecture. Most notably
769	# TARGET_PACKAGING_ARCH, TARGET_ARCH are set to the values for the
770	# respective packaging architecture. The per-subdir variables SOURCE_GRIST,
771	# LOCATE_TARGET, LOCATE_SOURCE, SEARCH_SOURCE, *_LOCATE_TARGET, are reset.
772	# All SUBDIR* and config variables are set to the values they had when this
773	# rule was invoked.
774
775	local result ;
776	architectures ?= $(TARGET_PACKAGING_ARCHS) ;
777	local architecture ;
778	for architecture in $(architectures) {
779		if ! $(architecture) in $(TARGET_PACKAGING_ARCHS) {
780			continue ;
781		}
782
783		local architectureObject = $(architecture:G=<arch-object>) ;
784		result += $(architectureObject) ;
785
786		# Set the variables that default to the values of the respective
787		# variables for the primary architecture.
788		TARGET_PACKAGING_ARCH on $(architectureObject) = $(architecture) ;
789
790		local var ;
791		for var in TARGET_ARCH {
792			$(var) on $(architectureObject) = $($(var)_$(architecture)) ;
793		}
794
795		# Clone the current config variable values and the variables SubDir
796		# resets.
797		for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) {
798			$(var) on $(architectureObject) = $($(var)) ;
799		}
800
801		# adjust SOURCE_GRIST and HDRGRIST
802		SOURCE_GRIST on $(architectureObject)
803			= $(SOURCE_GRIST:E=)!$(architecture) ;
804
805		HDRGRIST on $(architectureObject)
806			= $(HDRGRIST:E=)!$(architecture) ;
807
808		# Adjust the subdir's object dirs that are architecture dependent. To
809		# avoid duplicating the code from SetupObjectsDir, we call it. Since it
810		# sets global variables, we set these variables on our object, call
811		# SetupObjectsDir in an "on" block, and grab the new variable values.
812		local hostTarget = HOST TARGET ;
813		local objectDirVars =
814			COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS)
815			;
816		objectDirVars =
817			COMMON_PLATFORM_LOCATE_TARGET
818			$(hostTarget)_$(objectDirVars)_LOCATE_TARGET
819			LOCATE_TARGET
820			LOCATE_SOURCE
821			SEARCH_SOURCE
822			;
823
824		for var in $(objectDirVars) {
825			$(var) on $(architectureObject) = ;
826		}
827
828		on $(architectureObject) {
829			SetupObjectsDir ;
830
831			for var in $(objectDirVars) {
832				$(var) on $(architectureObject) = $($(var)) ;
833			}
834		}
835	}
836
837	return $(result) ;
838}
839