BuildSetup revision 20c61bb7
1# Variable naming conventions:
2# TARGET_*:	A build system variable specifying a property for building for
3#			the target platform (usually Haiku). E.g. TARGET_CC specifies the
4#			compiler when building a target for the target platform.
5# HOST_*:	A build system variable specifying a property of the platform
6#			hosting the build. E.g. HOST_CC specifies the compiler when
7#			building a target for the host platform (a build tool for
8#			instance).
9# HAIKU_*:	A build system variable specifying a build system property. Usually
10#			directory paths and the like.
11
12
13# The Haiku (base) version. For development builds the revision will be
14# attached.
15HAIKU_VERSION = r1~alpha4_pm ;
16
17
18#pragma mark - container settings
19
20# Haiku image
21HAIKU_IMAGE_CONTAINER_NAME = haiku-image-container ;
22HAIKU_CONTAINER_GRIST on $(HAIKU_IMAGE_CONTAINER_NAME) = HaikuImage ;
23HAIKU_INCLUDE_IN_CONTAINER_VAR on $(HAIKU_IMAGE_CONTAINER_NAME)
24	= HAIKU_INCLUDE_IN_IMAGE ;
25HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_IMAGE_CONTAINER_NAME)
26	= HAIKU_IMAGE_INSTALL_TARGETS ;
27HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(HAIKU_IMAGE_CONTAINER_NAME)
28	= system non-packaged ;
29
30# network boot archive
31HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME = haiku-netboot-archive-container ;
32HAIKU_CONTAINER_GRIST on $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
33	= NetBootArchive ;
34# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
35HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
36	= HAIKU_NET_BOOT_ARCHIVE_INSTALL_TARGETS ;
37HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
38	= system ;
39
40# boot floppy
41HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME = haiku-boot-floppy-container ;
42HAIKU_CONTAINER_GRIST on $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
43	= FloppyBootImage ;
44# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
45HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
46	= HAIKU_FLOPPY_BOOT_IMAGE_INSTALL_TARGETS ;
47HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
48	= system ;
49
50# boot CD image
51HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME = haiku-boot-cd-container ;
52HAIKU_CONTAINER_GRIST on $(HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME) = CDBootImage ;
53# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
54HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME)
55	= HAIKU_CD_BOOT_IMAGE_INSTALL_TARGETS ;
56HAIKU_CONTAINER_SYSTEM_DIR_TOKENS on $(HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME)
57	= system ;
58
59# Haiku image/install defaults
60HAIKU_DEFAULT_IMAGE_NAME = haiku.image ;
61HAIKU_DEFAULT_IMAGE_DIR = $(HAIKU_OUTPUT_DIR) ;
62HAIKU_DEFAULT_VMWARE_IMAGE_NAME = haiku.vmdk ;
63HAIKU_DEFAULT_INSTALL_DIR = /Haiku ;
64HAIKU_DEFAULT_IMAGE_SIZE ?= 300 ; # 300 MB
65HAIKU_DEFAULT_IMAGE_LABEL ?= Haiku ;
66
67# Haiku CD defaults
68HAIKU_DEFAULT_CD_NAME = haiku-cd.iso ;
69HAIKU_DEFAULT_CD_DIR = $(HAIKU_OUTPUT_DIR) ;
70HAIKU_DEFAULT_CD_LABEL = Haiku ;
71
72# Haiku Anyboot defaults
73HAIKU_DEFAULT_ANYBOOT_NAME = haiku-anyboot.iso ;
74HAIKU_DEFAULT_ANYBOOT_DIR = $(HAIKU_OUTPUT_DIR) ;
75HAIKU_DEFAULT_ANYBOOT_LABEL ?= Haiku ;
76
77# Haiku MMC defaults
78HAIKU_DEFAULT_MMC_IMAGE_NAME = haiku-mmc.image ;
79HAIKU_DEFAULT_MMC_DIR = $(HAIKU_OUTPUT_DIR) ;
80HAIKU_DEFAULT_MMC_LABEL ?= Haiku ;
81
82# analyze and optionally replace jam's target parameters
83ProcessCommandLineArguments ;
84
85
86# supported debug levels
87HAIKU_DEBUG_LEVELS = 0 1 2 3 4 5 ;
88
89# BeOS, BONE, Dan0 compatible platforms
90HAIKU_BEOS_COMPATIBLE_PLATFORMS = haiku r5 bone dano haiku_host ;
91HAIKU_BONE_COMPATIBLE_PLATFORMS = haiku bone dano haiku_host ;
92HAIKU_DANO_COMPATIBLE_PLATFORMS = haiku dano haiku_host ;
93HAIKU_HAIKU_COMPATIBLE_PLATFORMS = haiku haiku_host ;
94
95# configuration header directories
96HAIKU_CONFIG_HEADERS = [ FDirName $(HAIKU_TOP) build user_config_headers ]
97	[ FDirName $(HAIKU_TOP) build config_headers ] ;
98
99
100# object directories common to all architectures
101HAIKU_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) haiku ] ;
102HAIKU_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HAIKU_OBJECT_BASE_DIR) common ] ;
103
104
105#pragma mark - haiku target platform settings
106
107
108local architecture ;
109for architecture in $(HAIKU_PACKAGING_ARCHS) {
110	ArchitectureSetup $(architecture) ;
111}
112
113# TODO: Might not be needed anymore.
114if $(HAIKU_HOST_BUILD_ONLY) = 1 {
115	HAIKU_GCC_VERSION = 0 0 0 ;
116}
117
118if $(HAIKU_PACKAGING_ARCH) {
119	KernelArchitectureSetup $(HAIKU_PACKAGING_ARCH) ;
120}
121
122# define primary packaging architecture macro
123HAIKU_DEFINES = __HAIKU_PRIMARY_PACKAGING_ARCH=\\\"$(HAIKU_PACKAGING_ARCH)\\\" ;
124
125
126# distro compatibility level defines
127HAIKU_DISTRO_COMPATIBILITY ?= "default" ;
128switch $(HAIKU_DISTRO_COMPATIBILITY) {
129	case official :
130		HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_OFFICIAL ;
131		HAIKU_INCLUDE_TRADEMARKS = "" ;
132	case compatible :
133		HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_COMPATIBLE ;
134		HAIKU_INCLUDE_TRADEMARKS = "" ;
135	case "default" :
136		HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_DEFAULT ;
137		HAIKU_INCLUDE_TRADEMARKS = ;
138	case * :
139		Exit "Invalid value for HAIKU_DISTRO_COMPATIBILITY:"
140			$(HAIKU_DISTRO_COMPATIBILITY) ;
141}
142
143# network libraries
144HAIKU_NETWORK_LIBS = network ;
145HAIKU_NETAPI_LIB = bnetapi ;
146HAIKU_SELECT_UNAME_ETC_LIB = ;	# libroot, against which we link anyway
147
148HAIKU_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
149
150# TODO: The version stuff should probably go into a separate file and be made
151# available as macro, too.
152# Set our version number if not already set and mark it as a developer build
153if ! $(HAIKU_BUILD_VERSION) {
154	HAIKU_BUILD_VERSION ?= "1 0 0 a 1" ;
155	HAIKU_BUILD_DESCRIPTION ?= "Developer Build" ;
156}
157
158# If HAIKU_BUILD_VERSION is set, but HAIKU_BUILD_DESCRIPTION isn't, mark it as
159# an unknown build.
160HAIKU_BUILD_DESCRIPTION ?= "Unknown Build" ;
161
162
163#pragma mark - host platform settings
164
165
166# determine the endianness of the host
167switch $(HOST_GCC_MACHINE) {
168	case amd64-*	: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
169	case i?86-*		: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
170	case powerpc-*	: HAIKU_HOST_IS_BIG_ENDIAN = 1 ;
171	case x86_64-*	: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
172
173	# the following are rather unlikely as hosts ...
174	case arm-*		: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
175	case armv7l-*	: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
176	case armv7hl-*	: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
177	case armv7b-*	: HAIKU_HOST_IS_BIG_ENDIAN = 1 ;
178	case arm64-*	: HAIKU_HOST_IS_BIG_ENDIAN = 0 ;
179	case m68k-*		: HAIKU_HOST_IS_BIG_ENDIAN = 1 ;
180	case *			: Exit "Unsupported gcc host machine:" $(HOST_GCC_MACHINE) ;
181}
182
183# analyze the host gcc machine spec to find out about 64-bitness
184HOST_PLATFORM_IS_64_BIT = ;
185switch $(HOST_GCC_MACHINE) {
186	case amd64-* :				HOST_PLATFORM_IS_64_BIT = 1 ;
187	case i686-apple-darwin10 :	HOST_PLATFORM_IS_64_BIT = 1 ;
188	case i686-apple-darwin11 :	HOST_PLATFORM_IS_64_BIT = 1 ;
189	case x86_64-* :				HOST_PLATFORM_IS_64_BIT = 1 ;
190	case aarch64-* :			HOST_PLATFORM_IS_64_BIT = 1 ;
191}
192
193# If HAIKU_HOST_USE_32BIT is set, add the required gcc base flag (the LD flag
194# is set later), or, if the architecture isn't actually 64 bit, clear
195# HAIKU_HOST_USE_32BIT.
196# Afterwards HOST_PLATFORM_IS_64_BIT will indicate whether the architecture is
197# effectively (i.e. when using the compiler/linker flags) 64 bit and
198# HAIKU_HOST_USE_32BIT will be set, iff the architecture is really 64 bit and
199# 32 bit mode was requested.
200if $(HAIKU_HOST_USE_32BIT) = 1 {
201	if $(HOST_PLATFORM_IS_64_BIT) {
202		# enable GCC -m32 option
203		HOST_GCC_BASE_FLAGS = -m32 ;
204		HOST_PLATFORM_IS_64_BIT = ;
205	} else {
206		HAIKU_HOST_USE_32BIT = 0 ;
207	}
208}
209
210
211# save jam's variables for the build platform
212HOST_AR				?= $(AR) ;
213HOST_CC				?= $(CC) ;
214HOST_C++			?= $(C++) ;
215HOST_LINK			?= $(LINK) ;
216HOST_RANLIB			?= $(RANLIB) ;
217HOST_CPPFLAGS		?= $(CPPFLAGS) ;
218HOST_CCFLAGS		?= $(HOST_GCC_BASE_FLAGS) $(CCFLAGS) ;
219HOST_C++FLAGS		?= $(HOST_GCC_BASE_FLAGS) $(C++FLAGS) ;
220HOST_LDFLAGS		?= $(LDFLAGS) ;
221HOST_LINKFLAGS		?= $(HOST_GCC_BASE_FLAGS) $(LINKFLAGS) ;
222HOST_DEFINES		?= $(DEFINES) ;
223HOST_HDRS			?= $(HDRS) ;
224
225
226# split up HOST_AR into the command name and flags
227HOST_AR				= [ Match "([^ ]*) *(.*)" : $(HOST_AR[1]) ]
228					  $(HOST_AR[2-]) ;
229HOST_ARFLAGS		= $(HOST_AR[2-]) ;
230HOST_AR				= $(HOST_AR[1]) ;
231HOST_UNARFLAGS		?= x ;
232
233# check the host platform compatibility
234SetPlatformCompatibilityFlagVariables HOST_PLATFORM : HOST : host
235	: linux openbsd freebsd darwin sunos cygwin ;
236HOST_PLATFORM_(host)_COMPATIBLE = 1 ;
237
238if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd
239	|| $(HOST_PLATFORM) = darwin || $(HOST_PLATFORM) = cygwin
240	|| $(HOST_PLATFORM) = sunos || $(HOST_PLATFORM) = openbsd {
241	# don't use lex: otherwise rc will not work correctly
242	if $(LEX) = lex {
243		LEX = flex ;
244	}
245}
246
247if $(HOST_PLATFORM) = cygwin {
248	HOST_LINKFLAGS += -Xlinker --allow-multiple-definition -Xlinker
249		--enable-auto-import ;
250}
251
252HOST_CPU ?= $(OSPLAT:L) ;
253
254# Jam doesn't know x86_64, so override HOST_CPU, if 64 bit.
255if $(HOST_CPU) = x86 && $(HOST_PLATFORM_IS_64_BIT) {
256	HOST_CPU = x86_64 ;
257}
258
259HOST_ARCH ?= $(HOST_CPU) ;
260HOST_ARCHS = $(HOST_ARCH) ;
261HOST_KERNEL_ARCH = host ;
262
263# analyze GCC version
264HOST_GCC_VERSION = [ FAnalyzeGCCVersion HOST_GCC_RAW_VERSION ] ;
265
266# set packaging architecture
267HOST_PACKAGING_ARCH		?= $(HOST_CPU) ;
268if $(HOST_PACKAGING_ARCH) = x86 && $(HOST_GCC_VERSION[1]) = 2 {
269	HOST_PACKAGING_ARCH = x86_gcc2 ;
270}
271HOST_PACKAGING_ARCHS = $(HOST_PACKAGING_ARCH) ;
272
273# directories
274HOST_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) ] ;
275HOST_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) common ] ;
276HOST_ARCH_OBJECT_DIR
277	= [ FDirName $(HOST_OBJECT_BASE_DIR) $(HOST_PACKAGING_ARCH) ] ;
278HOST_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) common ] ;
279HOST_DEBUG_0_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) release ] ;
280
281local level ;
282for level in $(HAIKU_DEBUG_LEVELS[2-]) {
283	HOST_DEBUG_$(level)_OBJECT_DIR
284		= [ FDirName $(HOST_ARCH_OBJECT_DIR) debug_$(level) ] ;
285}
286
287# set variables for gcc header options
288SetIncludePropertiesVariables HOST ;
289
290# assembler flags
291HOST_ASFLAGS = ;
292
293# C/C++ flags
294HOST_CCFLAGS += -Wno-multichar ;
295HOST_C++FLAGS += -Wno-multichar ;
296
297if $(HOST_PLATFORM) != cygwin {
298	HOST_PIC_CCFLAGS += -fPIC ;
299	HOST_PIC_C++FLAGS += -fPIC ;
300}
301
302if $(HOST_GCC_VERSION[1]) >= 3 {
303	HOST_GCC_BASE_FLAGS += -fno-strict-aliasing -fno-delete-null-pointer-checks ;
304}
305
306HOST_KERNEL_CCFLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
307	-D_KERNEL_MODE ;
308HOST_KERNEL_C++FLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
309	-fno-exceptions -D_KERNEL_MODE ;
310HOST_KERNEL_DEFINES += _KERNEL_MODE ;
311
312HOST_KERNEL_PIC_CCFLAGS = -fno-pic ;
313HOST_KERNEL_PIC_LINKFLAGS = ;
314if $(HOST_ARCH) = ppc {
315	# Build a position independent PPC kernel. We need to be able to relocate
316	# the kernel, since the virtual address space layout at boot time is not
317	# fixed.
318	HOST_KERNEL_PIC_CCFLAGS = -fPIE ;
319	HOST_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
320}
321if $(HOST_ARCH) = m68k {
322	# Build a position independent M68K kernel. We need to be able to relocate
323	# the kernel, since the virtual address space layout at boot time is not
324	# fixed.
325	HOST_KERNEL_PIC_CCFLAGS = $(HAIKU_KERNEL_PIC_CCFLAGS) ;
326	HOST_KERNEL_PIC_LINKFLAGS = $(HAIKU_KERNEL_PIC_LINKFLAGS) ;
327}
328
329if $(HOST_PLATFORM) != darwin {
330	# fix for new changes to DSO linking policies
331	HOST_LINKFLAGS += -Xlinker --no-as-needed ;
332}
333
334
335# warning flags
336HOST_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes -Wpointer-arith
337	-Wcast-align -Wsign-compare ;
338HOST_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy
339	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ;
340
341HOST_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes ;
342HOST_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs ;
343
344HOST_WERROR_FLAGS = ;
345
346# debug flags
347local hostDebugFlags ;
348switch $(HOST_PLATFORM) {
349	case haiku		: hostDebugFlags ?= -ggdb ;
350	case haiku_host	: hostDebugFlags ?= -ggdb ;
351	case linux		: hostDebugFlags ?= -ggdb ;
352	case freebsd	: hostDebugFlags ?= -ggdb ;
353	case darwin		: hostDebugFlags ?= -ggdb ;
354	case *			: hostDebugFlags ?= -g ;
355}
356
357# debug 0: suppress asserts
358HOST_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
359HOST_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
360
361HOST_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
362HOST_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
363
364local level ;
365for level in $(HAIKU_DEBUG_LEVELS[2-]) {
366	local flags = $(hostDebugFlags) [ FDefines DEBUG=$(level) ] ;
367	HOST_DEBUG_$(level)_CCFLAGS			= $(flags) ;
368	HOST_DEBUG_$(level)_C++FLAGS		= $(flags) ;
369	HOST_KERNEL_DEBUG_$(level)_CCFLAGS	= $(flags) ;
370	HOST_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
371}
372
373# ld flags
374if $(HAIKU_HOST_USE_32BIT) = 1 {
375	HOST_LDFLAGS += -melf_i386 ;
376}
377
378# private kernel headers do be used when compiling kernel code
379HOST_PRIVATE_KERNEL_HEADERS = ;
380
381# private shared kernel/libroot headers
382HOST_PRIVATE_SYSTEM_HEADERS = ;
383
384# under BeOS use copyattr instead of cp
385if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
386	CP = copyattr --data ;
387}
388
389HOST_DEFINES += ARCH_$(HOST_CPU) ;
390HOST_DEFINES += _NO_INLINE_ASM __NO_INLINE__ ;
391
392# for builds of tools in the current environment
393HOST_BUILD_COMPATIBILITY_LIB_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) lib ] ;
394
395# For the generic attributes emulation: Target rm_attrs -- rm replacement that
396# also removes the attributes.
397HOST_RM_ATTRS_TARGET = ;
398
399HOST_LIBROOT = libroot_build_function_remapper.a libroot_build.so ;
400HOST_STATIC_LIBROOT = libroot_build_function_remapper.a libroot_build.a ;
401HOST_LIBBE = libbe_build.so ;
402
403if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
404	# the C++ standard and support libraries
405	if $(HOST_GCC_VERSION[1]) < 3 {
406		HOST_LIBSTDC++ = stdc++.r4 ;
407		HOST_LIBSUPC++ = ;
408	} else {
409		HOST_LIBSTDC++ = stdc++ ;
410		HOST_LIBSUPC++ = supc++ ;
411	}
412
413	HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
414		= "export LIBRARY_PATH=$LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
415	HOST_PTHREAD_LINKFLAGS = ;
416	HOST_LIBRARY_NAME_MAP_input_server = /system/servers/input_server ;
417	HOST_DEFINES += __STDC_FORMAT_MACROS __STDC_LIMIT_MACROS ;
418
419	local compatibilityHeader = -include [ FDirName $(HAIKU_TOP) headers build
420		HaikuBuildCompatibility.h ] ;
421	HOST_CCFLAGS += $(compatibilityHeader) ;
422	HOST_C++FLAGS += $(compatibilityHeader) ;
423} else {
424	HOST_LINKFLAGS += -lm ;
425	HOST_LIBSTDC++ = stdc++ ;
426	if $(HOST_PLATFORM) = cygwin {
427		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
428			= "export PATH=$PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
429	} else if $(HOST_PLATFORM) = darwin {
430		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
431			= "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
432	} else {
433		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
434			= "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
435	}
436
437	if $(HOST_PLATFORM) = cygwin {
438		# not needed
439		HOST_PTHREAD_LINKFLAGS = ;
440	} else if $(HOST_PLATFORM) = freebsd {
441		HOST_PTHREAD_LINKFLAGS = -pthread ;
442	} else {
443		HOST_PTHREAD_LINKFLAGS = -pthread ;
444	}
445
446	# the C++ support library
447	if $(HOST_GCC_VERSION[1]) < 3 {
448		HOST_LIBSUPC++ = ;
449	} else {
450		HOST_LIBSUPC++ = supc++ ;
451	}
452
453	if $(HOST_PLATFORM) = darwin {
454		# part of the C++ runtime lives in libstdc++ on Darwin
455		HOST_LIBSUPC++ = gcc_s.1 stdc++ ;
456		HOST_LIBSTDC++ = ;
457	} else if $(HOST_PLATFORM) = freebsd {
458		if $(HOST_CPU) = x86_64 {
459			# amd64 FreeBSD 8 doesn't come without a shared libsupc++, and the
460			# static one prevents us from building shared libraries. So we have
461			# to work around by using the shared libstdc++.
462			HOST_LIBSUPC++ = stdc++ ;
463			HOST_LIBSTDC++ = ;
464		}
465	}
466
467	# The BeOS compilers define __INTEL__ respectively __POWERPC__. On the
468	# build platform we need to make sure, this is also defined.
469	if $(HOST_CPU) = x86 {
470		HOST_DEFINES += __INTEL__ ;
471	} else if $(HOST_CPU) = x86_64 {
472		HOST_DEFINES += __x86_64__ ;
473	} else if $(HOST_CPU) = ppc {
474		HOST_DEFINES += __POWERPC__ ;
475	} else if $(HOST_CPU) = m68k {
476		HOST_DEFINES += __M68K__ ;
477	}
478
479	# Supposing this is a glibc platform, let's try to get features like large
480	# file support, ISO C 99 definitions, etc. On some platforms we need to
481	# request 64 bit off_t support explicitely.
482	HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 __STDC_FORMAT_MACROS
483		__STDC_LIMIT_MACROS ;
484}
485
486if $(HAIKU_HOST_USE_XATTR) = 1 {
487	HOST_DEFINES += HAIKU_HOST_USE_XATTR ;
488} else {
489	# Otherwise the generic attribute emulation is used, which uses a
490	# directory per file to store its attribute. We need to redefine RM so
491	# that the attributes are removed as well. We use a wrapper script,
492	# which invokes a build tool. If the build tool hasn't been built yet,
493	# the normal "rm" is used and the attributes are leaked (likely there
494	# aren't any yet).
495	RM = $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ";"
496		[ FDirName $(HAIKU_TOP) build scripts rm_attrs ]
497		[ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) $(HOST_ARCH) release
498			tools rm_attrs ] -f ;
499		# assumes that rm_attrs is built with debugging disabled
500	HOST_RM_ATTRS_TARGET = <build>rm_attrs ;
501
502	# If specified, use xattr support to tag files with unique IDs.
503	if $(HAIKU_HOST_USE_XATTR_REF) = 1 {
504		HOST_DEFINES += HAIKU_HOST_USE_XATTR_REF ;
505	}
506}
507
508# network libraries
509if $(HOST_PLATFORM_HAIKU_COMPATIBLE) {
510	HOST_NETWORK_LIBS = network ;
511	HOST_NETAPI_LIB = bnetapi ;
512	HOST_SELECT_UNAME_ETC_LIB = ;	# libroot
513} else if $(HOST_PLATFORM) = "sunos" {
514	HOST_NETWORK_LIBS = xnet ;
515	HOST_NETAPI_LIB = ;
516	HOST_SELECT_UNAME_ETC_LIB = ;
517} else {
518	# Linux,...
519	HOST_NETWORK_LIBS = ;
520	HOST_NETAPI_LIB = ;
521	HOST_SELECT_UNAME_ETC_LIB = ;
522}
523
524# define the executable MIME type
525HOST_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
526
527if $(METROWERKS) {
528	# at least parts of Haiku still can be compiled with
529	# the Metrowerks compiler on BeOS/PPC
530	HOST_EXECUTABLE_MIME_TYPE = "application/x-be-executable" ;
531}
532
533# Be API compatibility
534HOST_BE_API_HEADERS = ;
535HOST_BE_API_CCFLAGS = ;
536HOST_BE_API_C++FLAGS = ;
537
538# Add directory with system headers we need when building something for the host
539# platform, e.g. containing missing POSIX/GNU headers.
540HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host $(HOST_PLATFORM) ] ;
541
542if $(HOST_PLATFORM) = freebsd {
543	# FreeBSD's gcc doesn't include /usr/local/* in its search paths,
544	# though that's where most things from ports wind up being installed.
545	HOST_HDRS += /usr/local/include /usr/include/gnu ;
546	HOST_LINKFLAGS += -L/usr/local/lib ;
547}
548
549if $(HOST_PLATFORM) = darwin {
550	HOST_HDRS += [ FDirName $(HAIKU_TOP) src build libgnuregex ] ;
551
552	# Mac OS X users may be using macports libraries, in which case the headers
553	# and the libs are located in /opt/local/.
554	HOST_HDRS += /opt/local/include ;
555	HOST_LINKFLAGS += -L/opt/local/lib ;
556
557	# Mac OS X users may be using homebrew libraries, in which case the headers
558	# and the libs are locted in the /usr/local/.
559	HOST_HDRS += /usr/local/include ;
560	HOST_LINKFLAGS += -L/usr/local/lib ;
561}
562
563HOST_BE_API_HEADERS =
564	[ FDirName $(HAIKU_TOP) headers build ]
565	[ FDirName $(HAIKU_TOP) headers build os ]
566	[ FDirName $(HAIKU_TOP) headers build os add-ons registrar ]
567	[ FDirName $(HAIKU_TOP) headers build os app ]
568	[ FDirName $(HAIKU_TOP) headers build os bluetooth ]
569	[ FDirName $(HAIKU_TOP) headers build os drivers ]
570	[ FDirName $(HAIKU_TOP) headers build os kernel ]
571	[ FDirName $(HAIKU_TOP) headers build os interface ]
572	[ FDirName $(HAIKU_TOP) headers build os locale ]
573	[ FDirName $(HAIKU_TOP) headers build os storage ]
574	[ FDirName $(HAIKU_TOP) headers build os support ]
575	[ FDirName $(HAIKU_TOP) headers build private ]
576;
577HOST_BE_API_CCFLAGS = -include [ FDirName $(HAIKU_TOP) headers build
578	BeOSBuildCompatibility.h ] ;
579HOST_BE_API_C++FLAGS = $(HOST_BE_API_CCFLAGS) ;
580
581
582#pragma mark - target platform settings
583
584
585# check the target platform compatibility
586SetPlatformCompatibilityFlagVariables TARGET_PLATFORM : TARGET : target ;
587
588# Haiku architecture is undefined on host-only builds
589# set here to host arch to prevent recusive loops.
590if $(HAIKU_HOST_BUILD_ONLY) = 1 {
591	HAIKU_ARCH = $(HOST_ARCH) ;
592	HAIKU_KERNEL_ARCH = $(HOST_ARCH) ;
593}
594
595# Set TARGET_* variables either from HAIKU_* or HOST_* depending on the
596# specified TARGET_PLATFORM. Some variables are package architecture dependent
597# and their name gets a respective suffix. A few variables exist both with and
598# without suffix. The latter is either equivalent to the variable with the
599# primary architecture suffix (e.g. TARGET_ARCH) or is (additionally) applicable
600# for all architectures (e.g. TARGET_DEFINES).
601
602local buildVars =
603	ARCH ARCHS KERNEL_ARCH PACKAGING_ARCH PACKAGING_ARCHS
604
605	DEFINES
606	KERNEL_DEFINES
607
608	KERNEL_CCFLAGS KERNEL_C++FLAGS
609	KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS KERNEL_ADDON_LINKFLAGS
610	BOOT_CCFLAGS BOOT_C++FLAGS BOOT_LINKFLAGS BOOT_LDFLAGS
611
612	KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
613
614	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS
615	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
616
617	PRIVATE_KERNEL_HEADERS
618
619	NETWORK_LIBS NETAPI_LIB SELECT_UNAME_ETC_LIB
620
621	EXECUTABLE_MIME_TYPE
622
623	OBJECT_BASE_DIR COMMON_ARCH_OBJECT_DIR
624	;
625
626local archDependentBuildVars =
627	ARCH CPU GCC_VERSION
628
629	AR CC C++ ELFEDIT LD OBJCOPY RANLIB STRIP
630
631	ARFLAGS ASFLAGS UNARFLAGS CPPFLAGS CCFLAGS C++FLAGS HDRS LDFLAGS
632	LINK LINKFLAGS
633
634	WARNING_CCFLAGS WARNING_C++FLAGS WERROR_FLAGS
635
636	DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
637
638	INCLUDES_SEPARATOR LOCAL_INCLUDES_OPTION SYSTEM_INCLUDES_OPTION
639
640	PRIVATE_SYSTEM_HEADERS
641
642	ARCH_OBJECT_DIR COMMON_DEBUG_OBJECT_DIR
643	DEBUG_$(HAIKU_DEBUG_LEVELS)_OBJECT_DIR
644	;
645
646# target platform setup
647local var ;
648for var in $(buildVars) {
649	TARGET_$(var) = $(HAIKU_$(var)) ;
650}
651
652for var in $(archDependentBuildVars)_$(TARGET_PACKAGING_ARCHS) {
653	TARGET_$(var) = $(HAIKU_$(var)) ;
654}
655
656TARGET_BOOT_LIBGCC		= $(HAIKU_BOOT_LIBGCC_$(TARGET_PACKAGING_ARCH)) ;
657TARGET_BOOT_LIBSUPC++	= $(HAIKU_BOOT_LIBSUPC++_$(TARGET_PACKAGING_ARCH)) ;
658
659TARGET_BOOT_PLATFORM	?= $(HAIKU_BOOT_PLATFORM) ;
660
661local architecture ;
662for architecture in $(TARGET_PACKAGING_ARCHS) {
663	TARGET_DEFINES_$(architecture) = $(HAIKU_DEFINES_$(architecture)) ;
664	TARGET_LIBRARY_NAME_MAP_$(architecture)
665		= HAIKU_LIBRARY_NAME_MAP_$(architecture) ;
666}
667
668# define macro, for identifying the platform
669switch $(TARGET_PLATFORM) {
670	case haiku		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
671	case libbe_test	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LIBBE_TEST ;
672}
673
674# define macro, for identifying the host platform
675switch $(HOST_PLATFORM) {
676	case haiku_host	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_HAIKU ;
677	case linux		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_LINUX ;
678	case freebsd	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_FREEBSD ;
679	case darwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DARWIN ;
680	case cygwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_CYGWIN ;
681	case sunos		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_SUNOS ;
682}
683
684# define host platform 64 bit macro
685if $(HOST_PLATFORM_IS_64_BIT) {
686	HOST_DEFINES += HAIKU_HOST_PLATFORM_64_BIT ;
687}
688
689# define Haiku packaging architecture macro for host build
690HOST_DEFINES += HAIKU_PACKAGING_ARCH=\\\"$(HAIKU_PACKAGING_ARCH)\\\" ;
691
692
693#pragma mark -
694
695# special target libbe_test
696
697if $(TARGET_PLATFORM) = libbe_test {
698	# headers and flags
699	TARGET_HDRS_$(TARGET_PACKAGING_ARCH) +=
700		[ PublicHeaders $(DOT) app drivers game interface kernel locale storage
701			support ]
702		[ PrivateHeaders $(DOT) ] ;
703	TARGET_DEFINES += __HAIKU__ ;
704
705	TARGET_PRIVATE_SYSTEM_HEADERS_$(TARGET_PACKAGING_ARCH) =
706		[ PrivateHeaders $(DOT) system system/arch/$(TARGET_ARCH) ] ;
707
708	# directories
709	TARGET_OBJECT_BASE_DIR
710		= [ FDirName $(HAIKU_OBJECT_DIR) $(TARGET_PLATFORM) ] ;
711	TARGET_COMMON_ARCH_OBJECT_DIR
712		= [ FDirName $(TARGET_OBJECT_BASE_DIR) common ] ;
713	TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
714		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(TARGET_ARCH) ] ;
715	TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
716		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
717			common ] ;
718	TARGET_DEBUG_0_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
719		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
720			release ] ;
721
722	local level ;
723	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
724		TARGET_DEBUG_$(level)_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
725			= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
726				debug_$(level) ] ;
727	}
728
729	# library name map
730	TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH) = LIBBE_LIBRARY_NAME_MAP ;
731	LIBBE_LIBRARY_NAME_MAP_be = libbe_test.so ;
732}
733
734
735#pragma mark - common stuff
736
737
738# start with a clean state
739CCFLAGS = ;
740C++FLAGS = ;
741DEFINES = ;
742
743# Set CC, C++, LINK to invalid values, so that we realize early, that we use
744# the wrong compiler.
745CC = bad-cc ;
746C++ = bad-c++ ;
747LINK = bad-link ;
748
749
750# Defaults for warnings, optimization, and debugging.
751#
752WARNINGS ?= 1 ;
753OPTIM ?= -O2 ;
754DEBUG ?= 0 ;
755
756
757# Set a sane default for whether this is a CI build.
758HAIKU_CONTINUOUS_INTEGRATION_BUILD ?= 0 ;
759
760
761# Set the defaults for PLATFORM and SUPPORTED_PLATFORMS. PLATFORM is only
762# overridden for targets to be built for the host platform. SUPPORTED_PLATFORMS
763# can be overridden by the author of a component.
764PLATFORM = $(TARGET_PLATFORM) ;
765SUPPORTED_PLATFORMS = haiku ;
766
767
768# Define two pseudo targets for the target and buildhost platform. The main
769# build rules (Cc, C++, As, ...) depend on these pseude targets such that global
770# initializations that are required before anything is built for a specific
771# platform can be forced by depending the pseudo target for the platform on the
772# initializations.
773# This is currently used to unpack the external headers from the
774# gcc_syslibs_devel build feature before anything is built for the target
775# platform.
776NotFile $(TARGET_PLATFORM) ;
777NotFile host ;
778
779
780# Instructs the Library rule to not make its object files temporary.
781# This is needed as some objects are used in a static library and for an
782# executable.
783KEEPOBJS = true ;
784
785
786# Set permissions to how they should be on the image.
787EXEMODE		= 755 ;
788FILEMODE	= 644 ;
789SHELLMODE	= 755 ;
790
791
792# output directories
793# TODO: Review this.
794HAIKU_DOCUMENTATION_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) documentation ] ;
795HAIKU_DOCUMENTATION_OBJECT_DIR ?= [ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR)
796	documentation ] ;
797
798# TODO: Rethink test stuff.
799HAIKU_TEST_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tests
800	$(TARGET_PLATFORM) $(HAIKU_ARCH) ] ;
801HAIKU_APP_TEST_DIR		?= [ FDirName $(HAIKU_TEST_DIR) apps ] ;
802HAIKU_APP_TEST_LIB_DIR 	?= [ FDirName $(HAIKU_APP_TEST_DIR) lib ] ;
803HAIKU_TMP_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tmp ] ;
804
805local architecture ;
806for architecture in $(HAIKU_PACKAGING_ARCHS) {
807	local baseDir
808		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(architecture) packaging ] ;
809	HAIKU_PACKAGES_DIR_$(architecture) = [ FDirName $(baseDir) packages ] ;
810	HAIKU_PACKAGES_BUILD_DIR_$(architecture)
811		= [ FDirName $(baseDir) packages_build ] ;
812	HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)
813		= [ FDirName $(baseDir) repositories ] ;
814}
815
816
817HAIKU_PACKAGE_INFOS_DIR			= [ FDirName $(HAIKU_TOP) src data
818									package_infos ] ;
819
820TARGET_TEST_DIR				?= [ FDirName $(HAIKU_TEST_DIR)
821									$(TARGET_PLATFORM) ] ;
822TARGET_UNIT_TEST_DIR		?= [ FDirName $(TARGET_TEST_DIR) unittests ] ;
823TARGET_UNIT_TEST_LIB_DIR	?= [ FDirName $(TARGET_UNIT_TEST_DIR) lib ] ;
824
825# automatically setup the objects directory per subdirectory
826SUBDIRRULES += SetupObjectsDir ;
827
828# Add the standard (userland) warning flags variables to the ones restored in
829# every subdirectory. Thus we can easily meddle with them in subdirectories
830# with imported sources.
831AUTO_SET_UP_CONFIG_VARIABLES +=
832	HOST_WARNING_CCFLAGS HOST_WARNING_C++FLAGS
833	TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCHS)
834	TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCHS)
835	;
836
837# also add PLATFORM and SUPPORTED_PLATFORMS
838AUTO_SET_UP_CONFIG_VARIABLES += PLATFORM SUPPORTED_PLATFORMS ;
839
840
841# set up warnings
842local architecture ;
843for architecture in $(TARGET_PACKAGING_ARCHS) {
844	ArchitectureSetupWarnings $(architecture) ;
845}
846
847
848# set up architecture build features
849local architecture ;
850for architecture in $(TARGET_PACKAGING_ARCHS) {
851	InitArchitectureBuildFeatures $(architecture) ;
852}
853
854
855# The following directories cannot currently be compiled with DEBUG=1
856SetConfigVar DEBUG : HAIKU_TOP src add-ons disk_systems bfs : 0 : local ;
857SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio hda : 0 : local ;
858SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auich : 0 : local ; # fails with gcc4 only
859SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auvia : 0 : local ; # fails with gcc4 only
860SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 sis7018 : 0 : local ;
861SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems btrfs : 0 : local ;
862SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems ntfs libntfs : 0 : local ;
863SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems udf : 0 : local ;
864SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server : 0 : local ; # fails with gcc2 only
865SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server haiku : 0 : local ; # fails with gcc2 only
866SetConfigVar DEBUG : HAIKU_TOP src add-ons media media-add-ons dvb : 0 : local ;
867SetConfigVar DEBUG : HAIKU_TOP src add-ons print drivers gutenprint : 0 : local ;
868SetConfigVar DEBUG : HAIKU_TOP src servers input : 0 : local ;
869SetConfigVar DEBUG : HAIKU_TOP src servers media_addon : 0 : local ;
870SetConfigVar DEBUG : HAIKU_TOP src system boot loader file_systems bfs : 0 : local ;
871