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