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