ArchitectureRules revision 91182127
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)) = 0 {
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	local debugBootLoader
279		= [ ConfigVar DEBUG : HAIKU_TOP src system boot loader ] ;
280
281	switch $(cpu) {
282		case ppc :
283			HAIKU_BOOT_PLATFORM ?= openfirmware ;
284			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
285			# offset in floppy image (>= sizeof(haiku_loader))
286			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
287
288		case arm :
289			switch $(HAIKU_BOOT_BOARD) {
290				case beagle :
291				{
292					HAIKU_BOOT_PLATFORM ?= u-boot ;
293					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
294				}
295				case neo_freerunner :
296				{
297					HAIKU_BOOT_PLATFORM ?= u-boot ;
298					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
299				}
300				case overo :
301				{
302					HAIKU_BOOT_PLATFORM ?= u-boot ;
303					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
304				}
305				case raspberry_pi :
306				{
307					# For now rpi has a custom non u-boot loader
308					HAIKU_BOOT_PLATFORM ?= raspberrypi_arm ;
309					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
310				}
311				case verdex :
312				{
313					HAIKU_BOOT_PLATFORM ?= u-boot ;
314					HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
315				}
316				case * :
317				{
318					Exit "Set HAIKU_BOOT_BOARD for your target ARM device!" ;
319				}
320			}
321
322			# offset in floppy image (>= sizeof(haiku_loader))
323			HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
324
325		case x86 :
326			HAIKU_BOOT_PLATFORM = bios_ia32 ;
327			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
328			# offset in floppy image (>= sizeof(haiku_loader))
329			if $(debugBootLoader) {
330				HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 350 ; # in kB
331			} else {
332				HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 300 ; # in kB
333			}
334
335			# nasm is required for target arch x86
336			if ! $(HAIKU_NASM) {
337				Exit "HAIKU_NASM not set. Please re-run configure." ;
338			}
339
340		case x86_64 :
341			# x86_64 completely shares the x86 bootloader.
342			HAIKU_BOOT_PLATFORM = bios_ia32 ;
343			HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
344			# offset in floppy image (>= sizeof(haiku_loader))
345			if $(debugBootLoader) {
346				HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 350 ; # in kB
347			} else {
348				HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 300 ; # in kB
349			}
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)) = 0 {
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	HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbegin.o
487		<src!system!glue!$(architecture)>haiku_version_glue.o ;
488	HAIKU_KERNEL_ADDON_END_GLUE_CODE
489		= $(HAIKU_GCC_LIBGCC_$(architecture)) <$(architecture)>crtend.o ;
490}
491
492
493rule ArchitectureSetupWarnings architecture
494{
495	# ArchitectureSetupWarnings <architecture> ;
496	#
497	# Sets up compiler warnings and error flags for various subdirectories for
498	# the given packaging architecture.
499
500	local cpu = $(HAIKU_CPU_$(architecture)) ;
501	switch $(cpu) {
502		case arm :
503			return ;
504				# we use #warning as placeholders for things to write...
505		case m68k :
506			return ;
507				# we use #warning as placeholders for things to write...
508	}
509
510	# enable -Werror for certain parts of the source tree
511	HAIKU_WERROR_ARCH = $(architecture) ;
512
513	rule EnableWerror dirTokens : scope {
514		# Clang gives way more warnings than GCC, so that code won't compile
515		# -Werror when using Clang.
516		if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
517			SetConfigVar WARNINGS : HAIKU_TOP $(dirTokens) : treatAsErrors
518				: $(scope) ;
519		}
520	}
521
522	# Work-around for GCC 2 problem -- despite -Wno-multichar it reports
523	# multichar warnings in headers/private/kernel/debugger_keymaps.h included
524	# by src/system/kernel/arch/x86/arch_debug_console.cpp.
525	local gccVersion = $(HAIKU_GCC_VERSION_$(architecture)) ;
526	if $(gccVersion[1]) = 2 {
527		local file = <src!system!kernel!arch!x86>arch_debug_console.o ;
528		WARNINGS on $(file) = $(WARNINGS) ;
529	}
530
531	if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 {
532		# We need -integrated-as, as otherwise Clang uses GCC as assembler and
533		# passes -fheinous-gnu-extensions to GCC, which GCC does not understand
534		# then errors out.
535		AppendToConfigVar CCFLAGS :
536			HAIKU_TOP src system libroot posix glibc :
537			-integrated-as -fgnu89-inline -fheinous-gnu-extensions : global ;
538	}
539
540	EnableWerror src add-ons accelerants 3dfx ;
541	EnableWerror src add-ons accelerants ati ;
542	EnableWerror src add-ons accelerants common ;
543	EnableWerror src add-ons accelerants et6x00 ;
544#	EnableWerror src add-ons accelerants intel_extreme ;
545#	EnableWerror src add-ons accelerants matrox ;
546	EnableWerror src add-ons accelerants neomagic ;
547#	EnableWerror src add-ons accelerants nvidia ;
548	EnableWerror src add-ons accelerants nvidia_gpgpu ;
549#	EnableWerror src add-ons accelerants radeon ;
550#	EnableWerror src add-ons accelerants radeon_hd ;
551	EnableWerror src add-ons accelerants s3 ;
552	EnableWerror src add-ons accelerants skeleton ;
553	EnableWerror src add-ons accelerants vesa ;
554	EnableWerror src add-ons accelerants via ;
555	EnableWerror src add-ons accelerants vmware ;
556	EnableWerror src add-ons bluetooth ;
557	EnableWerror src add-ons decorators ;
558	EnableWerror src add-ons disk_systems ;
559	EnableWerror src add-ons input_server devices ;
560#	EnableWerror src add-ons input_server filters ;
561#	EnableWerror src add-ons input_server methods ;
562	EnableWerror src add-ons kernel bluetooth ;
563#	EnableWerror src add-ons kernel bus_managers acpi ;
564	EnableWerror src add-ons kernel bus_managers agp_gart ;
565	EnableWerror src add-ons kernel bus_managers ata ;
566	EnableWerror src add-ons kernel bus_managers config_manager ;
567#	EnableWerror src add-ons kernel bus_managers firewire ;
568	EnableWerror src add-ons kernel bus_managers isa ;
569	EnableWerror src add-ons kernel bus_managers pci ;
570#	EnableWerror src add-ons kernel bus_managers ps2 ; # gcc2
571	EnableWerror src add-ons kernel bus_managers scsi ;
572	EnableWerror src add-ons kernel bus_managers usb ;
573	EnableWerror src add-ons kernel busses agp_gart ;
574	EnableWerror src add-ons kernel busses ata ;
575	EnableWerror src add-ons kernel busses scsi ;
576	EnableWerror src add-ons kernel busses usb ;
577	EnableWerror src add-ons kernel console ;
578	EnableWerror src add-ons kernel cpu ;
579#	EnableWerror src add-ons kernel debugger ; # gcc2
580#	EnableWerror src add-ons kernel drivers audio ;
581	EnableWerror src add-ons kernel drivers bluetooth ;
582	EnableWerror src add-ons kernel drivers bus ;
583	EnableWerror src add-ons kernel drivers common ;
584	EnableWerror src add-ons kernel drivers disk ;
585	EnableWerror src add-ons kernel drivers dvb ;
586#	EnableWerror src add-ons kernel drivers graphics ;
587#	EnableWerror src add-ons kernel drivers input ;
588	EnableWerror src add-ons kernel drivers joystick ;
589	EnableWerror src add-ons kernel drivers midi ;
590	EnableWerror src add-ons kernel drivers misc ;
591#	EnableWerror src add-ons kernel drivers network ;
592	EnableWerror src add-ons kernel drivers ports ;
593#	EnableWerror src add-ons kernel drivers power ;
594	EnableWerror src add-ons kernel drivers printer ;
595	EnableWerror src add-ons kernel drivers random ;
596	EnableWerror src add-ons kernel drivers tty ;
597	EnableWerror src add-ons kernel drivers video ;
598	EnableWerror src add-ons kernel file_systems bfs ;
599	EnableWerror src add-ons kernel file_systems cdda ;
600#	EnableWerror src add-ons kernel file_systems ext2 ;
601#	EnableWerror src add-ons kernel file_systems fat ;
602#	EnableWerror src add-ons kernel file_systems googlefs ;
603	EnableWerror src add-ons kernel file_systems iso9660 ;
604	EnableWerror src add-ons kernel file_systems layers ;
605	EnableWerror src add-ons kernel file_systems netfs ;
606	EnableWerror src add-ons kernel file_systems nfs ;
607	EnableWerror src add-ons kernel file_systems nfs4 ;
608#	EnableWerror src add-ons kernel file_systems ntfs ;
609	EnableWerror src add-ons kernel file_systems packagefs ;
610	EnableWerror src add-ons kernel file_systems ramfs ;
611#	EnableWerror src add-ons kernel file_systems reiserfs ;
612	EnableWerror src add-ons kernel file_systems udf ;
613	EnableWerror src add-ons kernel file_systems userlandfs ;
614	EnableWerror src add-ons kernel generic ;
615#	EnableWerror src add-ons kernel network datalink_protocols ;
616	EnableWerror src add-ons kernel network devices ;
617	EnableWerror src add-ons kernel network dns_resolver ;
618	EnableWerror src add-ons kernel network notifications ;
619	EnableWerror src add-ons kernel network ppp ;
620	EnableWerror src add-ons kernel network protocols ;
621#	EnableWerror src add-ons kernel network stack ;
622	EnableWerror src add-ons kernel partitioning_systems ;
623	EnableWerror src add-ons kernel power ;
624	EnableWerror src add-ons locale ;
625	EnableWerror src add-ons mail_daemon ;
626	EnableWerror src add-ons media media-add-ons demultiplexer ;
627	EnableWerror src add-ons media media-add-ons dvb ;
628	EnableWerror src add-ons media media-add-ons esound_sink ;
629	EnableWerror src add-ons media media-add-ons finepix_webcam ;
630	EnableWerror src add-ons media media-add-ons firewire_dv ;
631	EnableWerror src add-ons media media-add-ons legacy ;
632	EnableWerror src add-ons media media-add-ons mixer ;
633	EnableWerror src add-ons media media-add-ons multi_audio ;
634	EnableWerror src add-ons media media-add-ons opensound ;
635	EnableWerror src add-ons media media-add-ons radeon ;
636	EnableWerror src add-ons media media-add-ons reader ;
637	EnableWerror src add-ons media media-add-ons tone_producer_demo ;
638	EnableWerror src add-ons media media-add-ons usb_vision ;
639#	EnableWerror src add-ons media media-add-ons usb_webcam ;
640	EnableWerror src add-ons media media-add-ons video_mixer ;
641#	EnableWerror src add-ons media media-add-ons video_producer_demo ;
642	EnableWerror src add-ons media media-add-ons videowindow ;
643	EnableWerror src add-ons media media-add-ons writer ;
644	EnableWerror src add-ons media plugins ac3_decoder ;
645	EnableWerror src add-ons media plugins aiff_reader ;
646	EnableWerror src add-ons media plugins ape_reader ;
647#	EnableWerror src add-ons media plugins asf_reader ;
648	EnableWerror src add-ons media plugins au_reader ;
649#	EnableWerror src add-ons media plugins avi_reader ;
650#	EnableWerror src add-ons media plugins ffmpeg ;
651#	EnableWerror src add-ons media plugins matroska ;
652#	EnableWerror src add-ons media plugins mov_reader ;
653	EnableWerror src add-ons media plugins mp3_decoder ;
654#	EnableWerror src add-ons media plugins mp3_reader ;
655	EnableWerror src add-ons media plugins mp4_reader ;
656	EnableWerror src add-ons media plugins musepack ;
657#	EnableWerror src add-ons media plugins ogg ;
658#	EnableWerror src add-ons media plugins raw_decoder ;
659#	EnableWerror src add-ons media plugins speex ;
660	EnableWerror src add-ons media plugins theora ;
661	EnableWerror src add-ons media plugins vorbis ;
662#	EnableWerror src add-ons media plugins wav_reader ;
663	EnableWerror src add-ons media plugins xvid_decoder ;
664	EnableWerror src add-ons print ;
665	EnableWerror src add-ons screen_savers ;
666	EnableWerror src add-ons tracker ;
667	EnableWerror src add-ons translators bmp ;
668#	EnableWerror src add-ons translators exr ;
669	EnableWerror src add-ons translators gif ;
670#	EnableWerror src add-ons translators hpgs ;
671	EnableWerror src add-ons translators hvif ;
672	EnableWerror src add-ons translators ico ;
673#	EnableWerror src add-ons translators jpeg ; # gcc2
674	EnableWerror src add-ons translators jpeg2000 ;
675	EnableWerror src add-ons translators pcx ;
676#	EnableWerror src add-ons translators png ; # gcc2
677	EnableWerror src add-ons translators ppm ;
678	EnableWerror src add-ons translators raw ;
679	EnableWerror src add-ons translators rtf ;
680	EnableWerror src add-ons translators sgi ;
681	EnableWerror src add-ons translators shared ;
682#	EnableWerror src add-ons translators stxt ;
683	EnableWerror src add-ons translators tga ;
684	EnableWerror src add-ons translators tiff ;
685#	EnableWerror src add-ons translators wonderbrush ;
686	EnableWerror src add-ons print ;
687	EnableWerror src bin desklink ;
688	EnableWerror src bin multiuser ;
689	EnableWerror src bin package ;
690	EnableWerror src bin package_repo ;
691	EnableWerror src bin pkgman ;
692	EnableWerror src libs bsd ;
693	EnableWerror src apps ;
694	EnableWerror src kits ;
695	EnableWerror src preferences ;
696	EnableWerror src servers ;
697	EnableWerror src system boot ;
698	EnableWerror src system kernel ;
699	EnableWerror src system libroot add-ons ;
700	EnableWerror src system libroot os ;
701	EnableWerror src system libroot posix locale ;
702	EnableWerror src system libroot posix wchar ;
703	EnableWerror src system runtime_loader ;
704}
705
706
707rule MultiArchIfPrimary ifValue : elseValue : architecture
708{
709	# MultiArchIfPrimary <ifValue> : <elseValue>
710	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
711	#
712	# Returns one of the two given values depending on whether
713	# <architecture> is the primary packaging architecture.
714
715	architecture ?= $(TARGET_PACKAGING_ARCH) ;
716
717	if $(architecture) = $(TARGET_PACKAGING_ARCHS[1]) {
718		return $(ifValue) ;
719	}
720	return $(elseValue) ;
721}
722
723
724rule MultiArchConditionalGristFiles files : primaryGrist : secondaryGrist
725	: architecture
726{
727	# MultiArchConditionalGristFiles <files> : <primaryGrist>
728	#	: <secondaryGrist> [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
729	#
730	# Returns <files> with their grist set to either <primaryGrist> or
731	# <secondaryGrist> depending on whether <architecture> is the primary
732	# packaging architecture.
733
734	architecture ?= $(TARGET_PACKAGING_ARCH) ;
735
736	local grist = [ MultiArchIfPrimary $(primaryGrist) : $(secondaryGrist)
737		: $(architecture) ] ;
738	return $(files:G=$(grist:E=)) ;
739}
740
741
742rule MultiArchDefaultGristFiles files : gristPrefix : architecture
743{
744	# MultiArchDefaultGristFiles <files> : <gristPrefix>
745	#	[ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ;
746	#
747	# Convenient shorthand for MultiArchConditionalGristFiles for the common
748	# case that for a secondary packaging architecture the packaging
749	# architecture name shall be appended to the grist while it shall be omitted
750	# for the primary packaging architecture. IOW, if architecture is the
751	# primary packaging architecture, <files> are returned with their grist set
752	# to <gristPrefix>, otherwise <files> are returned with their grist set to
753	# <gristPrefix>!<architecture> respectively <architecture> (if <gristPrefix>
754	# is empty).
755
756	architecture ?= $(TARGET_PACKAGING_ARCH) ;
757
758	local secondaryGrist = $(gristPrefix)!$(architecture) ;
759	secondaryGrist ?= $(architecture) ;
760
761	return [ MultiArchConditionalGristFiles $(files) : $(gristPrefix) :
762		$(secondaryGrist) : $(architecture) ] ;
763}
764
765
766rule MultiArchSubDirSetup architectures
767{
768	# MultiArchSubDirSetup <architectures> ;
769	#
770	# For each of the given packaging architectures <architectures> that are
771	# in the packaging architectures configured for the build (or all configured
772	# packaging architectures, if <architectures> is empty) an object is
773	# prepared that can be used for an "on ... { ... }" block to set up subdir
774	# variables for the respective packaging architecture. Most notably
775	# TARGET_PACKAGING_ARCH, TARGET_ARCH, TARGET_LIBSUPC++, and TARGET_LIBSTDC++
776	# are set to the values for the respective packaging architecture. The
777	# per-subdir variables SOURCE_GRIST, LOCATE_TARGET, LOCATE_SOURCE,
778	# SEARCH_SOURCE, *_LOCATE_TARGET, are reset. All SUBDIR* and config
779	# variables are set to the values they had when this rule was invoked.
780
781	local result ;
782	architectures ?= $(TARGET_PACKAGING_ARCHS) ;
783	local architecture ;
784	for architecture in $(architectures) {
785		if ! $(architecture) in $(TARGET_PACKAGING_ARCHS) {
786			continue ;
787		}
788
789		local architectureObject = $(architecture:G=<arch-object>) ;
790		result += $(architectureObject) ;
791
792		# Set the variables that default to the values of the respective
793		# variables for the primary architecture.
794		TARGET_PACKAGING_ARCH on $(architectureObject) = $(architecture) ;
795
796		local var ;
797		for var in TARGET_ARCH TARGET_LIBSUPC++ TARGET_LIBSTDC++ {
798			$(var) on $(architectureObject) = $($(var)_$(architecture)) ;
799		}
800
801		# Clone the current config variable values and the variables SubDir
802		# resets.
803		for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) {
804			$(var) on $(architectureObject) = $($(var)) ;
805		}
806
807		# adjust SOURCE_GRIST
808		SOURCE_GRIST on $(architectureObject)
809			= $(SOURCE_GRIST:E=)!$(architecture) ;
810
811		# Adjust the subdir's object dirs that are architecture dependent. To
812		# avoid duplicating the code from SetupObjectsDir, we call it. Since it
813		# sets global variables, we set these variables on our object, call
814		# SetupObjectsDir in an "on" block, and grab the new variable values.
815		local hostTarget = HOST TARGET ;
816		local objectDirVars =
817			COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS)
818			;
819		objectDirVars =
820			COMMON_PLATFORM_LOCATE_TARGET
821			$(hostTarget)_$(objectDirVars)_LOCATE_TARGET
822			LOCATE_TARGET
823			LOCATE_SOURCE
824			SEARCH_SOURCE
825			;
826
827		for var in $(objectDirVars) {
828			$(var) on $(architectureObject) = ;
829		}
830
831		on $(architectureObject) {
832			SetupObjectsDir ;
833
834			for var in $(objectDirVars) {
835				$(var) on $(architectureObject) = $($(var)) ;
836			}
837		}
838	}
839
840	return $(result) ;
841}
842