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