xref: /haiku/build/jam/BuildSetup (revision 14e3d1b5768e7110b3d5c0855833267409b71dbb)
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# analyze an optionally replace jam's target parameters
15HAIKU_ORIGINAL_JAM_TARGETS = $(JAM_TARGETS) ;
16if $(JAM_TARGETS) {
17	# If the target to be built is "all" (i.e. the default) and we're in the
18	# output directory, the root directory of the build system, or in "src/", we
19	# change the target to be built to "haiku-image".
20	if $(JAM_TARGETS) = all {
21		if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src {
22			JAM_TARGETS = haiku-image ;
23		}
24
25	# The "run" target allows for running arbitrary command lines containing
26	# build system targets, which are built and replaced accordingly.
27	} else if $(JAM_TARGETS[1]) = run && $(JAM_TARGETS[2]) {
28		local run = [ RunCommandLine $(JAM_TARGETS[2-]) ] ;
29		JAM_TARGETS = $(run) ;
30
31	# "update-image", "update-vmware-image", and "update-install" targets allow
32	# for updating only specific targets in the image/installation dir.
33	} else if $(JAM_TARGETS[1]) = update-image
34		|| $(JAM_TARGETS[1]) = update-vmware-image
35		|| $(JAM_TARGETS[1]) = update-install {
36		HAIKU_IMAGE_UPDATE_ONLY = 1 ;
37		HAIKU_INCLUDE_IN_IMAGE on $(JAM_TARGETS[2-]) = 1 ;
38
39		if $(JAM_TARGETS[1]) = update-image {
40			JAM_TARGETS = haiku-image ;
41		} else if $(JAM_TARGETS[1]) = update-vmware-image {
42			JAM_TARGETS = haiku-vmware-image ;
43		} else {
44			JAM_TARGETS = install-haiku ;
45		}
46	}
47}
48
49
50# Include BuildConfig/Timezones/libgccObjects
51{
52	local buildConfig = [ GLOB $(HAIKU_BUILD_OUTPUT_DIR) : BuildConfig ] ;
53	local timezones = [ GLOB $(HAIKU_BUILD_OUTPUT_DIR) : Timezones ] ;
54	local libgccObjects = [ GLOB $(HAIKU_BUILD_OUTPUT_DIR) : libgccObjects ] ;
55
56	if ! $(buildConfig) {
57		ECHO "No `BuildConfig' found in $(HAIKU_BUILD_OUTPUT_DIR)!" ;
58		EXIT "Run ./configure in the source tree's root directory first!" ;
59	}
60	if ! ( $(timezones) && $(libgccObjects) ) {
61		ECHO "No `Timezones' or `libgccObjects' found in $(HAIKU_BUILD_OUTPUT_DIR)!" ;
62		EXIT "Please run ./configure in the source tree's root directory again!" ;
63	}
64
65	LOCATE on BuildConfig = $(HAIKU_BUILD_OUTPUT_DIR) ;
66	LOCATE on Timezones = $(HAIKU_BUILD_OUTPUT_DIR) ;
67	LOCATE on libgccObjects = $(HAIKU_BUILD_OUTPUT_DIR) ;
68
69	include BuildConfig ;
70	include Timezones ;
71	include libgccObjects ;
72}
73
74
75# supported debug levels
76HAIKU_DEBUG_LEVELS = 0 1 2 3 4 5 ;
77
78# BeOS, BONE, Dan0 compatible platforms
79HAIKU_BEOS_COMPATIBLE_PLATFORMS = haiku r5 bone dano ;
80HAIKU_BONE_COMPATIBLE_PLATFORMS = haiku bone dano ;
81HAIKU_DANO_COMPATIBLE_PLATFORMS = haiku dano ;
82
83
84#pragma mark -
85
86# haiku target platform settings
87
88# enable GCC -pipe option, if requested
89if $(HAIKU_USE_GCC_PIPE) = 1 {
90	HAIKU_GCC_BASE_FLAGS = -pipe ;
91}
92
93# initial state for flags etc.
94HAIKU_C++ ?= $(HAIKU_CC) ;
95HAIKU_LINK = $(HAIKU_CC) ;
96HAIKU_LINKFLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
97
98HAIKU_HDRS = [ FStandardHeaders ] ;
99HAIKU_CCFLAGS = $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
100HAIKU_C++FLAGS = $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
101HAIKU_KERNEL_CCFLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
102HAIKU_KERNEL_C++FLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
103HAIKU_DEFINES = __HAIKU__ ;
104
105# distro compatibility level defines
106HAIKU_DISTRO_COMPATIBILITY ?= "default" ;
107switch $(HAIKU_DISTRO_COMPATIBILITY) {
108	case official	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_OFFICIAL ;
109	case compatible	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_COMPATIBLE ;
110	case "default"	: HAIKU_DEFINES += HAIKU_DISTRO_COMPATIBILITY_DEFAULT ;
111	case *			: Exit "Invalid value for HAIKU_DISTRO_COMPATIBILITY:"
112						$(HAIKU_DISTRO_COMPATIBILITY) ;
113}
114
115# analyze the gcc machine spec to determine HAIKU_CPU
116switch $(HAIKU_GCC_MACHINE) {
117	case i386-*		: HAIKU_CPU = x86 ;
118	case i486-*		: HAIKU_CPU = x86 ;
119	case i586-*		: HAIKU_CPU = x86 ;
120	case i686-*		: HAIKU_CPU = x86 ;
121	case powerpc-*	: HAIKU_CPU = ppc ;
122	case * : Exit "Unsupported gcc target machine:" $(HAIKU_GCC_MACHINE) ;
123}
124
125switch $(HAIKU_CPU) {
126	case ppc :
127	{
128		HAIKU_DEFINES += __POWERPC__ ;
129		HAIKU_BOOT_PLATFORM = openfirmware ;
130	}
131	case x86 :
132	{
133		HAIKU_DEFINES += __INTEL__ ;
134		HAIKU_BOOT_PLATFORM = bios_ia32 ;
135	}
136	case * :
137		Exit "Currently unsupported target CPU:" $(HAIKU_CPU) ;
138}
139HAIKU_ARCH ?= $(HAIKU_CPU) ;
140HAIKU_ARCH_MACRO_DEFINE = ARCH_$(HAIKU_ARCH) ;
141HAIKU_DEFINES += $(HAIKU_ARCH_MACRO_DEFINE) ;
142
143# directories
144HAIKU_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) haiku ] ;
145HAIKU_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HAIKU_OBJECT_BASE_DIR) common ] ;
146HAIKU_ARCH_OBJECT_DIR = [ FDirName $(HAIKU_OBJECT_BASE_DIR) $(HAIKU_ARCH) ] ;
147HAIKU_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HAIKU_ARCH_OBJECT_DIR) common ] ;
148HAIKU_DEBUG_0_OBJECT_DIR = [ FDirName $(HAIKU_ARCH_OBJECT_DIR) release ] ;
149
150local level ;
151for level in $(HAIKU_DEBUG_LEVELS[2-]) {
152	HAIKU_DEBUG_$(level)_OBJECT_DIR
153		= [ FDirName $(HAIKU_ARCH_OBJECT_DIR) debug_$(level) ] ;
154}
155
156# analyze GCC version
157HAIKU_GCC_VERSION = [ FAnalyzeGCCVersion HAIKU_GCC_RAW_VERSION ] ;
158
159# set variables for gcc header options
160SetIncludePropertiesVariables HAIKU ;
161
162# assembler flags
163HAIKU_ASFLAGS = ;
164
165# C/C++ flags
166HAIKU_CCFLAGS += -Wno-multichar ;
167HAIKU_C++FLAGS += -Wno-multichar ;
168
169HAIKU_KERNEL_CCFLAGS += -finline -fno-builtin -Wno-multichar
170	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
171HAIKU_KERNEL_C++FLAGS += -finline -fno-builtin -fno-exceptions -Wno-multichar
172	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
173
174if $(HAIKU_GCC_VERSION[1]) >= 3 {
175	HAIKU_KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
176}
177
178if $(HAIKU_GCC_VERSION[1]) >= 4 {
179	HAIKU_C++FLAGS += -Wno-deprecated ;
180}
181
182HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ;
183HAIKU_KERNEL_PIC_LINKFLAGS = ;
184if $(HAIKU_ARCH) = ppc {
185	# Build a position independent PPC kernel. We need to be able to relocate
186	# the kernel, since the virtual address space layout at boot time is not
187	# fixed.
188	HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ;
189	HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
190}
191
192# If the environment variable DEBUG_PRINTF is defined we define an equally
193# named macro to the variable value. Some components use the macro to allow
194# another function than printf() to print the debug output. The variable should
195# be set to the name of the alternative function.
196#
197if $(DEBUG_PRINTF) {
198	HAIKU_CCFLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
199	HAIKU_C++FLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
200}
201
202# warning flags
203HAIKU_WARNING_CCFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wcast-align
204	-Wsign-compare ;
205HAIKU_WARNING_C++FLAGS = -Wall -Wno-ctor-dtor-privacy
206	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ;
207
208HAIKU_KERNEL_WARNING_CCFLAGS = -Wall -Wmissing-prototypes ;
209HAIKU_KERNEL_WARNING_C++FLAGS = -Wall ;
210
211# debug flags
212HAIKU_DEBUG_FLAGS ?= -ggdb ;
213
214# debug 0: suppress asserts
215HAIKU_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
216HAIKU_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
217
218HAIKU_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
219HAIKU_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
220
221local level ;
222for level in $(HAIKU_DEBUG_LEVELS[2-]) {
223	local flags = $(HAIKU_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
224	HAIKU_DEBUG_$(level)_CCFLAGS			= $(flags) ;
225	HAIKU_DEBUG_$(level)_C++FLAGS			= $(flags) ;
226	HAIKU_KERNEL_DEBUG_$(level)_CCFLAGS		= $(flags) ;
227	HAIKU_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
228}
229
230if $(HAIKU_GCC_VERSION[1]) >= 3 {
231	# TODO: Temporary work-around. Should be defined in the compiler specs
232	HAIKU_LINKFLAGS += -Xlinker --no-undefined ;
233} else {
234	HAIKU_DEFINES += _BEOS_R5_COMPATIBLE_ ;
235}
236
237# private kernel headers do be used when compiling kernel code
238HAIKU_PRIVATE_KERNEL_HEADERS =
239	[ PrivateHeaders $(DOT) kernel libroot
240		kernel/boot/platform/$(HAIKU_BOOT_PLATFORM) ]
241	[ ArchHeaders $(HAIKU_ARCH) ]
242;
243
244# Add some grist to the libgcc objects
245HAIKU_GCC_LIBGCC_OBJECTS = $(HAIKU_GCC_LIBGCC_OBJECTS:G=libgcc) ;
246
247# the C++ library
248if $(HAIKU_SHARED_LIBSTDC++) {
249	HAIKU_LIBSTDC++ = $(HAIKU_SHARED_LIBSTDC++) ;
250} else if $(HAIKU_STATIC_LIBSTDC++) {
251	HAIKU_LIBSTDC++ = $(HAIKU_STATIC_LIBSTDC++) ;
252} else {
253	HAIKU_LIBSTDC++ = libstdc++.r4.so ;
254}
255
256# the C++ support library
257if $(HAIKU_SHARED_LIBSUPC++) {
258	HAIKU_LIBSUPC++ = $(HAIKU_SHARED_LIBSUPC++) ;
259} else if $(HAIKU_STATIC_LIBSUPC++) {
260	HAIKU_LIBSUPC++ = $(HAIKU_STATIC_LIBSUPC++) ;
261} else {
262	HAIKU_LIBSUPC++ = ;
263}
264
265# library and executable glue code
266local commonGlueCode =
267	<src!system!glue>init_term_dyn.o
268	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
269	<src!system!glue!arch!$(HAIKU_ARCH)>crtn.o
270;
271HAIKU_LIBRARY_BEGIN_GLUE_CODE =
272	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
273	crtbegin.o
274	<src!system!glue>init_term_dyn.o
275;
276HAIKU_LIBRARY_END_GLUE_CODE =
277	# TODO: For the time being always link against libsupc++.a.
278	$(HAIKU_STATIC_LIBSUPC++)
279	crtend.o
280	<src!system!glue!arch!$(HAIKU_ARCH)>crtn.o
281;
282HAIKU_EXECUTABLE_BEGIN_GLUE_CODE =
283	<src!system!glue!arch!$(HAIKU_ARCH)>crti.o
284	crtbegin.o
285	<src!system!glue>start_dyn.o
286	<src!system!glue>init_term_dyn.o
287;
288HAIKU_EXECUTABLE_END_GLUE_CODE = $(HAIKU_LIBRARY_END_GLUE_CODE) ;
289HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = crtbegin.o ;
290HAIKU_KERNEL_ADDON_END_GLUE_CODE = crtend.o ;
291
292SEARCH on crtbegin.o crtend.o = $(HAIKU_GCC_LIB_DIR) ;
293
294HAIKU_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
295
296# TODO: The version stuff should probably go into a separate file and be made
297# available as macro, too.
298# Set our version number if not already set and mark it as a developer build
299if ! $(HAIKU_BUILD_VERSION) {
300	HAIKU_BUILD_VERSION ?= "1 0 0 a 1" ;
301	HAIKU_BUILD_DESCRIPTION ?= "Developer Build" ;
302}
303
304# If HAIKU_BUILD_VERSION is set, but HAIKU_BUILD_DESCRIPTION isn't, mark it as
305# an unknown build.
306HAIKU_BUILD_DESCRIPTION ?= "Unknown Build" ;
307
308# init library name map
309{
310	local i ;
311	for i in be game GL mail media midi midi2 network netapi opengl screensaver root z
312			textencoding tracker translation {
313		HAIKU_LIBRARY_NAME_MAP_$(i) = lib$(i).so ;
314	}
315	HAIKU_LIBRARY_NAME_MAP_libstdc++ = $(HAIKU_LIBSTDC++) ;
316	HAIKU_LIBRARY_NAME_MAP_input_server = <nogrist>input_server ;
317}
318
319
320#pragma mark -
321
322# host platform settings
323
324# save jam's variables for the build platform
325HOST_AR				?= $(AR) ;
326HOST_CC				?= $(CC) ;
327HOST_C++			?= $(C++) ;
328HOST_LINK			?= $(LINK) ;
329HOST_LD				?= ld ;			# TODO: Fix this!
330HOST_OBJCOPY		?= objcopy ;	#
331HOST_RANLIB			?= $(RANLIB) ;
332HOST_CPPFLAGS		?= $(CPPFLAGS) ;
333HOST_CCFLAGS		?= $(CCFLAGS) ;
334HOST_C++FLAGS		?= $(C++FLAGS) ;
335HOST_LDFLAGS		?= $(LDFLAGS) ;
336HOST_LINKFLAGS		?= $(LINKFLAGS) ;
337HOST_DEFINES		?= $(DEFINES) ;
338HOST_HDRS			?= $(HDRS) ;
339
340# split up HOST_AR into the command name and flags
341HOST_AR				= [ Match "([^ ]*) *(.*)" : $(HOST_AR[1]) ]
342					  $(HOST_AR[2-]) ;
343HOST_ARFLAGS		= $(HOST_AR[2-]) ;
344HOST_AR				= $(HOST_AR[1]) ;
345HOST_UNARFLAGS		?= x ;
346
347# check the host platform compatibility
348SetPlatformCompatibilityFlagVariables HOST_PLATFORM : HOST : host
349	: linux freebsd darwin ;
350
351if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd
352	|| $(HOST_PLATFORM) = darwin {
353	# don't use lex: otherwise rc will not work correctly
354	if $(LEX) = lex {
355		LEX = flex ;
356	}
357}
358
359HOST_CPU	?= $(OSPLAT:L) ;
360
361HOST_ARCH				?= $(HOST_CPU) ;
362HOST_ARCH_MACRO_DEFINE	= ARCH_$(HOST_CPU) ;
363
364# directories
365HOST_OBJECT_BASE_DIR = [ FDirName $(HAIKU_OBJECT_DIR) $(HOST_PLATFORM) ] ;
366HOST_COMMON_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) common ] ;
367HOST_ARCH_OBJECT_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) $(HOST_ARCH) ] ;
368HOST_COMMON_DEBUG_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) common ] ;
369HOST_DEBUG_0_OBJECT_DIR = [ FDirName $(HOST_ARCH_OBJECT_DIR) release ] ;
370
371local level ;
372for level in $(HAIKU_DEBUG_LEVELS[2-]) {
373	HOST_DEBUG_$(level)_OBJECT_DIR
374		= [ FDirName $(HOST_ARCH_OBJECT_DIR) debug_$(level) ] ;
375}
376
377# analyze GCC version
378HOST_GCC_VERSION = [ FAnalyzeGCCVersion HOST_GCC_RAW_VERSION ] ;
379
380# set variables for gcc header options
381SetIncludePropertiesVariables HOST ;
382
383# assembler flags
384HOST_ASFLAGS = ;
385
386# C/C++ flags
387HOST_CCFLAGS += -Wno-multichar ;
388HOST_C++FLAGS += -Wno-multichar ;
389
390HOST_KERNEL_CCFLAGS += -finline -fno-builtin
391	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
392HOST_KERNEL_C++FLAGS += -finline -fno-builtin -fno-exceptions
393	-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
394
395HOST_KERNEL_PIC_CCFLAGS = -fno-pic ;
396HOST_KERNEL_PIC_LINKFLAGS = ;
397if $(HOST_ARCH) = ppc {
398	# Build a position independent PPC kernel. We need to be able to relocate
399	# the kernel, since the virtual address space layout at boot time is not
400	# fixed.
401	HOST_KERNEL_PIC_CCFLAGS = -fPIE ;
402	HOST_KERNEL_PIC_LINKFLAGS = -shared -fPIE ;
403}
404
405# warning flags
406HOST_WARNING_CCFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wcast-align
407	-Wsign-compare ;
408HOST_WARNING_C++FLAGS = -Wall -Wno-ctor-dtor-privacy
409	-Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ;
410
411HOST_KERNEL_WARNING_CCFLAGS = -Wall -Wmissing-prototypes ;
412HOST_KERNEL_WARNING_C++FLAGS = -Wall ;
413
414# debug flags
415switch $(HOST_PLATFORM) {
416	case haiku	: HOST_DEBUG_FLAGS ?= -ggdb ;
417	case linux	: HOST_DEBUG_FLAGS ?= -ggdb ;
418	case freebsd    : HOST_DEBUG_FLAGS ?= -ggdb ;
419	case darwin : HOST_DEBUG_FLAGS ?= -ggdb ;
420	case *		: HOST_DEBUG_FLAGS ?= -g ;
421}
422
423# debug 0: suppress asserts
424HOST_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
425HOST_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
426
427HOST_KERNEL_DEBUG_0_CCFLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
428HOST_KERNEL_DEBUG_0_C++FLAGS = [ FDefines NDEBUG=$(NDEBUG) ] ;
429
430local level ;
431for level in $(HAIKU_DEBUG_LEVELS[2-]) {
432	local flags = $(HOST_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ;
433	HOST_DEBUG_$(level)_CCFLAGS			= $(flags) ;
434	HOST_DEBUG_$(level)_C++FLAGS		= $(flags) ;
435	HOST_KERNEL_DEBUG_$(level)_CCFLAGS	= $(flags) ;
436	HOST_KERNEL_DEBUG_$(level)_C++FLAGS	= $(flags) ;
437}
438
439# private kernel headers do be used when compiling kernel code
440HOST_PRIVATE_KERNEL_HEADERS = ;
441
442# under BeOS use copyattr instead of cp
443if $(HOST_PLATFORM_BEOS_COMPATIBLE)
444{
445	CP = copyattr --data ;
446}
447
448HOST_DEFINES += $(HOST_ARCH_MACRO_DEFINE) ;
449HOST_DEFINES += _NO_INLINE_ASM ;
450
451if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
452	# TODO: That's obviously not correct, but in the way the COMPILE_FOR_R5
453	# macro is used, it actually seems to mean r5/bone/dano.
454	# TODO: Deprecated. Remove!
455	HOST_DEFINES += COMPILE_FOR_R5 ;
456}
457
458# for builds of tools in the current environment
459HOST_BUILD_COMPATIBILITY_LIB_DIR = [ FDirName $(HOST_OBJECT_BASE_DIR) lib ] ;
460
461if $(HOST_PLATFORM_BEOS_COMPATIBLE) {
462	HOST_LIBSTDC++ = stdc++.r4 ;
463	HOST_LIBROOT = root ;
464	HOST_LIBBE = be ;
465	HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR = ;
466	HOST_LIBRARY_NAME_MAP_input_server = /system/servers/input_server ;
467} else {
468	HOST_LIBSTDC++ = stdc++ ;
469	HOST_LIBROOT = libroot_build.so ;
470	HOST_LIBBE = libbe_build.so ;
471	HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR
472		= "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(HOST_BUILD_COMPATIBILITY_LIB_DIR)" ;
473
474	# the C++ support library
475	if $(HOST_GCC_VERSION[1]) < 3 {
476		HOST_LIBSUPC++ = ;
477	} else {
478		HOST_LIBSUPC++ = supc++ ;
479	}
480
481	if $(HOST_PLATFORM) = darwin {
482		HOST_LIBSUPC++ = gcc_s.1 ;
483	}
484
485	# Unlike glibc FreeBSD's libc doesn't have built-in regex support.
486	if $(HOST_PLATFORM) = freebsd {
487		HOST_LIBROOT += /usr/lib/libgnuregex.so ;
488	} else if $(HOST_PLATFORM) = darwin {
489		HOST_LIBROOT += /opt/local/lib/libgnuregex.dylib ;
490	}
491
492
493	# The BeOS compilers define __INTEL__ respectively __POWERPC__. On the
494	# build platform we need to make sure, this is also defined.
495	if $(HOST_CPU) = x86 {
496		HOST_DEFINES += __INTEL__ ;
497	} else if $(HOST_CPU) = ppc {
498		HOST_DEFINES += __POWERPC__ ;
499	}
500
501	# Supposing this is a glibc platform, let's try to get features like large
502	# file support, ISO C 99 definitions, etc. On some platforms we need to
503	# request 64 bit off_t support explicitely.
504	HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 ;
505
506	# On Linux with xattr support we can use it for our attribute emulation,
507	# which is somewhat more robust.
508	if $(HAIKU_HOST_USE_XATTR) = 1 {
509		HOST_DEFINES += HAIKU_HOST_USE_XATTR ;
510	}
511}
512
513# define the executable MIME type
514HOST_EXECUTABLE_MIME_TYPE = "application/x-vnd.Be-elfexecutable" ;
515
516if $(METROWERKS) {
517	# at least parts of Haiku still can be compiled with
518	# the Metrowerks compiler on BeOS/PPC
519	HOST_EXECUTABLE_MIME_TYPE = "application/x-be-executable" ;
520}
521
522# Be API compatibility
523HOST_BE_API_HEADERS = ;
524HOST_BE_API_CCFLAGS = ;
525HOST_BE_API_C++FLAGS = ;
526
527if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) {
528	HOST_BE_API_HEADERS =
529		[ FDirName $(HAIKU_TOP) headers build ]
530		[ FDirName $(HAIKU_TOP) headers build os ]
531		[ FDirName $(HAIKU_TOP) headers build os app ]
532		[ FDirName $(HAIKU_TOP) headers build os drivers ]
533		[ FDirName $(HAIKU_TOP) headers build os kernel ]
534		[ FDirName $(HAIKU_TOP) headers build os interface ]
535		[ FDirName $(HAIKU_TOP) headers build os storage ]
536		[ FDirName $(HAIKU_TOP) headers build os support ]
537	;
538	HOST_BE_API_CCFLAGS = -include BeOSBuildCompatibility.h ;
539	HOST_BE_API_C++FLAGS = $(HOST_BE_API_CCFLAGS) ;
540}
541
542# Add directory with system headers we need when building something for the host
543# platform, e.g. containing missing POSIX/GNU headers.
544HOST_HDRS += [ FDirName $(HAIKU_TOP) headers build host $(HOST_PLATFORM) ] ;
545
546
547#pragma mark -
548
549# target platform settings
550
551# check the target platform compatibility
552SetPlatformCompatibilityFlagVariables TARGET_PLATFORM : TARGET : target ;
553
554# check the compatibility between host and target platform
555if $(TARGET_PLATFORM) != haiku {
556	if ! $(HOST_PLATFORM_($(TARGET_PLATFORM))_COMPATIBLE) {
557		Exit ERROR: The host platform is not compatible with target platform
558			$(TARGET_PLATFORM). ;
559	}
560}
561
562# TODO: Fix the naming!
563if $(TARGET_PLATFORM) = haiku {
564	NETWORK_LIBS = network ;
565	SELECT_UNAME_ETC_LIB = root ;
566	NETAPI_LIB = network ;
567} else if $(TARGET_PLATFORM_BONE_COMPATIBLE) {
568	NETWORK_LIBS = socket bind ;
569	NETAPI_LIB = bnetapi ;
570	SELECT_UNAME_ETC_LIB = root ;
571} else {
572	NETWORK_LIBS = net ;
573	NETAPI_LIB = netapi ;
574	SELECT_UNAME_ETC_LIB = net ;
575}
576
577# TODO: For compatibility only. Remove when no longer used.
578R5_COMPATIBLE		= $(TARGET_PLATFORM_BEOS_COMPATIBLE) ;
579BONE_COMPATIBLE		= $(TARGET_PLATFORM_BONE_COMPATIBLE) ;
580DANO_COMPATIBLE		= $(TARGET_PLATFORM_DANO_COMPATIBLE) ;
581HAIKU_COMPATIBLE	= $(TARGET_PLATFORM_HAIKU_COMPATIBLE) ;
582
583# Set TARGET_* variables either from HAIKU_* or HOST_* depending on the
584# specified TARGET_PLATFORM.
585
586local buildVars =
587	ARCH CPU GCC_VERSION
588
589	AR CC C++ LD OBJCOPY RANLIB
590
591	INCLUDES_SEPARATOR LOCAL_INCLUDES_OPTION SYSTEM_INCLUDES_OPTION
592
593	HDRS CPPFLAGS CCFLAGS C++FLAGS LDFLAGS LINK LINKFLAGS DEFINES
594	ARFLAGS UNARFLAGS
595
596	KERNEL_CCFLAGS KERNEL_C++FLAGS
597	KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS
598	WARNING_CCFLAGS WARNING_C++FLAGS
599
600	KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
601
602	DEBUG_FLAGS
603
604	DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
605
606	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_CCFLAGS
607	KERNEL_DEBUG_$(HAIKU_DEBUG_LEVELS)_C++FLAGS
608
609	PRIVATE_KERNEL_HEADERS
610
611	LIBSTDC++ LIBSUPC++
612
613	ARCH_MACRO_DEFINE EXECUTABLE_MIME_TYPE
614
615	OBJECT_BASE_DIR COMMON_ARCH_OBJECT_DIR COMMON_DEBUG_OBJECT_DIR
616	DEBUG_$(HAIKU_DEBUG_LEVELS)_OBJECT_DIR
617;
618
619if $(TARGET_PLATFORM) = haiku {
620	local var ;
621	for var in $(buildVars) {
622		TARGET_$(var) = $(HAIKU_$(var)) ;
623	}
624
625	TARGET_GCC_LIB_DIR			= $(HAIKU_GCC_LIB_DIR) ;
626	TARGET_GCC_HEADERS_DIR		= $(HAIKU_GCC_HEADERS_DIR) ;
627	TARGET_GCC_LIBGCC			= $(HAIKU_GCC_LIBGCC) ;
628	TARGET_GCC_LIBGCC_OBJECTS	= $(HAIKU_GCC_LIBGCC_OBJECTS) ;
629
630	TARGET_BOOT_PLATFORM		?= $(HAIKU_BOOT_PLATFORM) ;
631
632	TARGET_LIBRARY_NAME_MAP		= HAIKU_LIBRARY_NAME_MAP ;
633
634} else {
635	local var ;
636	for var in $(buildVars) {
637		TARGET_$(var) = $(HOST_$(var)) ;
638	}
639
640	TARGET_GCC_LIB_DIR			= ;
641	TARGET_GCC_HEADERS_DIR		= ;
642	TARGET_GCC_LIBGCC			= ;
643	TARGET_GCC_LIBGCC_OBJECTS	= ;
644
645	TARGET_BOOT_PLATFORM		= ;
646
647	TARGET_LIBRARY_NAME_MAP		= HOST_LIBRARY_NAME_MAP ;
648}
649
650# define macro, for identifying the platform
651switch $(TARGET_PLATFORM) {
652	case r5			: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_BEOS ;
653	case bone		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_BONE ;
654	case dano		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_DANO ;
655	case haiku		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_HAIKU ;
656	case linux		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LINUX ;
657	case freebsd	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_FREEBSD ;
658	case darwin		: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_DARWIN ;
659	case libbe_test	: TARGET_DEFINES	+= HAIKU_TARGET_PLATFORM_LIBBE_TEST ;
660}
661
662# define macro, for identifying the host platform
663switch $(HOST_PLATFORM) {
664	case r5			: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_BEOS ;
665	case bone		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_BONE ;
666	case dano		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DANO ;
667	case haiku		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_HAIKU ;
668	case linux		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_LINUX ;
669	case freebsd	: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_FREEBSD ;
670	case darwin		: HOST_DEFINES	+= HAIKU_HOST_PLATFORM_DARWIN ;
671}
672
673
674#pragma mark -
675
676# In case we build for a BeOS compatible platform, but not for Haiku, we
677# include the HaikuBuildCompatibility.h header and link against
678# libhaikucompat.a.
679
680if $(TARGET_PLATFORM) != haiku &&  $(TARGET_PLATFORM_BEOS_COMPATIBLE) {
681	# headers and flags
682	local compatibilityHeader = -include [ FDirName $(HAIKU_TOP) headers build
683		HaikuBuildCompatibility.h ] ;
684	TARGET_CCFLAGS += $(compatibilityHeader) ;
685	TARGET_C++FLAGS += $(compatibilityHeader) ;
686
687	# compatibility library
688	TARGET_HAIKU_COMPATIBILITY_LIBS = libhaikucompat.a ;
689}
690
691# special target libbe_test
692
693if $(TARGET_PLATFORM) = libbe_test {
694	# headers and flags
695	TARGET_HDRS +=
696		[ PublicHeaders app drivers game interface kernel storage support ]
697		[ PrivateHeaders $(DOT) ] ;
698	TARGET_DEFINES += __HAIKU__ ;
699
700	# directories
701	TARGET_OBJECT_BASE_DIR
702		= [ FDirName $(HAIKU_OBJECT_DIR) $(TARGET_PLATFORM) ] ;
703	TARGET_COMMON_ARCH_OBJECT_DIR
704		= [ FDirName $(TARGET_OBJECT_BASE_DIR) common ] ;
705	TARGET_ARCH_OBJECT_DIR
706		= [ FDirName $(TARGET_OBJECT_BASE_DIR) $(TARGET_ARCH) ] ;
707	TARGET_COMMON_DEBUG_OBJECT_DIR
708		= [ FDirName $(TARGET_ARCH_OBJECT_DIR) common ] ;
709	TARGET_DEBUG_0_OBJECT_DIR
710		= [ FDirName $(TARGET_ARCH_OBJECT_DIR) release ] ;
711
712	local level ;
713	for level in $(HAIKU_DEBUG_LEVELS[2-]) {
714		TARGET_DEBUG_$(level)_OBJECT_DIR
715			= [ FDirName $(TARGET_ARCH_OBJECT_DIR) debug_$(level) ] ;
716	}
717
718	# library name map
719	TARGET_LIBRARY_NAME_MAP = LIBBE_LIBRARY_NAME_MAP ;
720	LIBBE_LIBRARY_NAME_MAP_be = libbe_haiku.so ;
721}
722
723
724#pragma mark -
725
726# common stuff
727
728# start with a clean slate
729CCFLAGS = ;
730C++FLAGS = ;
731DEFINES = ;
732
733# Set CC, C++, LINK to invalid values, so that we realize early, that we use
734# the wrong compiler.
735CC = bad-cc ;
736C++ = bad-c++ ;
737LINK = bad-link ;
738
739# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
740# issues, they deprecated that nice function. This will enable it again:
741C++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
742# Same for buggy find_directory threadsafety fixes
743C++FLAGS += -D_ZETA_TS_FIND_DIR_=1 ;
744	# TODO: Doesn't really belong here.
745
746
747# Defaults for warnings, optimization, and debugging.
748#
749WARNINGS ?= 1 ;
750OPTIM ?= -O2 ;
751DEBUG ?= 0 ;
752
753
754# Set the defaults for PLATFORM and SUPPORTED_PLATFORMS. PLATFORM is only
755# overridden for targets to be built for the host platform. SUPPORTED_PLATFORMS
756# can be overridden by the author of a component.
757PLATFORM = $(TARGET_PLATFORM) ;
758SUPPORTED_PLATFORMS = haiku ;
759
760
761# Instructs the Library rule to not make its object files temporary.
762# This is needed as some objects are used in a static library and for an
763# executable.
764KEEPOBJS = true ;
765
766
767# output directories
768# TODO: Review this.
769HAIKU_DOCUMENTATION_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) documentation ] ;
770HAIKU_DOCUMENTATION_OBJECT_DIR ?= [ FDirName $(HAIKU_COMMON_PLATFORM_DIR)
771	documentation ] ;
772
773# TODO: Rethink test stuff.
774HAIKU_TEST_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tests $(TARGET_PLATFORM) $(HAIKU_ARCH) ] ;
775HAIKU_APP_TEST_DIR		?= [ FDirName $(HAIKU_TEST_DIR) apps ] ;
776HAIKU_APP_TEST_LIB_DIR 	?= [ FDirName $(HAIKU_APP_TEST_DIR) lib ] ;
777HAIKU_TMP_DIR			?= [ FDirName $(HAIKU_OUTPUT_DIR) tmp ] ;
778
779HAIKU_PACKAGE_DIR ?= [ FDirName $(HAIKU_OUTPUT_DIR) packages ] ;
780HAIKU_PACKAGE_OBJECT_DIR ?= [ FDirName $(HAIKU_OBJECT_DIR) packages ] ;
781
782TARGET_TEST_DIR				?= [ FDirName $(HAIKU_TEST_DIR)
783									$(TARGET_PLATFORM) ] ;
784TARGET_UNIT_TEST_DIR		?= [ FDirName $(TARGET_TEST_DIR) unittests ] ;
785TARGET_UNIT_TEST_LIB_DIR	?= [ FDirName $(TARGET_UNIT_TEST_DIR) lib ] ;
786
787# automatically setup the objects directory per subdirectory
788SUBDIRRULES += SetupObjectsDir ;
789
790# Add the standard (userland) warning flags variables to the ones restored in
791# every subdirectory. Thus we can easily meddle with them in subdirectories
792# with imported sources.
793AUTO_SET_UP_CONFIG_VARIABLES +=
794	HOST_WARNING_CCFLAGS HOST_WARNING_C++FLAGS
795	TARGET_WARNING_CCFLAGS TARGET_WARNING_C++FLAGS
796
797	# also add PLATFORM and SUPPORTED_PLATFORMS
798	PLATFORM SUPPORTED_PLATFORMS
799;
800