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