xref: /haiku/configure (revision c7509fce9db782326f159843f1b028b5f5dcb1d2)
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  --cross-tools-prefix <prefix>
31                              Assume cross compilation. <prefix> should be a
32                              path to the directory where the cross
33                              compilation tools are located, plus the platform
34                              prefix, e.g. "/path/to/tools/i586-pc-beos-".
35                              This overrides the HAIKU_* tool variables.
36  --help                      Prints out this help.
37  --include-gpl-addons        Include GPL licensed add-ons.
38  --target=TARGET             Select build target platform. [default=${target}]
39                              valid targets=r5,bone,dano,haiku
40  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
41                              process, but uses more memory.
42  --use-xattr                 Use Linux xattr support for BeOS attribute
43                              emulation. Warning: Make sure your file system
44                              supports sufficient attribute sizes (4 KB per
45                              file for all attributes won't suffice).
46
47environment variables:
48  HAIKU_AR                    The static library archiver. Defaults to "ar".
49  HAIKU_CC                    The compiler. Defaults to "gcc".
50  HAIKU_LD                    The linker. Defaults to "ld".
51  HAIKU_OBJCOPY               The objcopy to be used. Defaults to "objcopy".
52  HAIKU_RANLIB                The static library indexer. Defaults to "ranlib".
53  HAIKU_CPPFLAGS              The preprocessor flags. Defaults to "".
54  HAIKU_CCFLAGS               The C flags. Defaults to "".
55  HAIKU_CXXFLAGS              The C++ flags. Defaults to "".
56  HAIKU_LDFLAGS               The linker flags. Defaults to "".
57  HAIKU_ARFLAGS               The flags passed to HAIKU_AR for archiving.
58                              Defaults to "ru".
59  HAIKU_UNARFLAGS             The flags passed to HAIKU_AR for unarchiving.
60                              Defaults to "x".
61EOF
62}
63
64# assertparam
65#
66# Checks whether at least one parameter is left.
67#
68assertparam()
69{
70	if [ $2 -lt 2 ]; then
71		echo $0: \`$1\': Parameter expected.
72		exit 1
73	fi
74}
75
76# assertparams
77#
78# Checks whether at least a certain number of parameters is left.
79#
80assertparams()
81{
82	if [ $3 -le $2 ]; then
83		echo $0: \`$1\': Not enough parameters.
84		exit 1
85	fi
86}
87
88# standard_gcc_settings
89#
90# Sets the variables for a GCC platform.
91#
92standard_gcc_settings()
93{
94	# PLATFORM_LINKLIBS
95	gcclib=`$HAIKU_CC -print-libgcc-file-name`
96	gccdir=`dirname ${gcclib}`
97
98	haikuGCCVersion=`$HAIKU_CC -dumpversion`
99	haikuGCCMachine=`$HAIKU_CC -dumpmachine`
100
101	HAIKU_GCC_LIB_DIR=${gccdir}
102	HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a
103	HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o"
104	HAIKU_GCC_HEADERS_DIR=${gccdir}/include
105	HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o`
106		# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and
107		# neither needed nor wanted.
108
109	case $haikuGCCVersion in
110		4.*)
111			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
112			# compiler
113			haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a`
114			haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so`
115			haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a`
116			haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so`
117			local headers=$gccdir/../../../../include/c++/$haikuGCCVersion
118			haikuCxxHeadersDir=$headers
119			for d in $haikuGCCMachine backward ext; do
120				# Note: We need the line break, otherwise the line might become
121				# too long for jam (512 bytes max).
122				haikuCxxHeadersDir="$haikuCxxHeadersDir
123					$headers/$d"
124			done
125
126
127			# when not building the crosscompiler, to use cpp headers from
128			# tree first, but fallback to local C++ system headers (like <new>)
129			# if [ "$buildCrossTools" = "" ]; then
130			#	haikuCxxHeadersDir="headers/cpp $haikuCxxHeadersDir"
131			# fi
132
133			if [ $haikuStaticLibStdCxx = libstdc++.a ]; then
134				haikuStaticLibStdCxx=
135			fi
136			if [ $haikuSharedLibStdCxx = libstdc++.so ]; then
137				haikuSharedLibStdCxx=
138			fi
139			if [ $haikuStaticLibSupCxx = libsupc++.a ]; then
140				haikuStaticLibSupCxx=
141			fi
142			if [ $haikuSharedLibSupCxx = libsupc++.so ]; then
143				haikuSharedLibSupCxx=
144			fi
145		;;
146		2.9*)
147			# check for correct (most up-to-date) legacy compiler and complain
148			# if an older one is installed
149			if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then
150				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
151				echo "Please download it from www.haiku-os.org...";
152				exit 1;
153			fi
154		;;
155	esac
156}
157
158# set_default_value
159#
160# Set the value for a variable, if no value is set yet.
161#
162set_default_value()
163{
164	eval "$1=\${$1-$2}"
165}
166
167# get_build_tool_path
168#
169# Gets a usable absolute path of a build tool.
170#
171get_build_tool_path()
172{
173	local var="HAIKU_$1"
174	local tool=$2
175	local path="${crossToolsPrefix}$tool"
176
177	if [ -f "$path" ]; then
178		# get absolute path
179		local oldPwd=$(pwd)
180		cd $(dirname "$path")
181		path="$(pwd)/$(basename "$path")"
182		cd $oldPwd
183	else
184		which "$path" &> /dev/null || {
185			echo "Build tool \"$path\" not found." >&2
186			exit 1
187		}
188	fi
189
190	eval "$var=$path"
191}
192
193# get cwd and the source directory
194currentDir=`pwd`
195cd `dirname "$0"`
196sourceDir=`pwd`
197cd "$currentDir"
198
199# default parameter values
200#
201platform=`uname`
202haikuGCCVersion=
203haikuGCCMachine=i586-pc-beos
204haikuStaticLibStdCxx=
205haikuSharedLibStdCxx=
206haikuStaticLibSupCxx=
207haikuSharedLibSupCxx=
208haikuCxxHeadersDir=
209hostGCCVersion=`gcc -dumpversion`
210bochs_debug=0
211include_gpl_addons=0
212target=haiku
213use_gcc_pipe=0
214use_xattr=0
215crossToolsPrefix=
216buildCrossTools=
217buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
218buildCrossToolsMachine=
219
220export haikuRequiredLegacyGCCVersion="2.95.3-beos-060710"
221	# version of legacy gcc required to build haiku
222
223set_default_value HAIKU_AR			ar
224set_default_value HAIKU_CC			gcc
225set_default_value HAIKU_LD			ld
226set_default_value HAIKU_OBJCOPY		objcopy
227set_default_value HAIKU_RANLIB		ranlib
228set_default_value HAIKU_CPPFLAGS	""
229set_default_value HAIKU_CCFLAGS		""
230set_default_value HAIKU_CXXFLAGS	""
231set_default_value HAIKU_LDFLAGS		""
232set_default_value HAIKU_ARFLAGS		ru
233set_default_value HAIKU_UNARFLAGS	x
234
235# parse parameters
236#
237while [ $# -gt 0 ] ; do
238	case "$1" in
239		--bochs-debug)	bochs_debug=1; shift 1;;
240		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
241		--build-cross-tools-gcc4) assertparams "$1" 2 $#; buildCrossTools=$3;
242						buildCrossToolsScript="${buildCrossToolsScript}_gcc4";
243						case "$2" in
244							x86)	haikuGCCMachine=i586-pc-haiku;;
245							ppc)	haikuGCCMachine=powerpc-apple-haiku;;
246							*)		echo "Unsupported target architecture: $2"
247									exit 1;;
248						esac
249						buildCrossToolsMachine=$haikuGCCMachine
250						shift 3;;
251		--cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;;
252		--help | -h)	usage; exit 0;;
253		--include-gpl-addons)	include_gpl_addons=1; shift 1;;
254		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
255		--use-gcc-pipe)	use_gcc_pipe=1; shift 1;;
256		--use-xattr)	use_xattr=1; shift 1;;
257		*)				echo Invalid argument: \`$1\'; exit 1;;
258	esac
259done
260
261# detect the build platform
262case "${platform}" in
263	BeOS)	revision=`uname -r`
264			case "$revision" in
265				6.*)	buildPlatform=dano ;;
266				5.1)	buildPlatform=dano ;;
267				5.0.4)	buildPlatform=bone ;;
268				5.0*)	buildPlatform=r5 ;;
269				*)		echo Unknown BeOS version: $revision
270						exit 1 ;;
271			esac
272			;;
273	Linux)	buildPlatform=linux ;;
274	FreeBSD) buildPlatform=freebsd ;;
275	*)		echo Unsupported platform: ${platform}
276			exit 1 ;;
277esac
278
279# create output directory
280if [ "$currentDir" = "$sourceDir" ]; then
281	outputDir=$currentDir/generated
282else
283	outputDir=$currentDir
284fi
285buildOutputDir="$outputDir/build"
286buildAttributesDir="$outputDir/attributes"
287mkdir -p "$buildOutputDir" || exit 1
288
289# build cross tools from sources
290if [ -n "$buildCrossTools" ]; then
291	"$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \
292		"$buildCrossTools" "$outputDir" || exit 1
293	crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-"
294fi
295
296# cross tools
297if [ -n "$crossToolsPrefix" ]; then
298	get_build_tool_path AR ar
299	get_build_tool_path CC gcc
300	get_build_tool_path LD ld
301	get_build_tool_path OBJCOPY objcopy
302	get_build_tool_path RANLIB ranlib
303fi
304
305# prepare gcc settings
306standard_gcc_settings
307
308# check whether the Haiku compiler really targets Haiku or BeOS
309case "$haikuGCCMachine" in
310	*-*-haiku)	;;
311	*-*-beos)	;;
312	*) echo The compiler specified as Haiku target compiler is not a valid \
313			Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
314	   echo compiler: $HAIKU_CC
315	   echo compiler is configured for target: $haikuGCCMachine
316	   exit 1 ;;
317esac
318
319# Generate BuildConfig
320cat << EOF > "$buildOutputDir/BuildConfig"
321# BuildConfig
322# Note: This file has been automatically generated by configure.
323
324TARGET_PLATFORM 	?= "${target}" ;
325HOST_PLATFORM		?= "${buildPlatform}" ;
326
327BOCHS_DEBUG_HACK		?= "${bochs_debug}" ;
328INCLUDE_GPL_ADDONS		?= "${include_gpl_addons}" ;
329HAIKU_USE_GCC_PIPE		?= "${use_gcc_pipe}" ;
330HAIKU_HOST_USE_XATTR	?= "${use_xattr}" ;
331
332HAIKU_GCC_RAW_VERSION	?= ${haikuGCCVersion} ;
333HAIKU_GCC_MACHINE		?= ${haikuGCCMachine} ;
334HAIKU_GCC_LIB_DIR		?= ${HAIKU_GCC_LIB_DIR} ;
335HAIKU_GCC_HEADERS_DIR	?= ${HAIKU_GCC_HEADERS_DIR} ;
336HAIKU_GCC_LIBGCC		?= ${HAIKU_GCC_LIBGCC} ;
337
338HAIKU_STATIC_LIBSTDC++	?= ${haikuStaticLibStdCxx} ;
339HAIKU_SHARED_LIBSTDC++	?= ${haikuSharedLibStdCxx} ;
340HAIKU_STATIC_LIBSUPC++	?= ${haikuStaticLibSupCxx} ;
341HAIKU_SHARED_LIBSUPC++	?= ${haikuSharedLibSupCxx} ;
342HAIKU_C++_HEADERS_DIR	?= ${haikuCxxHeadersDir} ;
343
344HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
345
346HAIKU_AR			?= ${HAIKU_AR} ;
347HAIKU_CC			?= ${HAIKU_CC} ;
348HAIKU_LD			?= ${HAIKU_LD} ;
349HAIKU_OBJCOPY		?= ${HAIKU_OBJCOPY} ;
350HAIKU_RANLIB		?= ${HAIKU_RANLIB} ;
351HAIKU_CPPFLAGS		?= ${HAIKU_CPPFLAGS} ;
352HAIKU_CCFLAGS		?= ${HAIKU_CCFLAGS} ;
353HAIKU_CXXFLAGS		?= ${HAIKU_CXXFLAGS} ;
354HAIKU_LDFLAGS		?= ${HAIKU_LDFLAGS} ;
355HAIKU_ARFLAGS		?= ${HAIKU_ARFLAGS} ;
356HAIKU_UNARFLAGS		?= ${HAIKU_UNARFLAGS} ;
357
358HOST_GCC_RAW_VERSION	?= ${hostGCCVersion} ;
359
360EOF
361
362# Libgcc.a objects
363
364cat << EOF > "$buildOutputDir/libgccObjects"
365# libgcc.a objects to be linked against libroot.so
366# Note: This file has been automatically generated by configure.
367
368HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
369EOF
370
371# Generate Timezones binaries bindings
372
373timezoneSources="africa antarctica asia australasia europe northamerica
374	southamerica pacificnew etcetera factory backward"
375
376cat << EOF > "$buildOutputDir/Timezones"
377# Timezones used for the build
378# Note: This file has been automatically generated by configure.
379
380HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
381
382EOF
383
384for source in ${timezoneSources}; do
385	f=$sourceDir/src/data/etc/timezones/$source
386
387TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" `
388
389cat << EOF >> "$buildOutputDir/Timezones"
390TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
391EOF
392done
393
394# Generate a boot strap Jamfile in the output directory, if it is not in
395# the source dir.
396
397if [ "$currentDir" != "$sourceDir" ]; then
398
399cat << EOF > $outputDir/Jamfile
400# automatically generated Jamfile
401
402HAIKU_TOP			= ${sourceDir} ;
403HAIKU_OUTPUT_DIR	= ${outputDir} ;
404
405include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
406
407EOF
408
409fi
410
411