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