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