BuildSetup revision 85f8e700
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) = x86_64 {
482		HOST_DEFINES += __x86_64__ ;
483	} else if $(HOST_CPU) = ppc {
484		HOST_DEFINES += __POWERPC__ ;
485	} else if $(HOST_CPU) = m68k {
486		HOST_DEFINES += __M68K__ ;
487	}
488
489	# Supposing this is a glibc platform, let's try to get features like large
490	# file support, ISO C 99 definitions, etc. On some platforms we need to
491	# request 64 bit off_t support explicitely.
492	HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 __STDC_FORMAT_MACROS
493		__STDC_LIMIT_MACROS ;
494}
495
496if $(HAIKU_HOST_USE_XATTR) = 1 {
497	HOST_DEFINES += HAIKU_HOST_USE_XATTR ;
498} else {
499	# Otherwise the generic attribute emulation is used, which uses a
500	# directory per file to store its attribute. We need to redefine RM so
501	# that the attributes are removed as well. We use a wrapper script,
502	# which invokes a build tool. If the build tool hasn't been built yet,
503	# the normal "rm" is used and the attributes are leaked (likely there
504	# aren't any yet).
505	RM = $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ";"
506		[ FDirName $(HAIKU_TOP) build scripts rm_attrs ]
507		[ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) $(HOST_ARCH) release
508			tools rm_attrs ] -f ;
509		# assumes that rm_attrs is built with debugging disabled
510	HOST_RM_ATTRS_TARGET = <build>rm_attrs ;
511
512	# If specified, use xattr support to tag files with unique IDs.
513	if $(HAIKU_HOST_USE_XATTR_REF) = 1 {
514		HOST_DEFINES += HAIKU_HOST_USE_XATTR_REF ;
515	}
516}
517
518# network libraries
519if $(HOST_PLATFORM_HAIKU_COMPATIBLE) {
520	HOST_NETWORK_LIBS = network ;
521	HOST_NETAPI_LIB = bnetapi ;
522	HOST_SELECT_UNAME_ETC_LIB = ;	# libroot
523} else if $(HOST_PLATFORM) = "sunos" {
524	HOST_NETWORK_LIBS = xnet ;
525	HOST_NETAPI_LIB = ;
526	HOST_SELECT_UNAME_ETC_LIB = ;
527} else {
528	# Linux,...
529	HOST_NETWORK_LIBS = ;
530	HOST_NETAPI_LIB = ;
531	HOST_SELECT_UNAME_ETC_LIB = ;
532}
533
534# define the executable MIME type
535HOST_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
536
537if $(METROWERKS) {
538	# at least parts of Haiku still can be compiled with
539	# the Metrowerks compiler on BeOS/PPC
540	HOST_EXECUTABLE_MIME_TYPE = "application/x-be-executable" ;
541}
542
543# Be API compatibility
544HOST_BE_API_HEADERS = ;
545HOST_BE_API_CCFLAGS = ;
546HOST_BE_API_C++FLAGS = ;
547
548# Add directory with system headers we need when building something for the host
549# platform, e.g. containing missing POSIX/GNU headers.
550HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host $(HOST_PLATFORM) ] ;
551
552if $(HOST_PLATFORM) = freebsd {
553	# FreeBSD's gcc doesn't include /usr/local/* in its search paths,
554	# though that's where most things from ports wind up being installed.
555	HOST_HDRS += /usr/local/include /usr/include/gnu ;
556	HOST_LINKFLAGS += -L/usr/local/lib ;
557}
558
559if $(HOST_PLATFORM) = darwin {
560	HOST_HDRS += [ FDirName $(HAIKU_TOP) src build libgnuregex ] ;
561
562	# Mac OS X users may be using macports libraries, in which case the headers
563	# and the libs are located in /opt/local/.
564	HOST_HDRS += /opt/local/include ;
565	HOST_LINKFLAGS += -L/opt/local/lib ;
566
567	# Mac OS X users may be using homebrew libraries, in which case the headers
568	# and the libs are locted in the /usr/local/.
569	HOST_HDRS += /usr/local/include ;
570	HOST_LINKFLAGS += -L/usr/local/lib ;
571}
572
573HOST_BE_API_HEADERS =
574	[ FDirName $(HAIKU_TOP) headers build ]
575	[ FDirName $(HAIKU_TOP) headers build os ]
576	[ FDirName $(HAIKU_TOP) headers build os add-ons registrar ]
577	[ FDirName $(HAIKU_TOP) headers build os app ]
578	[ FDirName $(HAIKU_TOP) headers build os bluetooth ]
579	[ FDirName $(HAIKU_TOP) headers build os drivers ]
580	[ FDirName $(HAIKU_TOP) headers build os kernel ]
581	[ FDirName $(HAIKU_TOP) headers build os interface ]
582	[ FDirName $(HAIKU_TOP) headers build os locale ]
583	[ FDirName $(HAIKU_TOP) headers build os storage ]
584	[ FDirName $(HAIKU_TOP) headers build os support ]
585	[ FDirName $(HAIKU_TOP) headers build private ]
586;
587HOST_BE_API_CCFLAGS = -include [ FDirName $(HAIKU_TOP) headers build
588	BeOSBuildCompatibility.h ] ;
589HOST_BE_API_C++FLAGS = $(HOST_BE_API_CCFLAGS) ;
590
591
592#pragma mark - target platform settings
593
594
595# check the target platform compatibility
596SetPlatformCompatibilityFlagVariables TARGET_PLATFORM : TARGET : target ;
597
598# Haiku architecture is undefined on host-only builds
599# set here to host arch to prevent recusive loops.
600if $(HAIKU_HOST_BUILD_ONLY) = 1 {
601	HAIKU_ARCH = $(HOST_ARCH) ;
602	HAIKU_KERNEL_ARCH = $(HOST_ARCH) ;
603}
604
605# Set TARGET_* variables either from HAIKU_* or HOST_* depending on the
606# specified TARGET_PLATFORM. Some variables are package architecture dependent
607# and their name gets a respective suffix. A few variables exist both with and
608# without suffix. The latter is either equivalent to the variable with the
609# primary architecture suffix (e.g. TARGET_ARCH) or is (additionally) applicable
610# for all architectures (e.g. TARGET_DEFINES).
611
612local buildVars =
613	ARCH ARCHS KERNEL_ARCH PACKAGING_ARCH PACKAGING_ARCHS
614
615	DEFINES
616	KERNEL_DEFINES
617
618	KERNEL_CCFLAGS KERNEL_C++FLAGS
619	KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS KERNEL_ADDON_LINKFLAGS
620	BOOT_CCFLAGS BOOT_C++FLAGS BOOT_LINKFLAGS BOOT_LDFLAGS
621
622	KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
623
624	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS
625	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
626
627	PRIVATE_KERNEL_HEADERS
628
629	NETWORK_LIBS NETAPI_LIB SELECT_UNAME_ETC_LIB
630
631	EXECUTABLE_MIME_TYPE
632
633	OBJECT_BASE_DIR COMMON_ARCH_OBJECT_DIR
634	;
635
636local archDependentBuildVars =
637	ARCH CPU GCC_VERSION
638
639	AR CC C++ ELFEDIT LD OBJCOPY RANLIB STRIP
640
641	ARFLAGS ASFLAGS UNARFLAGS CPPFLAGS CCFLAGS C++FLAGS HDRS LDFLAGS
642	LINK LINKFLAGS
643
644	WARNING_CCFLAGS WARNING_C++FLAGS WERROR_FLAGS
645
646	DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
647
648	INCLUDES_SEPARATOR LOCAL_INCLUDES_OPTION SYSTEM_INCLUDES_OPTION
649
650	PRIVATE_SYSTEM_HEADERS
651
652	ARCH_OBJECT_DIR COMMON_DEBUG_OBJECT_DIR
653	DEBUG_$(HAIKU_DEBUG_LEVELS)_OBJECT_DIR
654	;
655
656# target platform setup
657local var ;
658for var in $(buildVars) {
659	TARGET_$(var) = $(HAIKU_$(var)) ;
660}
661
662for var in $(archDependentBuildVars)_$(TARGET_PACKAGING_ARCHS) {
663	TARGET_$(var) = $(HAIKU_$(var)) ;
664}
665
666TARGET_BOOT_LIBGCC		= $(HAIKU_BOOT_LIBGCC_$(TARGET_PACKAGING_ARCH)) ;
667TARGET_BOOT_LIBSUPC++	= $(HAIKU_BOOT_LIBSUPC++_$(TARGET_PACKAGING_ARCH)) ;
668
669TARGET_KERNEL_PLATFORM	?= $(HAIKU_KERNEL_PLATFORM) ;
670
671local architecture ;
672for architecture in $(TARGET_PACKAGING_ARCHS) {
673	TARGET_DEFINES_$(architecture) = $(HAIKU_DEFINES_$(architecture)) ;
674	TARGET_LIBRARY_NAME_MAP_$(architecture)
675		= HAIKU_LIBRARY_NAME_MAP_$(architecture) ;
676}
677
678# define macro, for identifying the platform
679switch $(TARGET_PLATFORM) {
680	case haiku		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
681	case libbe_test	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LIBBE_TEST ;
682}
683
684# define macro, for identifying the host platform
685switch $(HOST_PLATFORM) {
686	case haiku_host	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_HAIKU ;
687	case linux		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_LINUX ;
688	case freebsd	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_FREEBSD ;
689	case darwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DARWIN ;
690	case cygwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_CYGWIN ;
691	case sunos		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_SUNOS ;
692}
693
694# define host platform 64 bit macro
695if $(HOST_PLATFORM_IS_64_BIT) {
696	HOST_DEFINES += HAIKU_HOST_PLATFORM_64_BIT ;
697}
698
699# define Haiku packaging architecture macro for host build
700HOST_DEFINES += HAIKU_PACKAGING_ARCH=\\\"$(HAIKU_PACKAGING_ARCH)\\\" ;
701
702
703#pragma mark -
704
705# special target libbe_test
706
707if $(TARGET_PLATFORM) = libbe_test {
708	# headers and flags
709	TARGET_HDRS_$(TARGET_PACKAGING_ARCH) +=
710		[ PublicHeaders $(DOT) app drivers game interface kernel locale storage
711			support ]
712		[ PrivateHeaders $(DOT) ] ;
713	TARGET_DEFINES += __HAIKU__ ;
714
715	TARGET_PRIVATE_SYSTEM_HEADERS_$(TARGET_PACKAGING_ARCH) =
716		[ PrivateHeaders $(DOT) system system/arch/$(TARGET_ARCH) ] ;
717
718	# directories
719	TARGET_OBJECT_BASE_DIR
720		= [ FDirName $(HAIKU_OBJECT_DIR) $(TARGET_PLATFORM) ] ;
721	TARGET_COMMON_ARCH_OBJECT_DIR
722		= [ FDirName $(TARGET_OBJECT_BASE_DIR) common ] ;
723	TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
724		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(TARGET_ARCH) ] ;
725	TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
726		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
727			common ] ;
728	TARGET_DEBUG_0_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
729		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
730			release ] ;
731
732	local level ;
733	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
734		TARGET_DEBUG_$(level)_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
735			= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
736				debug_$(level) ] ;
737	}
738
739	# library name map
740	TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH) = LIBBE_LIBRARY_NAME_MAP ;
741	LIBBE_LIBRARY_NAME_MAP_be = libbe_test.so ;
742}
743
744
745#pragma mark - common stuff
746
747
748# start with a clean state
749CCFLAGS = ;
750C++FLAGS = ;
751DEFINES = ;
752
753# Set CC, C++, LINK to invalid values, so that we realize early, that we use
754# the wrong compiler.
755CC = bad-cc ;
756C++ = bad-c++ ;
757LINK = bad-link ;
758
759
760# Defaults for warnings, optimization, and debugging.
761#
762WARNINGS ?= 1 ;
763OPTIM ?= -O2 ;
764DEBUG ?= 0 ;
765
766
767# Set a sane default for whether this is a CI build.
768HAIKU_CONTINUOUS_INTEGRATION_BUILD ?= 0 ;
769
770
771# Set the defaults for PLATFORM and SUPPORTED_PLATFORMS. PLATFORM is only
772# overridden for targets to be built for the host platform. SUPPORTED_PLATFORMS
773# can be overridden by the author of a component.
774PLATFORM = $(TARGET_PLATFORM) ;
775SUPPORTED_PLATFORMS = haiku ;
776
777
778# Define two pseudo targets for the target and buildhost platform. The main
779# build rules (Cc, C++, As, ...) depend on these pseude targets such that global
780# initializations that are required before anything is built for a specific
781# platform can be forced by depending the pseudo target for the platform on the
782# initializations.
783# This is currently used to unpack the external headers from the
784# gcc_syslibs_devel build feature before anything is built for the target
785# platform.
786NotFile $(TARGET_PLATFORM) ;
787NotFile host ;
788
789
790# Instructs the Library rule to not make its object files temporary.
791# This is needed as some objects are used in a static library and for an
792# executable.
793KEEPOBJS = true ;
794
795
796# Set permissions to how they should be on the image.
797EXEMODE		= 755 ;
798FILEMODE	= 644 ;
799SHELLMODE	= 755 ;
800
801
802# output directories
803# TODO: Review this.
804HAIKU_DOCUMENTATION_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) documentation ] ;
805HAIKU_DOCUMENTATION_OBJECT_DIR ?= [ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR)
806	documentation ] ;
807
808# TODO: Rethink test stuff.
809HAIKU_TEST_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tests
810	$(TARGET_PLATFORM) $(HAIKU_ARCH) ] ;
811HAIKU_APP_TEST_DIR		?= [ FDirName $(HAIKU_TEST_DIR) apps ] ;
812HAIKU_APP_TEST_LIB_DIR 	?= [ FDirName $(HAIKU_APP_TEST_DIR) lib ] ;
813HAIKU_TMP_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tmp ] ;
814
815local architecture ;
816for architecture in $(HAIKU_PACKAGING_ARCHS) {
817	local baseDir
818		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(architecture) packaging ] ;
819	HAIKU_PACKAGES_DIR_$(architecture) = [ FDirName $(baseDir) packages ] ;
820	HAIKU_PACKAGES_BUILD_DIR_$(architecture)
821		= [ FDirName $(baseDir) packages_build ] ;
822	HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)
823		= [ FDirName $(baseDir) repositories ] ;
824}
825
826
827HAIKU_PACKAGE_INFOS_DIR			= [ FDirName $(HAIKU_TOP) src data
828									package_infos ] ;
829
830TARGET_TEST_DIR				?= [ FDirName $(HAIKU_TEST_DIR)
831									$(TARGET_PLATFORM) ] ;
832TARGET_UNIT_TEST_DIR		?= [ FDirName $(TARGET_TEST_DIR) unittests ] ;
833TARGET_UNIT_TEST_LIB_DIR	?= [ FDirName $(TARGET_UNIT_TEST_DIR) lib ] ;
834
835# automatically setup the objects directory per subdirectory
836SUBDIRRULES += SetupObjectsDir ;
837
838# Add the standard (userland) warning flags variables to the ones restored in
839# every subdirectory. Thus we can easily meddle with them in subdirectories
840# with imported sources.
841AUTO_SET_UP_CONFIG_VARIABLES +=
842	HOST_WARNING_CCFLAGS HOST_WARNING_C++FLAGS
843	TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCHS)
844	TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCHS)
845	;
846
847# also add PLATFORM and SUPPORTED_PLATFORMS
848AUTO_SET_UP_CONFIG_VARIABLES += PLATFORM SUPPORTED_PLATFORMS ;
849
850
851# set up warnings
852local architecture ;
853for architecture in $(TARGET_PACKAGING_ARCHS) {
854	ArchitectureSetupWarnings $(architecture) ;
855}
856
857
858# set up architecture build features
859local architecture ;
860for architecture in $(TARGET_PACKAGING_ARCHS) {
861	InitArchitectureBuildFeatures $(architecture) ;
862}
863
864
865# The following directories cannot currently be compiled with DEBUG=1
866SetConfigVar DEBUG : HAIKU_TOP src add-ons disk_systems bfs : 0 : local ;
867SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio hda : 0 : local ;
868SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auich : 0 : local ; # fails with gcc4 only
869SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auvia : 0 : local ; # fails with gcc4 only
870SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 sis7018 : 0 : local ;
871SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems btrfs : 0 : local ;
872SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems ntfs libntfs : 0 : local ;
873SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems udf : 0 : local ;
874SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server : 0 : local ; # fails with gcc2 only
875SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server haiku : 0 : local ; # fails with gcc2 only
876SetConfigVar DEBUG : HAIKU_TOP src add-ons media media-add-ons dvb : 0 : local ;
877SetConfigVar DEBUG : HAIKU_TOP src add-ons print drivers gutenprint : 0 : local ;
878SetConfigVar DEBUG : HAIKU_TOP src servers input : 0 : local ;
879SetConfigVar DEBUG : HAIKU_TOP src servers media_addon : 0 : local ;
880SetConfigVar DEBUG : HAIKU_TOP src system boot loader file_systems bfs : 0 : local ;
881