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