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