xref: /haiku/configure (revision 4720c31bb08f5c6d1c8ddb616463c6fba9b350a1)
1#!/bin/sh
2#
3# configure [ <options> ]
4
5# usage
6#
7# Prints usage.
8#
9usage()
10{
11	cat << EOF
12
13Usage: $0 <options>
14options:
15  --bochs-debug               Enables bochs serial debug emulation (activated
16                              via kernel settings file).
17  --build-cross-tools <build tools dir>
18                              Assume cross compilation. <build tools dir>
19                              defines the location of the build tools sources.
20                              They will be compiled and placed in the output
21                              directory under "cross-tools". The HAIKU_* tools
22                              variables will be set accordingly.
23  --build-cross-tools-gcc4 <arch> <build tools dir>
24                              Like "--build-cross-tools" just that gcc 4 will
25                              be used for cross-compilation. Note, that the
26                              resulting Haiku installation built with gcc 4
27                              will not be binary compatible with BeOS R5.
28                              <arch> specifies the target architecture, either
29                              "x86" or "ppc".
30  --alternative-gcc-output-dir <dir>
31                              Build a Haiku installation that supports running
32                              executables built with a gcc version incompatible
33                              with the primary gcc (e.g. gcc 2 executables under
34                              a gcc 4 Haiku or vice versa). <dir> specifies the
35                              output directory of the other gcc. The directory
36                              must already be fully configured.
37                              Note, that a sub-jam will be executed when
38                              building Haiku. When using a jam that is not
39                              simply invoked by "jam", the JAM build variable
40                              needs to be set accordingly.
41                              To disable building the alternative libraries
42                              the variable HAIKU_ADD_ALTERNATIVE_GCC_LIBS can be
43                              unset in the UserBuildConfig file.
44  --cross-tools-prefix <prefix>
45                              Assume cross compilation. <prefix> should be a
46                              path to the directory where the cross
47                              compilation tools are located, plus the platform
48                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
49                              This overrides the HAIKU_* tool variables.
50  --distro-compatibility <level>
51                              The distribution's level of compatibility with
52                              the official Haiku distribution. The generated
53                              files will contain the respective trademarks
54                              accordingly.
55                              official -- the official Haiku distribution.
56                              compatible -- a Haiku Compatible (tm) distro.
57                              default -- any other distro (default value).
58  --help                      Prints out this help.
59  --include-gpl-addons        Include GPL licensed add-ons.
60  --include-3rdparty          Include 3rdparty/ in the build system.
61  --enable-multiuser          Enable experimental multiuser support.
62  --target=TARGET             Select build target platform. [default=${target}]
63                              valid targets=r5,bone,dano,haiku
64  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
65                              process, but uses more memory.
66  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
67  --use-xattr                 Use Linux xattr support for BeOS attribute
68                              emulation. Warning: Make sure your file system
69                              supports sufficient attribute sizes (4 KB per
70                              file for all attributes won't suffice).
71
72environment variables:
73  HAIKU_AR                    The static library archiver. Defaults to "ar".
74  HAIKU_CC                    The compiler. Defaults to "gcc".
75  HAIKU_LD                    The linker. Defaults to "ld".
76  HAIKU_OBJCOPY               The objcopy to be used. Defaults to "objcopy".
77  HAIKU_RANLIB                The static library indexer. Defaults to "ranlib".
78  HAIKU_CPPFLAGS              The preprocessor flags. Defaults to "".
79  HAIKU_CCFLAGS               The C flags. Defaults to "".
80  HAIKU_CXXFLAGS              The C++ flags. Defaults to "".
81  HAIKU_LDFLAGS               The linker flags. Defaults to "".
82  HAIKU_ARFLAGS               The flags passed to HAIKU_AR for archiving.
83                              Defaults to "ru".
84  HAIKU_UNARFLAGS             The flags passed to HAIKU_AR for unarchiving.
85                              Defaults to "x".
86
87Non-standard output directories:
88  By default all objects, build configuration, and other related files are
89  stored in /path/to/haiku_source/generated.  To store objects in a non-default
90  location, run "../../relative/path/to/haiku_source/configure <options>" from
91  within your non-default location.  "jam [ options ] targets" can then be run
92  directly inside your non-default location.  Another option is to invoke "jam
93  [ options ] targets" from within haiku_source.  This can be accomplished by
94  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
95  jam or by creating a symlink of haiku_source/generated pointing to your
96  non-default location and running jam.
97
98
99EOF
100}
101
102# assertparam
103#
104# Checks whether at least one parameter is left.
105#
106assertparam()
107{
108	if [ $2 -lt 2 ]; then
109		echo $0: \`$1\': Parameter expected.
110		exit 1
111	fi
112}
113
114# assertparams
115#
116# Checks whether at least a certain number of parameters is left.
117#
118assertparams()
119{
120	if [ $3 -le $2 ]; then
121		echo $0: \`$1\': Not enough parameters.
122		exit 1
123	fi
124}
125
126# standard_gcc_settings
127#
128# Sets the variables for a GCC platform.
129#
130standard_gcc_settings()
131{
132	# PLATFORM_LINKLIBS
133	gcclib=`$HAIKU_CC -print-libgcc-file-name`
134	gccdir=`dirname ${gcclib}`
135
136	haikuGCCVersion=`$HAIKU_CC -dumpversion`
137	haikuGCCMachine=`$HAIKU_CC -dumpmachine`
138
139	HAIKU_GCC_LIB_DIR=${gccdir}
140	HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a
141	HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o"
142	HAIKU_GCC_HEADERS_DIR="${gccdir}/include
143		${gccdir}/include-fixed"
144	HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o`
145		# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and
146		# neither needed nor wanted.
147
148	case $haikuGCCVersion in
149		4.*)
150			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
151			# compiler
152			haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a`
153			haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so`
154			haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a`
155			haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so`
156
157			local headers
158			if [ -d $gccdir/../../../../$haikuGCCMachine/include/c++/$haikuGCCVersion ]; then
159				headers=$gccdir/../../../../$haikuGCCMachine/include/c++/$haikuGCCVersion
160			else
161				headers=$gccdir/../../../../include/c++/$haikuGCCVersion
162			fi
163
164			haikuCxxHeadersDir=$headers
165			for d in $haikuGCCMachine backward ext; do
166				# Note: We need the line break, otherwise the line might become
167				# too long for jam (512 bytes max).
168				haikuCxxHeadersDir="$haikuCxxHeadersDir
169					$headers/$d"
170			done
171
172
173			# when not building the crosscompiler, to use cpp headers from
174			# tree first, but fallback to local C++ system headers (like <new>)
175			# if [ "$buildCrossTools" = "" ]; then
176			#	haikuCxxHeadersDir="headers/cpp $haikuCxxHeadersDir"
177			# fi
178
179			if [ $haikuStaticLibStdCxx = libstdc++.a ]; then
180				haikuStaticLibStdCxx=
181			fi
182			if [ $haikuSharedLibStdCxx = libstdc++.so ]; then
183				haikuSharedLibStdCxx=
184			fi
185			if [ $haikuStaticLibSupCxx = libsupc++.a ]; then
186				haikuStaticLibSupCxx=
187			fi
188			if [ $haikuSharedLibSupCxx = libsupc++.so ]; then
189				haikuSharedLibSupCxx=
190			fi
191		;;
192		2.9*)
193			# check for correct (most up-to-date) legacy compiler and complain
194			# if an older one is installed
195			if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then
196				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
197				echo "Please download it from www.haiku-os.org...";
198				exit 1;
199			fi
200		;;
201	esac
202}
203
204# set_default_value
205#
206# Set the value for a variable, if no value is set yet.
207#
208set_default_value()
209{
210	eval "$1=\${$1-$2}"
211}
212
213# get_build_tool_path
214#
215# Gets a usable absolute path of a build tool.
216#
217get_build_tool_path()
218{
219	local var="HAIKU_$1"
220	local tool=$2
221	local path="${crossToolsPrefix}$tool"
222
223	if [ -f "$path" ]; then
224		# get absolute path
225		local oldPwd="`pwd`"
226		cd "`dirname "$path"`"
227		path="`pwd`/`basename "$path"`"
228		cd $oldPwd
229	else
230		which "$path" &> /dev/null || {
231			echo "Build tool \"$path\" not found." >&2
232			exit 1
233		}
234	fi
235
236	eval "$var=$path"
237}
238
239# get cwd and the source directory
240currentDir=`pwd`
241cd `dirname "$0"`
242sourceDir=`pwd`
243cd "$currentDir"
244
245# default parameter values
246#
247platform=`uname`
248platformMachine=`uname  -m`
249haikuGCCVersion=
250haikuGCCMachine=i586-pc-haiku
251haikuStaticLibStdCxx=
252haikuSharedLibStdCxx=
253haikuStaticLibSupCxx=
254haikuSharedLibSupCxx=
255haikuCxxHeadersDir=
256hostGCCVersion=`gcc -dumpversion`
257bochsDebug=0
258includeGPLAddOns=0
259include3rdParty=0
260enableMultiuser=0
261distroCompatibility=default
262target=haiku
263useGCCPipe=0
264use32bit=0
265useXattr=0
266crossToolsPrefix=
267buildCrossTools=
268buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
269buildCrossToolsMachine=
270alternativeGCCOutputDir=
271addAlternativeGCCLibs=
272
273haikuRequiredLegacyGCCVersion="2.95.3-haiku-081024"
274export haikuRequiredLegacyGCCVersion
275	# version of legacy gcc required to build haiku
276
277set_default_value HAIKU_AR			ar
278set_default_value HAIKU_CC			gcc
279set_default_value HAIKU_LD			ld
280set_default_value HAIKU_OBJCOPY		objcopy
281set_default_value HAIKU_RANLIB		ranlib
282set_default_value HAIKU_CPPFLAGS	""
283set_default_value HAIKU_CCFLAGS		""
284set_default_value HAIKU_CXXFLAGS	""
285set_default_value HAIKU_LDFLAGS		""
286set_default_value HAIKU_ARFLAGS		ru
287set_default_value HAIKU_UNARFLAGS	x
288
289# parse parameters
290#
291while [ $# -gt 0 ] ; do
292	case "$1" in
293		--bochs-debug)	bochsDebug=1; shift 1;;
294		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
295		--build-cross-tools-gcc4)
296			assertparams "$1" 2 $#
297			buildCrossTools=$3
298			buildCrossToolsScript="${buildCrossToolsScript}_gcc4"
299			case "$2" in
300				x86)	haikuGCCMachine=i586-pc-haiku;;
301				ppc)	haikuGCCMachine=powerpc-apple-haiku;;
302				m68k)	haikuGCCMachine=m68k-unknown-haiku;;
303				arm)	haikuGCCMachine=arm-unknown-haiku;;
304				*)		echo "Unsupported target architecture: $2"
305						exit 1;;
306			esac
307			buildCrossToolsMachine=$haikuGCCMachine
308			shift 3
309			;;
310		--alternative-gcc-output-dir)
311			assertparam "$1" $#
312			cd $2 || exit 1
313			alternativeGCCOutputDir=`pwd`
314			addAlternativeGCCLibs=1
315			cd $currentDir
316			shift 2
317			;;
318		--cross-tools-prefix)
319			assertparam "$1" $#
320			crossToolsPrefix=$2
321			shift 2
322			;;
323		--help | -h)	usage; exit 0;;
324		--include-gpl-addons)	includeGPLAddOns=1; shift 1;;
325		--include-3rdparty)	include3rdParty=1; shift 1;;
326		--enable-multiuser)	enableMultiuser=1; shift 1;;
327		--distro-compatibility)
328			assertparam "$1" $#
329			distroCompatibility=$2
330			case "$distroCompatibility" in
331				official)	;;
332				compatible)	;;
333				default)	;;
334				*)			echo "Invalid distro compatibility" \
335								"level: $distroCompatibility"
336							exit 1;;
337			esac
338			shift 2
339			;;
340		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
341		--use-gcc-pipe)	useGCCPipe=1; shift 1;;
342		--use-32bit)	use32bit=1; shift 1;;
343		--use-xattr)	useXattr=1; shift 1;;
344		*)				echo Invalid argument: \`$1\'; exit 1;;
345	esac
346done
347
348# check for a 64bit platform
349case "${platformMachine}" in
350	x86_64)	use32bit=1 ;;
351	*)	echo Assuming 32-bit machine: "$platformMachine"
352		use32bit=0 ;;
353esac
354
355# detect the build platform
356case "${platform}" in
357	BeOS)	revision=`uname -r`
358			case "$revision" in
359				6.*)	buildPlatform=dano ;;
360				5.1)	buildPlatform=dano ;;
361				5.0.4)	buildPlatform=bone ;;
362				5.0*)	buildPlatform=r5 ;;
363				*)		echo Unknown BeOS version: $revision
364						exit 1 ;;
365			esac
366			;;
367	Darwin)	buildPlatform=darwin ;;
368	FreeBSD)	buildPlatform=freebsd
369				if [ "$use32bit" = 1 ] ; then
370					echo Unsupported platform: FreeBSD ${platformMachine}
371					exit 1
372				fi	;;
373	Haiku)	buildPlatform=haiku_host ;;
374	Linux)	buildPlatform=linux ;;
375	OpenBSD) buildPlatform=openbsd ;;
376	SunOS)	buildPlatform=sunos ;;
377	CYGWIN_NT-*) buildPlatform=cygwin ;;
378	*)		echo Unsupported platform: ${platform}
379			exit 1 ;;
380esac
381
382# create output directory
383if [ "$currentDir" = "$sourceDir" ]; then
384	outputDir=$currentDir/generated
385else
386	outputDir=$currentDir
387fi
388buildOutputDir="$outputDir/build"
389buildAttributesDir="$outputDir/attributes"
390mkdir -p "$buildOutputDir" || exit 1
391
392# build cross tools from sources
393if [ -n "$buildCrossTools" ]; then
394	"$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \
395		"$buildCrossTools" "$outputDir" || exit 1
396	crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-"
397fi
398
399# cross tools
400if [ -n "$crossToolsPrefix" ]; then
401	get_build_tool_path AR ar
402	get_build_tool_path CC gcc
403	get_build_tool_path LD ld
404	get_build_tool_path OBJCOPY objcopy
405	get_build_tool_path RANLIB ranlib
406fi
407
408# prepare gcc settings
409standard_gcc_settings
410
411# check whether the Haiku compiler really targets Haiku or BeOS
412case "$haikuGCCMachine" in
413	*-*-haiku)	;;
414	*-*-beos)	;;
415	*) echo The compiler specified as Haiku target compiler is not a valid \
416			Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
417	   echo compiler: $HAIKU_CC
418	   echo compiler is configured for target: $haikuGCCMachine
419	   exit 1 ;;
420esac
421
422# Generate BuildConfig
423cat << EOF > "$buildOutputDir/BuildConfig"
424# BuildConfig
425# Note: This file has been automatically generated by configure.
426
427TARGET_PLATFORM 			?= "${target}" ;
428HOST_PLATFORM				?= "${buildPlatform}" ;
429
430BOCHS_DEBUG_HACK					?= "${bochsDebug}" ;
431INCLUDE_GPL_ADDONS					?= "${includeGPLAddOns}" ;
432HAIKU_INCLUDE_3RDPARTY				?= "${include3rdParty}" ;
433HAIKU_ENABLE_MULTIUSER				?= "${enableMultiuser}" ;
434HAIKU_DISTRO_COMPATIBILITY			?= "${distroCompatibility}" ;
435HAIKU_USE_GCC_PIPE					?= "${useGCCPipe}" ;
436HAIKU_HOST_USE_32BIT				?= "${use32bit}" ;
437HAIKU_HOST_USE_XATTR				?= "${useXattr}" ;
438HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR	?= ${alternativeGCCOutputDir} ;
439HAIKU_ADD_ALTERNATIVE_GCC_LIBS		?= ${addAlternativeGCCLibs} ;
440
441HAIKU_GCC_RAW_VERSION		?= ${haikuGCCVersion} ;
442HAIKU_GCC_MACHINE			?= ${haikuGCCMachine} ;
443HAIKU_GCC_LIB_DIR			?= ${HAIKU_GCC_LIB_DIR} ;
444HAIKU_GCC_HEADERS_DIR		?= ${HAIKU_GCC_HEADERS_DIR} ;
445HAIKU_GCC_LIBGCC			?= ${HAIKU_GCC_LIBGCC} ;
446
447HAIKU_STATIC_LIBSTDC++		?= ${haikuStaticLibStdCxx} ;
448HAIKU_SHARED_LIBSTDC++		?= ${haikuSharedLibStdCxx} ;
449HAIKU_STATIC_LIBSUPC++		?= ${haikuStaticLibSupCxx} ;
450HAIKU_SHARED_LIBSUPC++		?= ${haikuSharedLibSupCxx} ;
451HAIKU_C++_HEADERS_DIR		?= ${haikuCxxHeadersDir} ;
452
453HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
454
455HAIKU_AR					?= ${HAIKU_AR} ;
456HAIKU_CC					?= ${HAIKU_CC} ;
457HAIKU_LD					?= ${HAIKU_LD} ;
458HAIKU_OBJCOPY				?= ${HAIKU_OBJCOPY} ;
459HAIKU_RANLIB				?= ${HAIKU_RANLIB} ;
460HAIKU_CPPFLAGS				?= ${HAIKU_CPPFLAGS} ;
461HAIKU_CCFLAGS				?= ${HAIKU_CCFLAGS} ;
462HAIKU_CXXFLAGS				?= ${HAIKU_CXXFLAGS} ;
463HAIKU_LDFLAGS				?= ${HAIKU_LDFLAGS} ;
464HAIKU_ARFLAGS				?= ${HAIKU_ARFLAGS} ;
465HAIKU_UNARFLAGS				?= ${HAIKU_UNARFLAGS} ;
466
467HOST_GCC_RAW_VERSION		?= ${hostGCCVersion} ;
468
469EOF
470
471# Libgcc.a objects
472
473cat << EOF > "$buildOutputDir/libgccObjects"
474# libgcc.a objects to be linked against libroot.so
475# Note: This file has been automatically generated by configure.
476
477HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
478EOF
479
480# Generate Timezones binaries bindings
481
482timezoneSources="africa antarctica asia australasia europe northamerica
483	southamerica pacificnew etcetera factory backward"
484
485cat << EOF > "$buildOutputDir/Timezones"
486# Timezones used for the build
487# Note: This file has been automatically generated by configure.
488
489HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
490
491EOF
492
493for source in ${timezoneSources}; do
494	f=$sourceDir/src/data/etc/timezones/$source
495
496TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" `
497
498cat << EOF >> "$buildOutputDir/Timezones"
499TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
500EOF
501done
502
503# Generate a boot strap Jamfile in the output directory.
504
505cat << EOF > $outputDir/Jamfile
506# automatically generated Jamfile
507
508HAIKU_TOP			= ${sourceDir} ;
509HAIKU_OUTPUT_DIR	= ${outputDir} ;
510
511include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
512
513EOF
514