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