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