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