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