xref: /haiku/build/jam/BuildSetup (revision b6b0567fbd186f8ce8a0c90bdc7a7b5b4c649678)
1
2# Variable naming conventions:
3# TARGET_*:	A build system variable specifying a property for building for
4#			the target platform (usually Haiku). E.g. TARGET_CC specifies the
5#			compiler when building a target for the target platform.
6# HOST_*:	A build system variable specifying a property of the platform
7#			hosting the build. E.g. HOST_CC specifies the compiler when
8#			building a target for the host platform (a build tool for
9#			instance).
10# HAIKU_*:	A build system variable specifying a build system property. Usually
11#			directory paths and the like.
12
13
14#pragma mark - container settings
15
16# Haiku image
17HAIKU_IMAGE_CONTAINER_NAME = haiku-image-container ;
18HAIKU_CONTAINER_GRIST on $(HAIKU_IMAGE_CONTAINER_NAME) = HaikuImage ;
19HAIKU_INCLUDE_IN_CONTAINER_VAR on $(HAIKU_IMAGE_CONTAINER_NAME)
20	= HAIKU_INCLUDE_IN_IMAGE ;
21HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_IMAGE_CONTAINER_NAME)
22	= HAIKU_IMAGE_INSTALL_TARGETS ;
23
24# network boot archive
25HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME = haiku-netboot-archive-container ;
26HAIKU_CONTAINER_GRIST on $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
27	= NetBootArchive ;
28# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
29HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME)
30	= HAIKU_NET_BOOT_ARCHIVE_INSTALL_TARGETS ;
31
32# alternative gcc archive
33HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME
34	= haiku-alternative-gcc-archive-container ;
35HAIKU_CONTAINER_GRIST on $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
36	= AlternativeGCCArchive ;
37# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
38HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_ALTERNATIVE_GCC_ARCHIVE_CONTAINER_NAME)
39	= HAIKU_ALTERNATIVE_GCC_ARCHIVE_INSTALL_TARGETS ;
40
41# boot floppy
42HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME = haiku-boot-floppy-container ;
43HAIKU_CONTAINER_GRIST on $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
44	= FloppyBootImage ;
45# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
46HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME)
47	= HAIKU_FLOPPY_BOOT_IMAGE_INSTALL_TARGETS ;
48
49# boot CD image
50HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME = haiku-boot-cd-container ;
51HAIKU_CONTAINER_GRIST on $(HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME) = CDBootImage ;
52# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
53HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_CD_BOOT_IMAGE_CONTAINER_NAME)
54	= HAIKU_CD_BOOT_IMAGE_INSTALL_TARGETS ;
55
56# boot CD for PPC image
57HAIKU_CD_BOOT_PPC_IMAGE_CONTAINER_NAME = haiku-boot-cd-ppc-container ;
58HAIKU_CONTAINER_GRIST on $(HAIKU_CD_BOOT_PPC_IMAGE_CONTAINER_NAME) = CDBootPPCImage ;
59# HAIKU_INCLUDE_IN_CONTAINER_VAR -- update only mode not supported
60HAIKU_INSTALL_TARGETS_VAR on $(HAIKU_CD_BOOT_PPC_IMAGE_CONTAINER_NAME)
61	= HAIKU_CD_BOOT_PPC_IMAGE_INSTALL_TARGETS ;
62
63# Haiku image/install defaults
64HAIKU_DEFAULT_IMAGE_NAME = haiku.image ;
65HAIKU_DEFAULT_IMAGE_DIR = $(HAIKU_OUTPUT_DIR) ;
66HAIKU_DEFAULT_VMWARE_IMAGE_NAME = haiku.vmdk ;
67HAIKU_DEFAULT_INSTALL_DIR = /Haiku ;
68HAIKU_DEFAULT_IMAGE_SIZE ?= 128 ; # 128 MB
69HAIKU_DEFAULT_IMAGE_LABEL ?= Haiku ;
70
71# Haiku CD defaults
72HAIKU_DEFAULT_CD_NAME = haiku-cd.iso ;
73HAIKU_DEFAULT_CD_DIR = $(HAIKU_OUTPUT_DIR) ;
74HAIKU_DEFAULT_CD_LABEL = Haiku ;
75
76# analyze and optionally replace jam's target parameters
77ProcessCommandLineArguments ;
78
79
80# include Timezones/libgccObjects
81{
82	local timezones = [ GLOB $(HAIKU_BUILD_OUTPUT_DIR) : Timezones ] ;
83	local libgccObjects = [ GLOB $(HAIKU_BUILD_OUTPUT_DIR) : libgccObjects ] ;
84
85	if ! ( $(timezones) && $(libgccObjects) ) {
86		ECHO "No `Timezones' or `libgccObjects' found in"
87			"$(HAIKU_BUILD_OUTPUT_DIR)!" ;
88		EXIT "Please run ./configure in the source tree's root directory"
89			"again!" ;
90	}
91
92	LOCATE on Timezones = $(HAIKU_BUILD_OUTPUT_DIR) ;
93	LOCATE on libgccObjects = $(HAIKU_BUILD_OUTPUT_DIR) ;
94
95	include Timezones ;
96	include libgccObjects ;
97}
98
99
100# supported debug levels
101HAIKU_DEBUG_LEVELS = 0 1 2 3 4 5 ;
102
103# BeOS, BONE, Dan0 compatible platforms
104HAIKU_BEOS_COMPATIBLE_PLATFORMS = haiku r5 bone dano haiku_host ;
105HAIKU_BONE_COMPATIBLE_PLATFORMS = haiku bone dano haiku_host ;
106HAIKU_DANO_COMPATIBLE_PLATFORMS = haiku dano haiku_host ;
107HAIKU_HAIKU_COMPATIBLE_PLATFORMS = haiku haiku_host ;
108
109# configuration header directories
110HAIKU_CONFIG_HEADERS = [ FDirName $(HAIKU_TOP) build user_config_headers ]
111	[ FDirName $(HAIKU_TOP) build config_headers ] ;
112
113
114#pragma mark -
115
116# haiku target platform settings
117
118# analyze GCC version
119HAIKU_GCC_VERSION = [ FAnalyzeGCCVersion HAIKU_GCC_RAW_VERSION ] ;
120
121# enable GCC -pipe option, if requested
122if $(HAIKU_USE_GCC_PIPE) = 1 {
123	HAIKU_GCC_BASE_FLAGS = -pipe ;
124}
125
126# disable strict aliasing on anything newer than gcc 2 as it may lead to
127# unexpected results. also disable the tree-vrp (value range propagation)
128# optimization for now as with the current gcc4 version we are using this
129# results in some broken code.
130# TODO: remove the -fno-strict-aliasing option when all code has been
131#		analyzed/fixed with regard to aliasing.
132# TODO: retest/remove the -fno-tree-vrp option as soon as we have updated our
133#		gcc4 compiler.
134if $(HAIKU_GCC_VERSION[1]) >= 3 {
135	HAIKU_GCC_BASE_FLAGS += -fno-strict-aliasing -fno-tree-vrp ;
136}
137
138# override gcc 2.95.3's header directory -- strictly necessary only when using
139# the BeOS native compiler (since its headers are incompatible), but it doesn't
140# harm for the cross-compiler either.
141if $(HAIKU_GCC_VERSION[1]) = 2 {
142	HAIKU_GCC_HEADERS_DIR = [ FDirName $(HAIKU_TOP) headers build gcc-2.95.3 ] ;
143}
144
145# the subdirectory into which the alternative GCC libraries are to be installed
146if $(HAIKU_GCC_VERSION[1]) = 2 {
147	HAIKU_ALTERNATIVE_GCC_LIB_SUBDIR = gcc2 ;
148} else {
149	HAIKU_ALTERNATIVE_GCC_LIB_SUBDIR = gcc4 ;
150}
151
152# initial state for flags etc.
153HAIKU_C++ ?= $(HAIKU_CC) ;
154HAIKU_LINK = $(HAIKU_CC) ;
155HAIKU_LINKFLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
156
157HAIKU_HDRS = [ FStandardHeaders ] ;
158HAIKU_CCFLAGS = $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
159HAIKU_C++FLAGS = $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
160HAIKU_KERNEL_CCFLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
161HAIKU_KERNEL_C++FLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
162HAIKU_DEFINES = __HAIKU__ ;
163HAIKU_NO_WERROR ?= 0 ;
164
165# distro compatibility level defines
166HAIKU_DISTRO_COMPATIBILITY ?= "default" ;
167switch $(HAIKU_DISTRO_COMPATIBILITY) {
168	case official	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_OFFICIAL ;
169	case compatible	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_COMPATIBLE ;
170	case "default"	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_DEFAULT ;
171	case *			: Exit "Invalid value for HAIKU_DISTRO_COMPATIBILITY:"
172						$(HAIKU_DISTRO_COMPATIBILITY) ;
173}
174
175# analyze the gcc machine spec to determine HAIKU_CPU
176switch $(HAIKU_GCC_MACHINE) {
177	case i386-*		: HAIKU_CPU = x86 ;
178	case i486-*		: HAIKU_CPU = x86 ;
179	case i586-*		: HAIKU_CPU = x86 ;
180	case i686-*		: HAIKU_CPU = x86 ;
181	case powerpc-*	: HAIKU_CPU = ppc ;
182	case m68k-*	: HAIKU_CPU = m68k ;
183	case mipsel-*	: HAIKU_CPU = mipsel ;
184	case arm-*	: HAIKU_CPU = arm ;
185	case * : Exit "Unsupported gcc target machine:" $(HAIKU_GCC_MACHINE) ;
186}
187
188switch $(HAIKU_CPU) {
189	case ppc :
190	{
191		HAIKU_DEFINES += __POWERPC__ ;
192		HAIKU_BOOT_PLATFORM = openfirmware ;
193		HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
194		# offset in floppy image (>= sizeof(haiku_loader))
195		HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
196	}
197	case arm :
198	{
199		HAIKU_DEFINES += __ARM__ ;
200		HAIKU_BOOT_PLATFORM = u-boot ;
201		HAIKU_BOOT_BOARD ?= verdex ;
202		HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
203			# in kB (there is not really a floppy on the gumstix ;) )
204		# offset in floppy image (>= sizeof(haiku_loader))
205		HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet
206		HAIKU_NO_WERROR = 1 ;
207			# we use #warning as placeholders for things to write...
208	}
209	case x86 :
210	{
211		HAIKU_DEFINES += __INTEL__ ;
212		HAIKU_BOOT_PLATFORM = bios_ia32 ;
213		HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
214		# offset in floppy image (>= sizeof(haiku_loader))
215		HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 300 ; # in kB
216
217		# yasm is required for target arch x86
218		if ! $(HAIKU_YASM) {
219			Exit "HAIKU_YASM not set. Please re-run configure." ;
220		}
221	}
222	case m68k :
223	{
224		HAIKU_DEFINES += __M68K__ ;
225		HAIKU_BOOT_PLATFORM = atari_m68k ;
226		HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB
227		# offset in floppy image (>= sizeof(haiku_loader))
228		HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 150 ; # in kB
229		HAIKU_NO_WERROR = 1 ;
230			# we use #warning as placeholders for things to write...
231	}
232	case mipsel :
233	{
234		HAIKU_DEFINES += __MIPSEL__ ;
235		# RouterBOARD firmware (ELF image over TFTP)
236		HAIKU_BOOT_PLATFORM = routerboot_mipsel ;
237		# offset in floppy image (>= sizeof(haiku_loader))
238		HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - todo/fixme
239		HAIKU_NO_WERROR = 1 ; # we use #warning as placeholders for things to write...
240	}
241	case * :
242		Exit "Currently unsupported target CPU:" $(HAIKU_CPU) ;
243}
244HAIKU_ARCH ?= $(HAIKU_CPU) ;
245HAIKU_ARCH_MACRO_DEFINE = ARCH_$(HAIKU_ARCH) ;
246HAIKU_DEFINES += $(HAIKU_ARCH_MACRO_DEFINE) ;
247HAIKU_DEFINES += BOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
248HAIKU_ATA_STACK ?= 0 ;
249
250# directories
251HAIKU_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) haiku ] ;
252HAIKU_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HAIKU_OBJECT_BASE_DIR) common ] ;
253HAIKU_ARCH_OBJECT_DIR = [ FDirName $(HAIKU_OBJECT_BASE_DIR) $(HAIKU_ARCH) ] ;
254HAIKU_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HAIKU_ARCH_OBJECT_DIR) common ] ;
255HAIKU_DEBUG_0_OBJECT_DIR = [ FDirName $(HAIKU_ARCH_OBJECT_DIR) release ] ;
256
257local level ;
258for level in $(HAIKU_DEBUG_LEVELS[2-]) {
259	HAIKU_DEBUG_$(level)_OBJECT_DIR
260		= [ FDirName $(HAIKU_ARCH_OBJECT_DIR) debug_$(level) ] ;
261}
262
263# set variables for gcc header options
264SetIncludePropertiesVariables HAIKU ;
265
266# assembler flags
267HAIKU_ASFLAGS = ;
268
269# C/C++ flags
270HAIKU_KERNEL_CCFLAGS += -finline -fno-builtin
271	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) ;
272HAIKU_KERNEL_C++FLAGS += -finline -fno-builtin -fno-exceptions
273	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) ;
274HAIKU_KERNEL_DEFINES += _KERNEL_MODE ;
275
276if $(HAIKU_GCC_VERSION[1]) >= 3 {
277	HAIKU_KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
278}
279
280if $(HAIKU_GCC_VERSION[1]) >= 4 {
281	HAIKU_C++FLAGS += -Wno-deprecated ;
282
283	if $(HAIKU_GCC_VERSION[2]) >= 3 {
284		HAIKU_KERNEL_CCFLAGS += -ffreestanding ;
285		HAIKU_KERNEL_C++FLAGS += -ffreestanding ;
286	}
287}
288
289HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
290HAIKU_KERNEL_PIC_LINKFLAGS = ;
291if $(HAIKU_ARCH) = ppc {
292	# Build a position independent PPC kernel. We need to be able to relocate
293	# the kernel, since the virtual address space layout at boot time is not
294	# fixed.
295	HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ;
296	HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
297}
298if $(HAIKU_ARCH) = m68k {
299	# We don't need a PIC kernel as it's always at the same place.
300	# it's actually needed to not use pic, else linking fails due to too large
301	# pc refs.
302	HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
303	HAIKU_KERNEL_PIC_LINKFLAGS = ;
304	# we don't want to have to handle emulating missing FPU opcodes for 040 and
305	# 060 in the kernel
306	HAIKU_KERNEL_CCFLAGS += -m68020-60 ;
307	HAIKU_KERNEL_C++FLAGS += -m68020-60 ;
308}
309if $(HAIKU_ARCH) = mipsel {
310	# todo: verify correctness of this
311	HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
312	HAIKU_KERNEL_PIC_LINKFLAGS = ;
313}
314
315# If the environment variable DEBUG_PRINTF is defined we define an equally
316# named macro to the variable value. Some components use the macro to allow
317# another function than printf() to print the debug output. The variable should
318# be set to the name of the alternative function.
319#
320if $(DEBUG_PRINTF) {
321	HAIKU_CCFLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
322	HAIKU_C++FLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
323}
324
325# warning flags
326HAIKU_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes
327	-Wpointer-arith -Wcast-align -Wsign-compare -Wno-multichar ;
328HAIKU_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy
329	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare
330	-Wno-multichar ;
331
332HAIKU_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes
333	-Wno-multichar ;
334HAIKU_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-multichar ;
335
336# debug flags
337HAIKU_DEBUG_FLAGS ?= -ggdb ;
338
339# debug 0: suppress asserts
340HAIKU_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
341HAIKU_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
342
343HAIKU_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
344HAIKU_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
345
346local level ;
347for level in $(HAIKU_DEBUG_LEVELS[2-]) {
348	local flags = $(HAIKU_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
349	HAIKU_DEBUG_$(level)_CCFLAGS			= $(flags) ;
350	HAIKU_DEBUG_$(level)_C++FLAGS			= $(flags) ;
351	HAIKU_KERNEL_DEBUG_$(level)_CCFLAGS		= $(flags) ;
352	HAIKU_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
353}
354
355if $(HAIKU_GCC_VERSION[1]) >= 3 {
356	# TODO: Temporary work-around. Should be defined in the compiler specs
357	HAIKU_LINKFLAGS += -Xlinker --no-undefined ;
358} else {
359	HAIKU_DEFINES += _BEOS_R5_COMPATIBLE_ ;
360}
361
362# private shared kernel/libroot headers
363HAIKU_PRIVATE_SYSTEM_HEADERS =
364	[ PrivateHeaders $(DOT) system system/arch/$(HAIKU_ARCH) ]
365;
366
367# private kernel headers to be used when compiling kernel code
368HAIKU_PRIVATE_KERNEL_HEADERS =
369	[ PrivateHeaders $(DOT) kernel libroot
370		kernel/boot/platform/$(HAIKU_BOOT_PLATFORM) ]
371	[ ArchHeaders $(HAIKU_ARCH) ]
372	$(HAIKU_PRIVATE_SYSTEM_HEADERS)
373;
374
375# Add some grist to the libgcc objects
376HAIKU_GCC_LIBGCC_OBJECTS = $(HAIKU_GCC_LIBGCC_OBJECTS:G=libgcc) ;
377
378# the C++ library
379if $(HAIKU_SHARED_LIBSTDC++) {
380	HAIKU_LIBSTDC++ = $(HAIKU_SHARED_LIBSTDC++) ;
381} else if $(HAIKU_STATIC_LIBSTDC++) {
382	HAIKU_LIBSTDC++ = $(HAIKU_STATIC_LIBSTDC++) ;
383} else {
384	HAIKU_LIBSTDC++ = libstdc++.r4.so ;
385	HAIKU_SHARED_LIBSTDC++ = $(HAIKU_LIBSTDC++) ;
386}
387
388# the C++ support library
389if $(HAIKU_SHARED_LIBSUPC++) {
390	HAIKU_LIBSUPC++ = $(HAIKU_SHARED_LIBSUPC++) ;
391} else if $(HAIKU_STATIC_LIBSUPC++) {
392	HAIKU_LIBSUPC++ = $(HAIKU_STATIC_LIBSUPC++) ;
393} else {
394	HAIKU_LIBSUPC++ = ;
395}
396
397# network libraries
398HAIKU_NETWORK_LIBS = network ;
399HAIKU_NETAPI_LIB = bnetapi ;
400HAIKU_SELECT_UNAME_ETC_LIB = ;	# libroot, against which we link anyway
401
402# library and executable glue code
403local commonGlueCode =
404	<src!system!glue>init_term_dyn.o
405	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
406	<src!system!glue!arch!$(HAIKU_ARCH)>crtn.o
407;
408HAIKU_LIBRARY_BEGIN_GLUE_CODE =
409	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
410	crtbegin.o
411	<src!system!glue>init_term_dyn.o
412;
413HAIKU_LIBRARY_END_GLUE_CODE =
414	crtend.o
415	<src!system!glue!arch!$(HAIKU_ARCH)>crtn.o
416;
417HAIKU_EXECUTABLE_BEGIN_GLUE_CODE =
418	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
419	crtbegin.o
420	<src!system!glue>start_dyn.o
421	<src!system!glue>init_term_dyn.o
422;
423HAIKU_EXECUTABLE_END_GLUE_CODE = $(HAIKU_LIBRARY_END_GLUE_CODE) ;
424HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = crtbegin.o
425	<src!system!glue>haiku_version_glue.o ;
426HAIKU_KERNEL_ADDON_END_GLUE_CODE = $(HAIKU_GCC_LIBGCC) crtend.o ;
427
428SEARCH on crtbegin.o crtend.o = $(HAIKU_GCC_LIB_DIR) ;
429
430HAIKU_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
431
432# TODO: The version stuff should probably go into a separate file and be made
433# available as macro, too.
434# Set our version number if not already set and mark it as a developer build
435if ! $(HAIKU_BUILD_VERSION) {
436	HAIKU_BUILD_VERSION ?= "1 0 0 a 1" ;
437	HAIKU_BUILD_DESCRIPTION ?= "Developer Build" ;
438}
439
440# If HAIKU_BUILD_VERSION is set, but HAIKU_BUILD_DESCRIPTION isn't, mark it as
441# an unknown build.
442HAIKU_BUILD_DESCRIPTION ?= "Unknown Build" ;
443
444# init library name map
445{
446	local i ;
447	for i in be game GL mail media midi midi2 network bnetapi opengl
448			screensaver root z textencoding tracker translation {
449		HAIKU_LIBRARY_NAME_MAP_$(i) = lib$(i).so ;
450	}
451	HAIKU_LIBRARY_NAME_MAP_libstdc++ = $(HAIKU_LIBSTDC++) ;
452	HAIKU_LIBRARY_NAME_MAP_libsupc++ = $(HAIKU_LIBSUPC++) ;
453	HAIKU_LIBRARY_NAME_MAP_input_server = <nogrist>input_server ;
454}
455
456
457#pragma mark -
458
459# host platform settings
460
461# enable GCC -m32 option, if requested
462if $(HAIKU_HOST_USE_32BIT) = 1 {
463	HOST_GCC_BASE_FLAGS = -m32 ;
464}
465
466
467# save jam's variables for the build platform
468HOST_AR				?= $(AR) ;
469HOST_CC				?= $(CC) ;
470HOST_C++			?= $(C++) ;
471HOST_LINK			?= $(LINK) ;
472HOST_LD				?= ld ;			# TODO: Fix this!
473HOST_OBJCOPY		?= objcopy ;	#
474HOST_RANLIB			?= $(RANLIB) ;
475HOST_CPPFLAGS		?= $(CPPFLAGS) ;
476HOST_CCFLAGS		?= $(HOST_GCC_BASE_FLAGS) $(CCFLAGS) ;
477HOST_C++FLAGS		?= $(HOST_GCC_BASE_FLAGS) $(C++FLAGS) ;
478HOST_LDFLAGS		?= $(HOST_GCC_BASE_FLAGS) $(LDFLAGS) ;
479HOST_LINKFLAGS		?= $(HOST_GCC_BASE_FLAGS) $(LINKFLAGS) ;
480HOST_DEFINES		?= $(DEFINES) ;
481HOST_HDRS			?= $(HDRS) ;
482
483
484# split up HOST_AR into the command name and flags
485HOST_AR				= [ Match "([^ ]*) *(.*)" : $(HOST_AR[1]) ]
486					  $(HOST_AR[2-]) ;
487HOST_ARFLAGS		= $(HOST_AR[2-]) ;
488HOST_AR				= $(HOST_AR[1]) ;
489HOST_UNARFLAGS		?= x ;
490
491# check the host platform compatibility
492SetPlatformCompatibilityFlagVariables HOST_PLATFORM : HOST : host
493	: linux openbsd freebsd darwin sunos cygwin ;
494
495if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd
496	|| $(HOST_PLATFORM) = darwin || $(HOST_PLATFORM) = cygwin
497	|| $(HOST_PLATFORM) = sunos || $(HOST_PLATFORM) = openbsd {
498	# don't use lex: otherwise rc will not work correctly
499	if $(LEX) = lex {
500		LEX = flex ;
501	}
502}
503
504if $(HOST_PLATFORM) = cygwin {
505	HOST_LINKFLAGS += -Xlinker --allow-multiple-definition -Xlinker
506		--enable-auto-import ;
507}
508
509HOST_CPU	?= $(OSPLAT:L) ;
510
511HOST_ARCH				?= $(HOST_CPU) ;
512HOST_ARCH_MACRO_DEFINE	= ARCH_$(HOST_CPU) ;
513
514# directories
515HOST_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) ] ;
516HOST_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) common ] ;
517HOST_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) $(HOST_ARCH) ] ;
518HOST_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) common ] ;
519HOST_DEBUG_0_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) release ] ;
520
521local level ;
522for level in $(HAIKU_DEBUG_LEVELS[2-]) {
523	HOST_DEBUG_$(level)_OBJECT_DIR
524		= [ FDirName $(HOST_ARCH_OBJECT_DIR) debug_$(level) ] ;
525}
526
527# analyze GCC version
528HOST_GCC_VERSION = [ FAnalyzeGCCVersion HOST_GCC_RAW_VERSION ] ;
529
530# set variables for gcc header options
531SetIncludePropertiesVariables HOST ;
532
533# assembler flags
534HOST_ASFLAGS = ;
535
536# C/C++ flags
537HOST_CCFLAGS += -Wno-multichar ;
538HOST_C++FLAGS += -Wno-multichar ;
539
540if $(HOST_PLATFORM) != cygwin {
541	HOST_PIC_CCFLAGS += -fPIC ;
542	HOST_PIC_C++FLAGS += -fPIC ;
543}
544
545HOST_KERNEL_CCFLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
546	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
547HOST_KERNEL_C++FLAGS += $(HOST_GCC_BASE_FLAGS) -finline -fno-builtin
548	-fno-exceptions -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
549HOST_KERNEL_DEFINES += _KERNEL_MODE ;
550
551HOST_KERNEL_PIC_CCFLAGS = -fno-pic ;
552HOST_KERNEL_PIC_LINKFLAGS = ;
553if $(HOST_ARCH) = ppc {
554	# Build a position independent PPC kernel. We need to be able to relocate
555	# the kernel, since the virtual address space layout at boot time is not
556	# fixed.
557	HOST_KERNEL_PIC_CCFLAGS = -fPIE ;
558	HOST_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
559}
560if $(HOST_ARCH) = m68k {
561	# Build a position independent M68K kernel. We need to be able to relocate
562	# the kernel, since the virtual address space layout at boot time is not
563	# fixed.
564	HOST_KERNEL_PIC_CCFLAGS = $(HAIKU_KERNEL_PIC_CCFLAGS) ;
565	HOST_KERNEL_PIC_LINKFLAGS = $(HAIKU_KERNEL_PIC_LINKFLAGS) ;
566}
567
568# warning flags
569HOST_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes -Wpointer-arith
570	-Wcast-align -Wsign-compare ;
571HOST_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy
572	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ;
573
574HOST_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes ;
575HOST_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs ;
576
577# debug flags
578switch $(HOST_PLATFORM) {
579	case haiku	: HOST_DEBUG_FLAGS ?= -ggdb ;
580	case haiku_host	: HOST_DEBUG_FLAGS ?= -ggdb ;
581	case linux	: HOST_DEBUG_FLAGS ?= -ggdb ;
582	case freebsd	: HOST_DEBUG_FLAGS ?= -ggdb ;
583	case darwin	: HOST_DEBUG_FLAGS ?= -ggdb ;
584	case *		: HOST_DEBUG_FLAGS ?= -g ;
585}
586
587# debug 0: suppress asserts
588HOST_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
589HOST_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
590
591HOST_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
592HOST_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
593
594local level ;
595for level in $(HAIKU_DEBUG_LEVELS[2-]) {
596	local flags = $(HOST_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
597	HOST_DEBUG_$(level)_CCFLAGS			= $(flags) ;
598	HOST_DEBUG_$(level)_C++FLAGS		= $(flags) ;
599	HOST_KERNEL_DEBUG_$(level)_CCFLAGS	= $(flags) ;
600	HOST_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
601}
602
603# ld flags
604if $(HOST_ARCH) = x86 && $(HAIKU_HOST_USE_32BIT) = 1 {
605	HOST_LDFLAGS += -melf_i386 ;
606}
607
608# private kernel headers do be used when compiling kernel code
609HOST_PRIVATE_KERNEL_HEADERS = ;
610
611# private shared kernel/libroot headers
612HOST_PRIVATE_SYSTEM_HEADERS = ;
613
614# under BeOS use copyattr instead of cp
615if $(HOST_PLATFORM_BEOS_COMPATIBLE)
616{
617	CP = copyattr --data ;
618}
619
620HOST_DEFINES += $(HOST_ARCH_MACRO_DEFINE) ;
621HOST_DEFINES += _NO_INLINE_ASM ;
622
623if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
624	# TODO: That's obviously not correct, but in the way the COMPILE_FOR_R5
625	# macro is used, it actually seems to mean r5/bone/dano.
626	# TODO: Deprecated. Remove!
627	HOST_DEFINES += COMPILE_FOR_R5 ;
628}
629
630# for builds of tools in the current environment
631HOST_BUILD_COMPATIBILITY_LIB_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) lib ] ;
632
633# For the generic attributes emulation: Target rm_attrs -- rm replacement that
634# also removes the attributes.
635HOST_RM_ATTRS_TARGET = ;
636
637if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
638	if $(HOST_GCC_VERSION[1]) < 3 {
639		HOST_LIBSTDC++ = stdc++.r4 ;
640	} else {
641		HOST_LIBSTDC++ = stdc++ ;
642	}
643
644	HOST_LIBROOT = root ;
645	HOST_STATIC_LIBROOT = $(HOST_LIBROOT) ;
646	HOST_LIBBE = be ;
647	HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR = ;
648	HOST_LIBRARY_NAME_MAP_input_server = /system/servers/input_server ;
649} else {
650	HOST_LIBSTDC++ = stdc++ ;
651	HOST_LIBROOT = libroot_build.so ;
652	HOST_STATIC_LIBROOT = libroot_build.a ;
653	HOST_LIBBE = libbe_build.so ;
654	if $(HOST_PLATFORM) = cygwin {
655		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
656			= "export PATH=$PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
657	} else if $(HOST_PLATFORM) = darwin {
658		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
659			= "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
660	} else {
661		HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
662			= "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
663	}
664
665	# the C++ support library
666	if $(HOST_GCC_VERSION[1]) < 3 {
667		HOST_LIBSUPC++ = ;
668	} else {
669		HOST_LIBSUPC++ = supc++ ;
670	}
671
672	if $(HOST_PLATFORM) = darwin {
673		# part of the C++ runtime lives in libstdc++ on Darwin
674		HOST_LIBSUPC++ = gcc_s.1 stdc++ ;
675		HOST_LIBSTDC++ = ;
676	}
677
678	# Unlike glibc FreeBSD's libc doesn't have built-in regex support.
679	if $(HOST_PLATFORM) = freebsd {
680		HOST_LIBROOT += /usr/lib/libgnuregex.so ;
681		HOST_STATIC_LIBROOT += /usr/lib/libgnuregex.so ;
682	} else if $(HOST_PLATFORM) = darwin {
683		HOST_LIBROOT += /opt/local/lib/libgnuregex.dylib ;
684		HOST_STATIC_LIBROOT += /opt/local/lib/libgnuregex.dylib ;
685	}
686
687
688	# The BeOS compilers define __INTEL__ respectively __POWERPC__. On the
689	# build platform we need to make sure, this is also defined.
690	if $(HOST_CPU) = x86 {
691		HOST_DEFINES += __INTEL__ ;
692	} else if $(HOST_CPU) = ppc {
693		HOST_DEFINES += __POWERPC__ ;
694	} else if $(HOST_CPU) = m68k {
695		HOST_DEFINES += __M68K__ ;
696	} else if $(HOST_CPU) = mipsel {
697		HOST_DEFINES += __MIPSEL__ ;
698	}
699
700	# Supposing this is a glibc platform, let's try to get features like large
701	# file support, ISO C 99 definitions, etc. On some platforms we need to
702	# request 64 bit off_t support explicitely.
703	HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 ;
704
705	# On Linux with xattr support we can use it for our attribute emulation,
706	# which is somewhat more robust.
707	if $(HAIKU_HOST_USE_XATTR) = 1 {
708		HOST_DEFINES += HAIKU_HOST_USE_XATTR ;
709	} else {
710		# Otherwise the generic attribute emulation is used, which uses a
711		# directory per file to store its attribute. We need to redefine RM so
712		# that the attributes are removed as well. We use a wrapper script,
713		# which invokes a build tool. If the build tool hasn't been built yet,
714		# the normal "rm" is used and the attributes are leaked (likely there
715		# aren't any yet).
716		RM = $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ";"
717			[ FDirName $(HAIKU_TOP) build scripts rm_attrs ]
718			[ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) $(HOST_ARCH) release
719				tools rm_attrs ] -f ;
720			# assumes that rm_attrs is built with debugging disabled
721		HOST_RM_ATTRS_TARGET = <build>rm_attrs ;
722	}
723}
724
725# network libraries
726if $(HOST_PLATFORM_HAIKU_COMPATIBLE) {
727	HOST_NETWORK_LIBS = network ;
728	HOST_NETAPI_LIB = bnetapi ;
729	HOST_SELECT_UNAME_ETC_LIB = ;	# libroot
730} else if $(HOST_PLATFORM_BONE_COMPATIBLE) {
731	HOST_NETWORK_LIBS = socket bind ;
732	HOST_NETAPI_LIB = bnetapi ;
733	HOST_SELECT_UNAME_ETC_LIB = ;	# libroot
734} else if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
735	HOST_NETWORK_LIBS = net ;
736	HOST_NETAPI_LIB = netapi ;
737	HOST_SELECT_UNAME_ETC_LIB = net ;
738} else if $(HOST_PLATFORM) = "sunos" {
739	HOST_NETWORK_LIBS = xnet ;
740	HOST_NETAPI_LIB = ;
741	HOST_SELECT_UNAME_ETC_LIB = ;
742} else {
743	# Linux,...
744	HOST_NETWORK_LIBS = ;
745	HOST_NETAPI_LIB = ;
746	HOST_SELECT_UNAME_ETC_LIB = ;
747}
748
749# define the executable MIME type
750HOST_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
751
752if $(METROWERKS) {
753	# at least parts of Haiku still can be compiled with
754	# the Metrowerks compiler on BeOS/PPC
755	HOST_EXECUTABLE_MIME_TYPE = "application/x-be-executable" ;
756}
757
758# Be API compatibility
759HOST_BE_API_HEADERS = ;
760HOST_BE_API_CCFLAGS = ;
761HOST_BE_API_C++FLAGS = ;
762
763if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) {
764	HOST_BE_API_HEADERS =
765		[ FDirName $(HAIKU_TOP) headers build ]
766		[ FDirName $(HAIKU_TOP) headers build os ]
767		[ FDirName $(HAIKU_TOP) headers build os app ]
768		[ FDirName $(HAIKU_TOP) headers build os drivers ]
769		[ FDirName $(HAIKU_TOP) headers build os kernel ]
770		[ FDirName $(HAIKU_TOP) headers build os interface ]
771		[ FDirName $(HAIKU_TOP) headers build os opengl ]
772		[ FDirName $(HAIKU_TOP) headers build os storage ]
773		[ FDirName $(HAIKU_TOP) headers build os support ]
774	;
775	HOST_BE_API_CCFLAGS = -include BeOSBuildCompatibility.h ;
776	HOST_BE_API_C++FLAGS = $(HOST_BE_API_CCFLAGS) ;
777}
778
779# Add directory with system headers we need when building something for the host
780# platform, e.g. containing missing POSIX/GNU headers.
781HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host $(HOST_PLATFORM) ] ;
782
783# For all versions of BeOS also add the common beos directory.
784if $(HOST_PLATFORM) in r5 bone dano {
785	HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host beos_common ] ;
786}
787
788
789#pragma mark -
790
791# target platform settings
792
793# check the target platform compatibility
794SetPlatformCompatibilityFlagVariables TARGET_PLATFORM : TARGET : target ;
795
796# check the compatibility between host and target platform
797if $(TARGET_PLATFORM) != haiku {
798	if ! $(HOST_PLATFORM_($(TARGET_PLATFORM))_COMPATIBLE) {
799		Exit ERROR: The host platform is not compatible with target platform
800			$(TARGET_PLATFORM). ;
801	}
802}
803
804# Set TARGET_* variables either from HAIKU_* or HOST_* depending on the
805# specified TARGET_PLATFORM.
806
807local buildVars =
808	ARCH CPU GCC_VERSION
809
810	AR CC C++ LD OBJCOPY RANLIB
811
812	INCLUDES_SEPARATOR LOCAL_INCLUDES_OPTION SYSTEM_INCLUDES_OPTION
813
814	HDRS CPPFLAGS CCFLAGS C++FLAGS LDFLAGS LINK LINKFLAGS DEFINES
815	ARFLAGS UNARFLAGS
816	KERNEL_DEFINES
817
818	KERNEL_CCFLAGS KERNEL_C++FLAGS
819	KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS
820	WARNING_CCFLAGS WARNING_C++FLAGS
821
822	KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
823
824	DEBUG_FLAGS
825
826	DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
827
828	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS
829	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
830
831	PRIVATE_KERNEL_HEADERS
832	PRIVATE_SYSTEM_HEADERS
833
834	LIBSTDC++ LIBSUPC++
835	STATIC_LIBSTDC++ STATIC_LIBSUPC++
836
837	NETWORK_LIBS NETAPI_LIB SELECT_UNAME_ETC_LIB
838
839	ARCH_MACRO_DEFINE EXECUTABLE_MIME_TYPE
840
841	OBJECT_BASE_DIR COMMON_ARCH_OBJECT_DIR COMMON_DEBUG_OBJECT_DIR
842	DEBUG_$(HAIKU_DEBUG_LEVELS)_OBJECT_DIR
843;
844
845if $(TARGET_PLATFORM) = haiku {
846	local var ;
847	for var in $(buildVars) {
848		TARGET_$(var) = $(HAIKU_$(var)) ;
849	}
850
851	TARGET_GCC_LIB_DIR			= $(HAIKU_GCC_LIB_DIR) ;
852	TARGET_GCC_HEADERS_DIR		= $(HAIKU_GCC_HEADERS_DIR) ;
853	TARGET_GCC_LIBGCC			= $(HAIKU_GCC_LIBGCC) ;
854	TARGET_GCC_LIBGCC_OBJECTS	= $(HAIKU_GCC_LIBGCC_OBJECTS) ;
855
856	TARGET_BOOT_PLATFORM		?= $(HAIKU_BOOT_PLATFORM) ;
857	TARGET_BOOT_BOARD		?= $(HAIKU_BOOT_BOARD) ;
858
859	TARGET_LIBRARY_NAME_MAP		= HAIKU_LIBRARY_NAME_MAP ;
860
861} else {
862	local var ;
863	for var in $(buildVars) {
864		TARGET_$(var) = $(HOST_$(var)) ;
865	}
866
867	TARGET_GCC_LIB_DIR			= ;
868	TARGET_GCC_HEADERS_DIR		= ;
869	TARGET_GCC_LIBGCC			= ;
870	TARGET_GCC_LIBGCC_OBJECTS	= ;
871
872	TARGET_BOOT_PLATFORM		= ;
873	TARGET_BOOT_BOARD		= ;
874
875	TARGET_LIBRARY_NAME_MAP		= HOST_LIBRARY_NAME_MAP ;
876}
877
878# define macro, for identifying the platform
879switch $(TARGET_PLATFORM) {
880	case r5			: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_BEOS ;
881	case bone		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_BONE ;
882	case dano		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_DANO ;
883	case haiku_host	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
884	case haiku		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
885	case linux		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LINUX ;
886	case freebsd	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_FREEBSD ;
887	case darwin		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_DARWIN ;
888	case cygwin		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_CYGWIN ;
889	case sunos		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_SUNOS ;
890	case libbe_test	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LIBBE_TEST ;
891}
892
893# define macro, for identifying the host platform
894switch $(HOST_PLATFORM) {
895	case r5			: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_BEOS ;
896	case bone		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_BONE ;
897	case dano		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DANO ;
898	case haiku_host	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_HAIKU ;
899	case linux		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_LINUX ;
900	case freebsd	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_FREEBSD ;
901	case darwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DARWIN ;
902	case cygwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_CYGWIN ;
903	case sunos		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_SUNOS ;
904}
905
906
907#pragma mark -
908
909# In case we build for a BeOS compatible platform, but not for Haiku, we
910# include the HaikuBuildCompatibility.h header and link against
911# libhaikucompat.a.
912
913if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) && $(TARGET_PLATFORM_BEOS_COMPATIBLE) {
914	# headers and flags
915	local compatibilityHeader = -include [ FDirName $(HAIKU_TOP) headers build
916		HaikuBuildCompatibility.h ] ;
917	TARGET_CCFLAGS += $(compatibilityHeader) ;
918	TARGET_C++FLAGS += $(compatibilityHeader) ;
919
920	# compatibility library
921	TARGET_HAIKU_COMPATIBILITY_LIBS = libhaikucompat.a ;
922}
923
924# special target libbe_test
925
926if $(TARGET_PLATFORM) = libbe_test {
927	# headers and flags
928	TARGET_HDRS +=
929		[ PublicHeaders $(DOT) app drivers game interface kernel storage
930			support ]
931		[ PrivateHeaders $(DOT) ] ;
932	TARGET_DEFINES += __HAIKU__ ;
933
934	TARGET_PRIVATE_SYSTEM_HEADERS =
935		[ PrivateHeaders $(DOT) system system/arch/$(TARGET_ARCH) ] ;
936
937	# directories
938	TARGET_OBJECT_BASE_DIR
939		= [ FDirName $(HAIKU_OBJECT_DIR) $(TARGET_PLATFORM) ] ;
940	TARGET_COMMON_ARCH_OBJECT_DIR
941		= [ FDirName $(TARGET_OBJECT_BASE_DIR) common ] ;
942	TARGET_ARCH_OBJECT_DIR
943		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(TARGET_ARCH) ] ;
944	TARGET_COMMON_DEBUG_OBJECT_DIR
945		= [ FDirName $(TARGET_ARCH_OBJECT_DIR) common ] ;
946	TARGET_DEBUG_0_OBJECT_DIR
947		= [ FDirName $(TARGET_ARCH_OBJECT_DIR) release ] ;
948
949	local level ;
950	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
951		TARGET_DEBUG_$(level)_OBJECT_DIR
952			= [ FDirName $(TARGET_ARCH_OBJECT_DIR) debug_$(level) ] ;
953	}
954
955	# library name map
956	TARGET_LIBRARY_NAME_MAP = LIBBE_LIBRARY_NAME_MAP ;
957	LIBBE_LIBRARY_NAME_MAP_be = libbe_test.so ;
958}
959
960
961#pragma mark -
962
963# common stuff
964
965# start with a clean state
966CCFLAGS = ;
967C++FLAGS = ;
968DEFINES = ;
969
970# Set CC, C++, LINK to invalid values, so that we realize early, that we use
971# the wrong compiler.
972CC = bad-cc ;
973C++ = bad-c++ ;
974LINK = bad-link ;
975
976# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
977# issues, they deprecated that nice function. This will enable it again:
978C++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
979# Same for buggy find_directory threadsafety fixes
980C++FLAGS += -D_ZETA_TS_FIND_DIR_=1 ;
981	# TODO: Doesn't really belong here.
982
983
984# Defaults for warnings, optimization, and debugging.
985#
986WARNINGS ?= 1 ;
987OPTIM ?= -O2 ;
988DEBUG ?= 0 ;
989
990
991# Set the defaults for PLATFORM and SUPPORTED_PLATFORMS. PLATFORM is only
992# overridden for targets to be built for the host platform. SUPPORTED_PLATFORMS
993# can be overridden by the author of a component.
994PLATFORM = $(TARGET_PLATFORM) ;
995SUPPORTED_PLATFORMS = haiku ;
996
997
998# Instructs the Library rule to not make its object files temporary.
999# This is needed as some objects are used in a static library and for an
1000# executable.
1001KEEPOBJS = true ;
1002
1003
1004# Set permissions to how they should be on the image.
1005EXEMODE		= 755 ;
1006FILEMODE	= 644 ;
1007SHELLMODE	= 755 ;
1008
1009
1010# output directories
1011# TODO: Review this.
1012HAIKU_DOCUMENTATION_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) documentation ] ;
1013HAIKU_DOCUMENTATION_OBJECT_DIR ?= [ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR)
1014	documentation ] ;
1015
1016# TODO: Rethink test stuff.
1017HAIKU_TEST_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tests
1018	$(TARGET_PLATFORM) $(HAIKU_ARCH) ] ;
1019HAIKU_APP_TEST_DIR		?= [ FDirName $(HAIKU_TEST_DIR) apps ] ;
1020HAIKU_APP_TEST_LIB_DIR 	?= [ FDirName $(HAIKU_APP_TEST_DIR) lib ] ;
1021HAIKU_TMP_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tmp ] ;
1022
1023HAIKU_PACKAGE_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) packages ] ;
1024HAIKU_PACKAGE_OBJECT_DIR ?= [ FDirName $(HAIKU_OBJECT_DIR) packages ] ;
1025
1026TARGET_TEST_DIR				?= [ FDirName $(HAIKU_TEST_DIR)
1027									$(TARGET_PLATFORM) ] ;
1028TARGET_UNIT_TEST_DIR		?= [ FDirName $(TARGET_TEST_DIR) unittests ] ;
1029TARGET_UNIT_TEST_LIB_DIR	?= [ FDirName $(TARGET_UNIT_TEST_DIR) lib ] ;
1030
1031# automatically setup the objects directory per subdirectory
1032SUBDIRRULES += SetupObjectsDir ;
1033
1034# Add the standard (userland) warning flags variables to the ones restored in
1035# every subdirectory. Thus we can easily meddle with them in subdirectories
1036# with imported sources.
1037AUTO_SET_UP_CONFIG_VARIABLES +=
1038	HOST_WARNING_CCFLAGS HOST_WARNING_C++FLAGS
1039	TARGET_WARNING_CCFLAGS TARGET_WARNING_C++FLAGS
1040
1041	# also add PLATFORM and SUPPORTED_PLATFORMS
1042	PLATFORM SUPPORTED_PLATFORMS
1043;
1044
1045
1046# enable -Werror for certain parts of the source tree
1047
1048if $(HAIKU_GCC_VERSION[1]) = 2 {
1049	rule EnableWerror dirTokens : scope {
1050		AppendToConfigVar CCFLAGS : HAIKU_TOP $(dirTokens) : -Werror
1051			: $(scope) ;
1052		AppendToConfigVar C++FLAGS : HAIKU_TOP $(dirTokens) : -Werror
1053			: $(scope) ;
1054	}
1055} else {
1056	# -Wuninitialized gives too many false positives.
1057	rule EnableWerror dirTokens : scope {
1058		AppendToConfigVar CCFLAGS : HAIKU_TOP $(dirTokens)
1059			: -Werror -Wno-error=uninitialized : $(scope) ;
1060		AppendToConfigVar C++FLAGS : HAIKU_TOP $(dirTokens)
1061			: -Werror -Wno-error=uninitialized : $(scope) ;
1062	}
1063}
1064
1065# Work-around for GCC 2 problem -- despite -Wno-multichar it reports
1066# multichar warnings in headers/private/kernel/debugger_keymaps.h included by
1067# src/system/kernel/arch/x86/arch_debug_console.c.
1068if $(HAIKU_GCC_VERSION[1]) = 2 {
1069	local file = <src!system!kernel!arch!x86>arch_debug_console.o ;
1070	CCFLAGS on $(file) = [ on $(file) return $(CCFLAGS) ] ;
1071}
1072
1073if $(HAIKU_NO_WERROR) != 1 {
1074	EnableWerror src kits app ;
1075	EnableWerror src kits interface ;
1076	EnableWerror src kits storage ;
1077	EnableWerror src kits support ;
1078	EnableWerror src system kernel ;
1079	EnableWerror src system runtime_loader ;
1080	EnableWerror src add-ons kernel file_systems bfs ;
1081	EnableWerror src add-ons kernel file_systems userlandfs ;
1082}
1083
1084