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