xref: /haiku/configure (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
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  --floppy <floppy location>  Specifies the location of the floppy
16                              (device or image).
17  --bochs-debug               Enables bochs serial debug emulation (activated 
18                              via kernel settings file).
19  --cross-tools-prefix <prefix>
20                              Assume cross compilation. <prefix> should be a
21                              path to the directory where the cross
22                              compilation tools are located, plus the platform
23                              prefix, e.g. "/path/to/tools/i586-pc-beos-".
24                              This overrides the HAIKU_* tool variables.
25  --build-cross-tools <build tools dir>
26                              Assume cross compilation. <build tools dir>
27                              defines the location of the build tools sources.
28                              They will be compiled and placed in the output
29                              directory under "cross-tools". The HAIKU_* tools
30                              variables will be set accordingly.
31  --build-cross-tools-gcc4 <arch> <build tools dir>
32                              Like "--build-cross-tools" just that gcc 4 will
33                              be used for cross-compilation. Note, that the
34                              resulting Haiku installation built with gcc 4
35                              will not be binary compatible with BeOS R5.
36                              <arch> specifies the target architecture, either
37                              "x86" or "ppc".
38  --target=TARGET             Select build target platform. [default=${target}]
39                              valid targets=r5,bone,dano,haiku
40  --include-gpl-addons        Include GPL licensed add-ons.
41  --help                      Prints out this help.
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	haikuGCCVersion=`$HAIKU_CC -dumpversion`
94	haikuGCCMachine=`$HAIKU_CC -dumpmachine`
95
96	HAIKU_GCC_LIB_DIR=${gccdir}
97	HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a
98	HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o"
99	HAIKU_GCC_HEADERS_DIR=${gccdir}/include
100	HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o`
101		# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and
102		# neither needed nor wanted.
103
104	# for gcc 4 we use the libstdc++ and libsupc++ that come with the compiler
105	case $haikuGCCVersion in
106		4.*)
107			haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a`
108			haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so`
109			haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a`
110			haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so`
111			local headers=$gccdir/../../../../include/c++/$haikuGCCVersion
112			haikuCxxHeadersDir=$headers
113			for d in $haikuGCCMachine backward ext; do
114				# Note: We need the line break, otherwise the line might become
115				# too long for jam (512 bytes max).
116				haikuCxxHeadersDir="$haikuCxxHeadersDir
117					$headers/$d"
118			done
119
120			if [ $haikuStaticLibStdCxx = libstdc++.a ]; then
121				haikuStaticLibStdCxx=
122			fi
123			if [ $haikuSharedLibStdCxx = libstdc++.so ]; then
124				haikuSharedLibStdCxx=
125			fi
126			if [ $haikuStaticLibSupCxx = libsupc++.a ]; then
127				haikuStaticLibSupCxx=
128			fi
129			if [ $haikuSharedLibSupCxx = libsupc++.so ]; then
130				haikuSharedLibSupCxx=
131			fi
132		;;
133	esac
134}
135
136# set_default_value
137#
138# Set the value for a variable, if no value is set yet.
139#
140set_default_value()
141{
142	eval "$1=\${$1-$2}"
143}
144
145# get_build_tool_path
146#
147# Gets a usable absolute path of a build tool.
148#
149get_build_tool_path()
150{
151	local var="HAIKU_$1"
152	local tool=$2
153	local path="${crossToolsPrefix}$tool"
154
155	if [ -f "$path" ]; then
156		# get absolute path
157		local oldPwd=$(pwd)
158		cd $(dirname "$path")
159		path="$(pwd)/$(basename "$path")"
160		cd $oldPwd
161	else
162		which "$path" &> /dev/null || {
163			echo "Build tool \"$path\" not found." >&2
164			exit 1
165		}
166	fi
167
168	eval "$var=$path"
169}
170
171# get cwd and the source directory
172currentDir=`pwd`
173cd `dirname "$0"`
174sourceDir=`pwd`
175cd "$currentDir"
176
177# default parameter values
178#
179platform=`uname`
180haikuGCCVersion=
181haikuGCCMachine=i586-pc-beos
182haikuStaticLibStdCxx=
183haikuSharedLibStdCxx=
184haikuStaticLibSupCxx=
185haikuSharedLibSupCxx=
186haikuCxxHeadersDir=
187hostGCCVersion=`gcc -dumpversion`
188floppy=
189bochs_debug=0
190include_gpl_addons=0
191target=haiku
192crossToolsPrefix=
193buildCrossTools=
194buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
195buildCrossToolsMachine=
196
197set_default_value HAIKU_AR			ar
198set_default_value HAIKU_CC			gcc
199set_default_value HAIKU_LD			ld
200set_default_value HAIKU_OBJCOPY		objcopy
201set_default_value HAIKU_RANLIB		ranlib
202set_default_value HAIKU_CPPFLAGS	""
203set_default_value HAIKU_CCFLAGS		""
204set_default_value HAIKU_CXXFLAGS	""
205set_default_value HAIKU_LDFLAGS		""
206set_default_value HAIKU_ARFLAGS		ru
207set_default_value HAIKU_UNARFLAGS	x
208
209# parse parameters
210#
211while [ $# -gt 0 ] ; do
212	case "$1" in
213		--include-gpl-addons)	include_gpl_addons=1; shift 1;;
214		--floppy)		assertparam "$1" $#; floppy=$2; shift 2;;
215		--bochs-debug)	bochs_debug=1; shift 1;;
216		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
217		--cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;;
218		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
219		--build-cross-tools-gcc4) assertparams "$1" 2 $#; buildCrossTools=$3;
220						buildCrossToolsScript="${buildCrossToolsScript}_gcc4";
221						case "$2" in
222							x86)	haikuGCCMachine=i586-pc-haiku;;
223							ppc)	haikuGCCMachine=powerpc-apple-haiku;;
224							*)		echo "Unsupported target architecture: $2"
225									exit 1;;
226						esac
227						buildCrossToolsMachine=$haikuGCCMachine
228						shift 3;;
229		--help | -h)	usage; exit 0;;
230		*)				echo Invalid argument: \`$1\'; exit 1;;
231	esac
232done
233
234# check parameters
235#
236if [ -n "$floppy" ]; then
237	case "$floppy" in
238		/*)	;;
239		*)	echo "Warning: non-absolute floppy path. Parameter ignored.";
240			floppy=;;
241	esac
242fi
243
244# detect the build platform
245case "${platform}" in
246	BeOS)	revision=`uname -r`
247			case "$revision" in
248				6.*)	buildPlatform=dano ;;
249				5.1)	buildPlatform=dano ;;
250				5.0.4)	buildPlatform=bone ;;
251				5.0*)	buildPlatform=r5 ;;
252				6.*)	buildPlatform=dano ;;
253				*)		echo Unknown BeOS version: $revision
254						exit 1 ;;
255			esac
256			;;
257	Linux)	buildPlatform=linux ;;
258	FreeBSD) buildPlatform=freebsd ;;
259	*)		echo Unsupported platform: ${platform}
260			exit 1 ;;
261esac
262
263# create output directory
264if [ "$currentDir" = "$sourceDir" ]; then
265	outputDir=$currentDir/generated
266else
267	outputDir=$currentDir
268fi
269buildOutputDir="$outputDir/build"
270buildAttributesDir="$outputDir/attributes"
271mkdir -p "$buildOutputDir" || exit 1
272
273# build cross tools from sources
274if [ -n "$buildCrossTools" ]; then
275	"$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \
276		"$buildCrossTools" "$outputDir" || exit 1
277	crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-"
278fi
279
280# cross tools
281if [ -n "$crossToolsPrefix" ]; then
282	get_build_tool_path AR ar
283	get_build_tool_path CC gcc
284	get_build_tool_path LD ld
285	get_build_tool_path OBJCOPY objcopy
286	get_build_tool_path RANLIB ranlib
287fi
288
289# prepare gcc settings
290standard_gcc_settings
291
292# Generate BuildConfig
293cat << EOF > "$buildOutputDir/BuildConfig"
294# BuildConfig
295# Note: This file has been automatically generated by configure.
296
297FLOPPY_PATH			?= "${floppy}" ;
298BOCHS_DEBUG_HACK	?= "${bochs_debug}" ;
299INCLUDE_GPL_ADDONS	?= "${include_gpl_addons}" ;
300TARGET_PLATFORM 	?= "${target}" ;
301HOST_PLATFORM		?= "${buildPlatform}" ;
302
303HAIKU_GCC_RAW_VERSION	?= ${haikuGCCVersion} ;
304HAIKU_GCC_MACHINE		?= ${haikuGCCMachine} ;
305HAIKU_GCC_LIB_DIR		?= ${HAIKU_GCC_LIB_DIR} ;
306HAIKU_GCC_HEADERS_DIR	?= ${HAIKU_GCC_HEADERS_DIR} ;
307HAIKU_GCC_LIBGCC		?= ${HAIKU_GCC_LIBGCC} ;
308
309HAIKU_STATIC_LIBSTDC++	?= ${haikuStaticLibStdCxx} ;
310HAIKU_SHARED_LIBSTDC++	?= ${haikuSharedLibStdCxx} ;
311HAIKU_STATIC_LIBSUPC++	?= ${haikuStaticLibSupCxx} ;
312HAIKU_SHARED_LIBSUPC++	?= ${haikuSharedLibSupCxx} ;
313HAIKU_C++_HEADERS_DIR	?= ${haikuCxxHeadersDir} ;
314
315HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
316
317HAIKU_AR			?= ${HAIKU_AR} ;
318HAIKU_CC			?= ${HAIKU_CC} ;
319HAIKU_LD			?= ${HAIKU_LD} ;
320HAIKU_OBJCOPY		?= ${HAIKU_OBJCOPY} ;
321HAIKU_RANLIB		?= ${HAIKU_RANLIB} ;
322HAIKU_CPPFLAGS		?= ${HAIKU_CPPFLAGS} ;
323HAIKU_CCFLAGS		?= ${HAIKU_CCFLAGS} ;
324HAIKU_CXXFLAGS		?= ${HAIKU_CXXFLAGS} ;
325HAIKU_LDFLAGS		?= ${HAIKU_LDFLAGS} ;
326HAIKU_ARFLAGS		?= ${HAIKU_ARFLAGS} ;
327HAIKU_UNARFLAGS		?= ${HAIKU_UNARFLAGS} ;
328
329HOST_GCC_RAW_VERSION	?= ${hostGCCVersion} ;
330
331EOF
332
333# Libgcc.a objects
334
335cat << EOF > "$buildOutputDir/libgccObjects"
336# libgcc.a objects to be linked against libroot.so
337# Note: This file has been automatically generated by configure.
338
339HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
340EOF
341
342# Generate Timezones binaries bindings
343
344timezoneSources="africa antarctica asia australasia europe northamerica
345	southamerica pacificnew etcetera factory backward"
346
347cat << EOF > "$buildOutputDir/Timezones"
348# Timezones used for the build
349# Note: This file has been automatically generated by configure.
350
351HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
352
353EOF
354
355for source in ${timezoneSources}; do
356	f=$sourceDir/src/data/etc/timezones/$source
357
358TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" `
359
360cat << EOF >> "$buildOutputDir/Timezones"
361TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
362EOF
363done
364
365# Generate a boot strap Jamfile in the output directory, if it is not in
366# the source dir.
367
368if [ "$currentDir" != "$sourceDir" ]; then
369
370cat << EOF > $outputDir/Jamfile
371# automatically generated Jamfile
372
373HAIKU_TOP			= ${sourceDir} ;
374HAIKU_OUTPUT_DIR	= ${outputDir} ;
375
376include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
377
378EOF
379
380fi
381
382