xref: /haiku/build/jam/BuildSetup (revision e680a439bf54eb3f561c3fc8cefd299587e69368)
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 mingw ;
246HOST_PLATFORM_(host)_COMPATIBLE = 1 ;
247
248if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd
249	|| $(HOST_PLATFORM) = darwin || $(HOST_PLATFORM) = openbsd {
250	# don't use lex: otherwise rc will not work correctly
251	if $(LEX) = lex {
252		LEX = flex ;
253	}
254}
255
256HOST_CPU ?= $(OSPLAT:L) ;
257
258# Jam doesn't know x86_64, so override HOST_CPU, if 64 bit.
259if $(HOST_CPU) = x86 && $(HOST_PLATFORM_IS_64_BIT) {
260	HOST_CPU = x86_64 ;
261}
262
263HOST_ARCH ?= $(HOST_CPU) ;
264HOST_ARCHS = $(HOST_ARCH) ;
265HOST_KERNEL_ARCH = host ;
266
267# analyze GCC version
268HOST_GCC_VERSION = [ FAnalyzeGCCVersion HOST_GCC_RAW_VERSION ] ;
269
270# set packaging architecture
271HOST_PACKAGING_ARCH		?= $(HOST_CPU) ;
272if $(HOST_PACKAGING_ARCH) = x86 && $(HOST_GCC_VERSION[1]) = 2 {
273	HOST_PACKAGING_ARCH = x86_gcc2 ;
274}
275HOST_PACKAGING_ARCHS = $(HOST_PACKAGING_ARCH) ;
276
277# directories
278HOST_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) ] ;
279HOST_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) common ] ;
280HOST_ARCH_OBJECT_DIR
281	= [ FDirName $(HOST_OBJECT_BASE_DIR) $(HOST_PACKAGING_ARCH) ] ;
282HOST_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) common ] ;
283HOST_DEBUG_0_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) release ] ;
284
285local level ;
286for level in $(HAIKU_DEBUG_LEVELS[2-]) {
287	HOST_DEBUG_$(level)_OBJECT_DIR
288		= [ FDirName $(HOST_ARCH_OBJECT_DIR) debug_$(level) ] ;
289}
290
291# set variables for gcc header options
292SetIncludePropertiesVariables HOST ;
293
294# assembler flags
295HOST_ASFLAGS = ;
296
297# C/C++ flags
298HOST_CCFLAGS += -Wno-multichar ;
299HOST_C++FLAGS += -Wno-multichar ;
300
301HOST_PIC_CCFLAGS += -fPIC ;
302HOST_PIC_C++FLAGS += -fPIC ;
303
304if $(HOST_GCC_VERSION[1]) >= 3 {
305	HOST_GCC_BASE_FLAGS += -fno-strict-aliasing -fno-delete-null-pointer-checks ;
306}
307
308HOST_KERNEL_CCFLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
309	-D_KERNEL_MODE ;
310HOST_KERNEL_C++FLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
311	-fno-exceptions -D_KERNEL_MODE ;
312HOST_KERNEL_DEFINES += _KERNEL_MODE ;
313
314HOST_KERNEL_PIC_CCFLAGS = -fno-pic ;
315HOST_KERNEL_PIC_LINKFLAGS = ;
316if $(HOST_ARCH) = ppc {
317	# Build a position independent PPC kernel. We need to be able to relocate
318	# the kernel, since the virtual address space layout at boot time is not
319	# fixed.
320	HOST_KERNEL_PIC_CCFLAGS = -fPIE ;
321	HOST_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
322}
323if $(HOST_ARCH) = m68k {
324	# Build a position independent M68K kernel. We need to be able to relocate
325	# the kernel, since the virtual address space layout at boot time is not
326	# fixed.
327	HOST_KERNEL_PIC_CCFLAGS = $(HAIKU_KERNEL_PIC_CCFLAGS) ;
328	HOST_KERNEL_PIC_LINKFLAGS = $(HAIKU_KERNEL_PIC_LINKFLAGS) ;
329}
330
331if $(HOST_PLATFORM) != darwin {
332	# fix for new changes to DSO linking policies
333	HOST_LINKFLAGS += -Xlinker --no-as-needed ;
334}
335
336
337# warning flags
338HOST_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes -Wpointer-arith
339	-Wcast-align -Wsign-compare ;
340HOST_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy
341	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ;
342
343HOST_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes ;
344HOST_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs ;
345
346HOST_WERROR_FLAGS = ;
347
348# debug flags
349local hostDebugFlags ;
350switch $(HOST_PLATFORM) {
351	case haiku		: hostDebugFlags ?= -ggdb ;
352	case haiku_host	: hostDebugFlags ?= -ggdb ;
353	case linux		: hostDebugFlags ?= -ggdb ;
354	case freebsd	: hostDebugFlags ?= -ggdb ;
355	case darwin		: hostDebugFlags ?= -ggdb ;
356	case *			: hostDebugFlags ?= -g ;
357}
358
359# debug 0: suppress asserts
360HOST_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
361HOST_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
362
363HOST_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
364HOST_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
365
366local level ;
367for level in $(HAIKU_DEBUG_LEVELS[2-]) {
368	local flags = $(hostDebugFlags) [ FDefines DEBUG=$(level) ] ;
369	HOST_DEBUG_$(level)_CCFLAGS			= $(flags) ;
370	HOST_DEBUG_$(level)_C++FLAGS		= $(flags) ;
371	HOST_KERNEL_DEBUG_$(level)_CCFLAGS	= $(flags) ;
372	HOST_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
373}
374
375# ld flags
376if $(HAIKU_HOST_USE_32BIT) = 1 {
377	HOST_LDFLAGS += -melf_i386 ;
378}
379
380# private kernel headers do be used when compiling kernel code
381HOST_PRIVATE_KERNEL_HEADERS = ;
382
383# private shared kernel/libroot headers
384HOST_PRIVATE_SYSTEM_HEADERS = ;
385
386# under BeOS use copyattr instead of cp
387if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
388	CP = copyattr --data ;
389}
390
391HOST_DEFINES += ARCH_$(HOST_CPU) ;
392HOST_DEFINES += _NO_INLINE_ASM __NO_INLINE__ ;
393
394# for builds of tools in the current environment
395HOST_BUILD_COMPATIBILITY_LIB_DIR = [ FDirName $(PWD) $(HOST_OBJECT_BASE_DIR) lib ] ;
396
397# For the generic attributes emulation: Target rm_attrs -- rm replacement that
398# also removes the attributes.
399HOST_RM_ATTRS_TARGET = ;
400
401HOST_LIBROOT = libroot_build_function_remapper.a libroot_build.so ;
402HOST_STATIC_LIBROOT = libroot_build_function_remapper.a libroot_build.a ;
403HOST_LIBBE = libbe_build.so ;
404
405if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
406	# the C++ standard and support libraries
407	if $(HOST_GCC_VERSION[1]) < 3 {
408		HOST_LIBSTDC++ = stdc++.r4 ;
409		HOST_LIBSUPC++ = ;
410	} else {
411		HOST_LIBSTDC++ = stdc++ ;
412		HOST_LIBSUPC++ = supc++ ;
413	}
414
415	HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
416		= "export \"LIBRARY_PATH=$LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)\"" ;
417	HOST_PTHREAD_LINKFLAGS = ;
418	HOST_LIBRARY_NAME_MAP_input_server = /system/servers/input_server ;
419	HOST_DEFINES += __STDC_FORMAT_MACROS __STDC_LIMIT_MACROS ;
420
421	local compatibilityHeader = -include [ FDirName $(HAIKU_TOP) headers build
422		HaikuBuildCompatibility.h ] ;
423	HOST_CCFLAGS += $(compatibilityHeader) ;
424	HOST_C++FLAGS += $(compatibilityHeader) ;
425} else {
426	HOST_LINKFLAGS += -lm -ldl ;
427	HOST_LIBSTDC++ = stdc++ ;
428	if $(HOST_PLATFORM) = mingw {
429		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
430			= "export PATH=$PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
431	} else if $(HOST_PLATFORM) = darwin {
432		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
433			= "export \"DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)\"" ;
434	} else {
435		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
436			= "export \"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)\"" ;
437	}
438
439	HOST_PTHREAD_LINKFLAGS = -pthread ;
440
441	# the C++ support library
442	if $(HOST_GCC_VERSION[1]) < 3 {
443		HOST_LIBSUPC++ = ;
444	} else {
445		HOST_LIBSUPC++ = supc++ ;
446	}
447
448	if $(HOST_PLATFORM) = darwin {
449		# part of the C++ runtime lives in libstdc++ on Darwin
450		HOST_LIBSUPC++ = gcc_s.1 stdc++ ;
451		HOST_LIBSTDC++ = ;
452	} else if $(HOST_PLATFORM) = freebsd {
453		if $(HOST_CPU) = x86_64 {
454			# amd64 FreeBSD 8 doesn't come without a shared libsupc++, and the
455			# static one prevents us from building shared libraries. So we have
456			# to work around by using the shared libstdc++.
457			HOST_LIBSUPC++ = stdc++ ;
458			HOST_LIBSTDC++ = ;
459		}
460	}
461
462	# The BeOS compilers define __INTEL__ respectively __POWERPC__. On the
463	# build platform we need to make sure, this is also defined.
464	if $(HOST_CPU) = x86 {
465		HOST_DEFINES += __INTEL__ ;
466	} else if $(HOST_CPU) = ppc {
467		HOST_DEFINES += __POWERPC__ ;
468	} else if $(HOST_CPU) = m68k {
469		HOST_DEFINES += __M68K__ ;
470	}
471
472	# Supposing this is a glibc platform, let's try to get features like large
473	# file support, ISO C 99 definitions, etc. On some platforms we need to
474	# request 64 bit off_t support explicitely.
475	HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 __STDC_FORMAT_MACROS
476		__STDC_LIMIT_MACROS ;
477}
478
479if $(HAIKU_HOST_USE_XATTR) = 1 {
480	HOST_DEFINES += HAIKU_HOST_USE_XATTR ;
481} else {
482	# Otherwise the generic attribute emulation is used, which uses a
483	# directory per file to store its attribute. We need to redefine RM so
484	# that the attributes are removed as well. We use a wrapper script,
485	# which invokes a build tool. If the build tool hasn't been built yet,
486	# the normal "rm" is used and the attributes are leaked (likely there
487	# aren't any yet).
488	RM = $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ";"
489		[ FDirName $(HAIKU_TOP) build scripts rm_attrs ]
490		[ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) $(HOST_ARCH) release
491			tools rm_attrs ] -f ;
492		# assumes that rm_attrs is built with debugging disabled
493	HOST_RM_ATTRS_TARGET = <build>rm_attrs ;
494
495	# If specified, use xattr support to tag files with unique IDs.
496	if $(HAIKU_HOST_USE_XATTR_REF) = 1 {
497		HOST_DEFINES += HAIKU_HOST_USE_XATTR_REF ;
498	}
499}
500
501# network libraries
502if $(HOST_PLATFORM_HAIKU_COMPATIBLE) {
503	HOST_NETWORK_LIBS = network ;
504	HOST_NETAPI_LIB = bnetapi ;
505	HOST_SELECT_UNAME_ETC_LIB = ;	# libroot
506} else {
507	# Linux, ...
508	HOST_NETWORK_LIBS = ;
509	HOST_NETAPI_LIB = ;
510	HOST_SELECT_UNAME_ETC_LIB = ;
511}
512
513# define the executable MIME type
514HOST_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
515
516if $(METROWERKS) {
517	# at least parts of Haiku still can be compiled with
518	# the Metrowerks compiler on BeOS/PPC
519	HOST_EXECUTABLE_MIME_TYPE = "application/x-be-executable" ;
520}
521
522# Be API compatibility
523HOST_BE_API_HEADERS = ;
524HOST_BE_API_CCFLAGS = ;
525HOST_BE_API_C++FLAGS = ;
526
527# Add directory with system headers we need when building something for the host
528# platform, e.g. containing missing POSIX/GNU headers.
529HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host $(HOST_PLATFORM) ] ;
530
531if $(HOST_PLATFORM) = freebsd {
532	# FreeBSD's gcc doesn't include /usr/local/* in its search paths,
533	# though that's where most things from ports wind up being installed.
534	HOST_HDRS += /usr/local/include /usr/include/gnu ;
535	HOST_LINKFLAGS += -L/usr/local/lib ;
536}
537
538if $(HOST_PLATFORM) = darwin {
539	HOST_HDRS += [ FDirName $(HAIKU_TOP) src build libgnuregex ] ;
540
541	# Mac OS X users may be using macports libraries, in which case the headers
542	# and the libs are located in /opt/local/.
543	HOST_HDRS += /opt/local/include ;
544	HOST_LINKFLAGS += -L/opt/local/lib ;
545
546	# Mac OS X users may be using homebrew libraries, in which case the headers
547	# and the libs are locted in the /usr/local/.
548	HOST_HDRS += /usr/local/include ;
549	HOST_LINKFLAGS += -L/usr/local/lib ;
550}
551
552HOST_BE_API_HEADERS =
553	[ FDirName $(HAIKU_TOP) headers build ]
554	[ FDirName $(HAIKU_TOP) headers build os ]
555	[ FDirName $(HAIKU_TOP) headers build os add-ons registrar ]
556	[ FDirName $(HAIKU_TOP) headers build os app ]
557	[ FDirName $(HAIKU_TOP) headers build os bluetooth ]
558	[ FDirName $(HAIKU_TOP) headers build os drivers ]
559	[ FDirName $(HAIKU_TOP) headers build os kernel ]
560	[ FDirName $(HAIKU_TOP) headers build os interface ]
561	[ FDirName $(HAIKU_TOP) headers build os locale ]
562	[ FDirName $(HAIKU_TOP) headers build os storage ]
563	[ FDirName $(HAIKU_TOP) headers build os support ]
564	[ FDirName $(HAIKU_TOP) headers build private ]
565;
566HOST_BE_API_CCFLAGS = -include [ FDirName $(HAIKU_TOP) headers build
567	BeOSBuildCompatibility.h ] ;
568HOST_BE_API_C++FLAGS = $(HOST_BE_API_CCFLAGS) ;
569
570
571#pragma mark - target platform settings
572
573
574# check the target platform compatibility
575SetPlatformCompatibilityFlagVariables TARGET_PLATFORM : TARGET : target ;
576
577# Haiku architecture is undefined on host-only builds
578# set here to host arch to prevent recusive loops.
579if $(HAIKU_HOST_BUILD_ONLY) = 1 {
580	HAIKU_ARCH = $(HOST_ARCH) ;
581	HAIKU_KERNEL_ARCH = $(HOST_ARCH) ;
582}
583
584# Set TARGET_* variables either from HAIKU_* or HOST_* depending on the
585# specified TARGET_PLATFORM. Some variables are package architecture dependent
586# and their name gets a respective suffix. A few variables exist both with and
587# without suffix. The latter is either equivalent to the variable with the
588# primary architecture suffix (e.g. TARGET_ARCH) or is (additionally) applicable
589# for all architectures (e.g. TARGET_DEFINES).
590
591local buildVars =
592	ARCH ARCHS KERNEL_ARCH PACKAGING_ARCH PACKAGING_ARCHS
593
594	DEFINES
595	KERNEL_DEFINES
596
597	KERNEL_CCFLAGS KERNEL_C++FLAGS
598	KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS KERNEL_ADDON_LINKFLAGS
599	BOOT_CCFLAGS BOOT_C++FLAGS BOOT_LINKFLAGS BOOT_LDFLAGS
600
601	KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
602
603	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS
604	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
605
606	PRIVATE_KERNEL_HEADERS
607
608	NETWORK_LIBS NETAPI_LIB SELECT_UNAME_ETC_LIB
609
610	EXECUTABLE_MIME_TYPE
611
612	OBJECT_BASE_DIR COMMON_ARCH_OBJECT_DIR
613	;
614
615local archDependentBuildVars =
616	ARCH CPU GCC_VERSION
617
618	AR CC C++ ELFEDIT LD OBJCOPY RANLIB STRIP
619
620	ARFLAGS ASFLAGS UNARFLAGS CPPFLAGS CCFLAGS C++FLAGS HDRS LDFLAGS
621	LINK LINKFLAGS
622
623	WARNING_CCFLAGS WARNING_C++FLAGS WERROR_FLAGS
624
625	DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
626
627	INCLUDES_SEPARATOR LOCAL_INCLUDES_OPTION SYSTEM_INCLUDES_OPTION
628
629	PRIVATE_SYSTEM_HEADERS
630
631	ARCH_OBJECT_DIR COMMON_DEBUG_OBJECT_DIR
632	DEBUG_$(HAIKU_DEBUG_LEVELS)_OBJECT_DIR
633	;
634
635# target platform setup
636local var ;
637for var in $(buildVars) {
638	TARGET_$(var) = $(HAIKU_$(var)) ;
639}
640
641for var in $(archDependentBuildVars)_$(TARGET_PACKAGING_ARCHS) {
642	TARGET_$(var) = $(HAIKU_$(var)) ;
643}
644
645TARGET_BOOT_LIBGCC		= $(HAIKU_BOOT_LIBGCC_$(TARGET_PACKAGING_ARCH)) ;
646TARGET_BOOT_LIBSUPC++	= $(HAIKU_BOOT_LIBSUPC++_$(TARGET_PACKAGING_ARCH)) ;
647
648TARGET_KERNEL_PLATFORM	?= $(HAIKU_KERNEL_PLATFORM) ;
649
650local architecture ;
651for architecture in $(TARGET_PACKAGING_ARCHS) {
652	TARGET_DEFINES_$(architecture) = $(HAIKU_DEFINES_$(architecture)) ;
653	TARGET_LIBRARY_NAME_MAP_$(architecture)
654		= HAIKU_LIBRARY_NAME_MAP_$(architecture) ;
655}
656
657# define macro, for identifying the platform
658switch $(TARGET_PLATFORM) {
659	case haiku		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
660	case libbe_test	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LIBBE_TEST ;
661}
662
663# define macro, for identifying the host platform
664switch $(HOST_PLATFORM) {
665	case haiku_host	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_HAIKU ;
666	case linux		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_LINUX ;
667	case freebsd	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_FREEBSD ;
668	case darwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DARWIN ;
669	case mingw		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_MINGW ;
670}
671
672# define host platform 64 bit macro
673if $(HOST_PLATFORM_IS_64_BIT) {
674	HOST_DEFINES += HAIKU_HOST_PLATFORM_64_BIT ;
675}
676
677# define Haiku packaging architecture macro for host build
678HOST_DEFINES += HAIKU_PACKAGING_ARCH=\\\"$(HAIKU_PACKAGING_ARCH)\\\" ;
679
680
681#pragma mark -
682
683# special target libbe_test
684
685if $(TARGET_PLATFORM) = libbe_test {
686	# headers and flags
687	TARGET_HDRS_$(TARGET_PACKAGING_ARCH) +=
688		[ PublicHeaders $(DOT) app drivers game interface kernel locale storage
689			support ]
690		[ PrivateHeaders $(DOT) ] ;
691	TARGET_DEFINES += __HAIKU__ ;
692
693	TARGET_PRIVATE_SYSTEM_HEADERS_$(TARGET_PACKAGING_ARCH) =
694		[ PrivateHeaders $(DOT) system system/arch/$(TARGET_ARCH) ] ;
695
696	# directories
697	TARGET_OBJECT_BASE_DIR
698		= [ FDirName $(HAIKU_OBJECT_DIR) $(TARGET_PLATFORM) ] ;
699	TARGET_COMMON_ARCH_OBJECT_DIR
700		= [ FDirName $(TARGET_OBJECT_BASE_DIR) common ] ;
701	TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
702		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(TARGET_ARCH) ] ;
703	TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
704		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
705			common ] ;
706	TARGET_DEBUG_0_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
707		= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
708			release ] ;
709
710	local level ;
711	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
712		TARGET_DEBUG_$(level)_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)
713			= [ FDirName $(TARGET_ARCH_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
714				debug_$(level) ] ;
715	}
716
717	# library name map
718	TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH) = LIBBE_LIBRARY_NAME_MAP ;
719	LIBBE_LIBRARY_NAME_MAP_be = libbe_test.so ;
720}
721
722
723#pragma mark - common stuff
724
725
726# start with a clean state
727CCFLAGS = ;
728C++FLAGS = ;
729DEFINES = ;
730
731# Set CC, C++, LINK to invalid values, so that we realize early, that we use
732# the wrong compiler.
733CC = bad-cc ;
734C++ = bad-c++ ;
735LINK = bad-link ;
736
737
738# Defaults for warnings, optimization, and debugging.
739#
740WARNINGS ?= 1 ;
741OPTIM ?= -O2 ;
742DEBUG ?= 0 ;
743
744
745# Set a sane default for whether this is a CI build.
746HAIKU_CONTINUOUS_INTEGRATION_BUILD ?= 0 ;
747
748
749# Set the defaults for PLATFORM and SUPPORTED_PLATFORMS. PLATFORM is only
750# overridden for targets to be built for the host platform. SUPPORTED_PLATFORMS
751# can be overridden by the author of a component.
752PLATFORM = $(TARGET_PLATFORM) ;
753SUPPORTED_PLATFORMS = haiku ;
754
755
756# Define two pseudo targets for the target and buildhost platform. The main
757# build rules (Cc, C++, As, ...) depend on these pseude targets such that global
758# initializations that are required before anything is built for a specific
759# platform can be forced by depending the pseudo target for the platform on the
760# initializations.
761# This is currently used to unpack the external headers from the
762# gcc_syslibs_devel build feature before anything is built for the target
763# platform.
764NotFile $(TARGET_PLATFORM) ;
765NotFile host ;
766
767
768# Instructs the Library rule to not make its object files temporary.
769# This is needed as some objects are used in a static library and for an
770# executable.
771KEEPOBJS = true ;
772
773
774# Set permissions to how they should be on the image.
775EXEMODE		= 755 ;
776FILEMODE	= 644 ;
777SHELLMODE	= 755 ;
778
779
780# output directories
781# TODO: Review this.
782HAIKU_DOCUMENTATION_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) documentation ] ;
783HAIKU_DOCUMENTATION_OBJECT_DIR ?= [ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR)
784	documentation ] ;
785
786# TODO: Rethink test stuff.
787HAIKU_TEST_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tests
788	$(TARGET_PLATFORM) $(HAIKU_ARCH) ] ;
789HAIKU_APP_TEST_DIR		?= [ FDirName $(HAIKU_TEST_DIR) apps ] ;
790HAIKU_APP_TEST_LIB_DIR 	?= [ FDirName $(HAIKU_APP_TEST_DIR) lib ] ;
791HAIKU_TMP_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tmp ] ;
792
793local architecture ;
794for architecture in $(HAIKU_PACKAGING_ARCHS) {
795	local baseDir
796		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(architecture) packaging ] ;
797	HAIKU_PACKAGES_DIR_$(architecture) = [ FDirName $(baseDir) packages ] ;
798	HAIKU_PACKAGES_BUILD_DIR_$(architecture)
799		= [ FDirName $(baseDir) packages_build ] ;
800	HAIKU_PACKAGE_REPOSITORIES_DIR_$(architecture)
801		= [ FDirName $(baseDir) repositories ] ;
802}
803
804
805HAIKU_PACKAGE_INFOS_DIR			= [ FDirName $(HAIKU_TOP) src data
806									package_infos ] ;
807
808TARGET_TEST_DIR				?= [ FDirName $(HAIKU_TEST_DIR)
809									$(TARGET_PLATFORM) ] ;
810TARGET_UNIT_TEST_DIR		?= [ FDirName $(TARGET_TEST_DIR) unittests ] ;
811TARGET_UNIT_TEST_LIB_DIR	?= [ FDirName $(TARGET_UNIT_TEST_DIR) lib ] ;
812
813# automatically setup the objects directory per subdirectory
814SUBDIRRULES += SetupObjectsDir ;
815
816# Add the standard (userland) warning flags variables to the ones restored in
817# every subdirectory. Thus we can easily meddle with them in subdirectories
818# with imported sources.
819AUTO_SET_UP_CONFIG_VARIABLES +=
820	HOST_WARNING_CCFLAGS HOST_WARNING_C++FLAGS
821	TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCHS)
822	TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCHS)
823	;
824
825# also add PLATFORM and SUPPORTED_PLATFORMS
826AUTO_SET_UP_CONFIG_VARIABLES += PLATFORM SUPPORTED_PLATFORMS ;
827
828
829# set up warnings
830local architecture ;
831for architecture in $(TARGET_PACKAGING_ARCHS) {
832	ArchitectureSetupWarnings $(architecture) ;
833}
834
835
836# set up architecture build features
837local architecture ;
838for architecture in $(TARGET_PACKAGING_ARCHS) {
839	InitArchitectureBuildFeatures $(architecture) ;
840}
841
842
843# The following directories cannot currently be compiled with DEBUG=1
844SetConfigVar DEBUG : HAIKU_TOP src add-ons disk_systems bfs : 0 : local ;
845SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio hda : 0 : local ;
846SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auich : 0 : local ; # fails with gcc4 only
847SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 auvia : 0 : local ; # fails with gcc4 only
848SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel drivers audio ac97 sis7018 : 0 : local ;
849SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems btrfs : 0 : local ;
850SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems ntfs libntfs : 0 : local ;
851SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems udf : 0 : local ;
852SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server : 0 : local ; # fails with gcc2 only
853SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems userlandfs server haiku : 0 : local ; # fails with gcc2 only
854SetConfigVar DEBUG : HAIKU_TOP src add-ons media media-add-ons dvb : 0 : local ;
855SetConfigVar DEBUG : HAIKU_TOP src add-ons print drivers gutenprint : 0 : local ;
856SetConfigVar DEBUG : HAIKU_TOP src servers input : 0 : local ;
857SetConfigVar DEBUG : HAIKU_TOP src servers media_addon : 0 : local ;
858SetConfigVar DEBUG : HAIKU_TOP src system boot loader file_systems bfs : 0 : local ;
859