xref: /haiku/configure (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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  --target=TARGET             Select build target platform. [default=${target}]
32                              valid targets=r5,bone,dano,haiku
33  --include-gpl-addons        Include GPL licensed add-ons.
34  --help                      Prints out this help.
35
36environment variables:
37  HAIKU_AR                    The static library archiver. Defaults to "ar".
38  HAIKU_CC                    The compiler. Defaults to "gcc".
39  HAIKU_LD                    The linker. Defaults to "ld".
40  HAIKU_OBJCOPY               The objcopy to be used. Defaults to "objcopy".
41  HAIKU_RANLIB                The static library indexer. Defaults to "ranlib".
42  HAIKU_CPPFLAGS              The preprocessor flags. Defaults to "".
43  HAIKU_CCFLAGS               The C flags. Defaults to "".
44  HAIKU_CXXFLAGS              The C++ flags. Defaults to "".
45  HAIKU_LDFLAGS               The linker flags. Defaults to "".
46  HAIKU_ARFLAGS               The flags passed to HAIKU_AR for archiving.
47                              Defaults to "ru".
48  HAIKU_UNARFLAGS             The flags passed to HAIKU_AR for unarchiving.
49                              Defaults to "x".
50EOF
51}
52
53# assertparam
54#
55# Checks whether at least one parameter is left.
56#
57assertparam()
58{
59	if [ $2 \< 2 ]; then
60		echo $0: \`$1\': Parameter expected.
61		exit 1
62	fi
63}
64
65# standard_gcc_settings
66#
67# Sets the variables for a GCC platform.
68#
69standard_gcc_settings()
70{
71	# PLATFORM_LINKLIBS
72	gcclib=`$HAIKU_CC -print-libgcc-file-name`
73	gccdir=`dirname ${gcclib}`
74	haikuGCCVersion=`$HAIKU_CC -dumpversion`
75	haikuGCCMachine=`$HAIKU_CC -dumpmachine`
76
77	HAIKU_GCC_LIB_DIR=${gccdir}
78	HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a
79	HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o"
80	HAIKU_GCC_HEADERS_DIR=${gccdir}/include
81	HAIKU_GCC_LIBGCC_OBJECTS=`ar t ${HAIKU_GCC_LIBGCC}`
82
83	# for gcc 4 we use the libstdc++ and libsupc++ that come with the compiler
84	case $haikuGCCVersion in
85		4.*)
86			haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a`
87			haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so`
88			haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a`
89			haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so`
90			local headers=$gccdir/../../../../include/c++/$haikuGCCVersion
91			haikuCxxHeadersDir=$headers
92			for d in $haikuGCCMachine backward ext debug; do
93				haikuCxxHeadersDir="$haikuCxxHeadersDir $headers/$d"
94			done
95
96			if [ $haikuStaticLibStdCxx = libstdc++.a ]; then
97				haikuStaticLibStdCxx=
98			fi
99			if [ $haikuSharedLibStdCxx = libstdc++.so ]; then
100				haikuSharedLibStdCxx=
101			fi
102			if [ $haikuStaticLibSupCxx = libsupc++.a ]; then
103				haikuStaticLibSupCxx=
104			fi
105			if [ $haikuSharedLibSupCxx = libsupc++.so ]; then
106				haikuSharedLibSupCxx=
107			fi
108		;;
109	esac
110}
111
112# set_default_value
113#
114# Set the value for a variable, if no value is set yet.
115#
116set_default_value()
117{
118	local var=$1;
119	# any better way?
120	(set -u; (eval "echo \${$var}") &> /dev/null) || eval "$var=$2"
121}
122
123# get_build_tool_path
124#
125# Gets a usable absolute path of a build tool.
126#
127get_build_tool_path()
128{
129	local var="HAIKU_$1"
130	local tool=$2
131	local path="${crossToolsPrefix}$tool"
132
133	if [ -f "$path" ]; then
134		# get absolute path
135		local oldPwd=$(pwd)
136		cd $(dirname "$path")
137		path="$(pwd)/$(basename "$path")"
138		cd $oldPwd
139	else
140		which "$path" &> /dev/null || {
141			echo "Build tool \"$path\" not found." >&2
142			exit 1
143		}
144	fi
145
146	eval "$var=$path"
147}
148
149# get cwd and the source directory
150currentDir=`pwd`
151cd `dirname $0`
152sourceDir=`pwd`
153cd $currentDir
154
155# default parameter values
156#
157platform=`uname`
158haikuGCCVersion=
159haikuStaticLibStdCxx=
160haikuSharedLibStdCxx=
161haikuStaticLibSupCxx=
162haikuSharedLibSupCxx=
163haikuCxxHeadersDir=
164hostGCCVersion=`cc -dumpversion`
165floppy=
166bochs_debug=0
167include_gpl_addons=0
168target=haiku
169crossToolsPrefix=
170buildCrossTools=
171
172set_default_value HAIKU_AR			ar
173set_default_value HAIKU_CC			gcc
174set_default_value HAIKU_LD			ld
175set_default_value HAIKU_OBJCOPY		objcopy
176set_default_value HAIKU_RANLIB		ranlib
177set_default_value HAIKU_CPPFLAGS	""
178set_default_value HAIKU_CCFLAGS		""
179set_default_value HAIKU_CXXFLAGS	""
180set_default_value HAIKU_LDFLAGS		""
181set_default_value HAIKU_ARFLAGS		ru
182set_default_value HAIKU_UNARFLAGS	x
183
184# parse parameters
185#
186while [ $# \> 0 ] ; do
187	case "$1" in
188		--include-gpl-addons)	include_gpl_addons=1; shift 1;;
189		--floppy)		assertparam "$1" $#; floppy=$2; shift 2;;
190		--bochs-debug)	bochs_debug=1; shift 1;;
191		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
192		--cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;;
193		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
194		--help | -h)	usage; exit 0;;
195		*)				echo Invalid argument: \`$1\'; exit 1;;
196	esac
197done
198
199# check parameters
200#
201if [ -n "$floppy" ]; then
202	case "$floppy" in
203		/*)	;;
204		*)	echo "Warning: non-absolute floppy path. Parameter ignored.";
205			floppy=;;
206	esac
207fi
208
209# detect the build platform
210case "${platform}" in
211	BeOS)	revision=`uname -r`
212			case "$revision" in
213				6.*)	buildPlatform=dano ;;
214				5.1)	buildPlatform=dano ;;
215				5.0.4)	buildPlatform=bone ;;
216				5.0*)	buildPlatform=r5 ;;
217				*)		echo Unknown BeOS version: $revision
218						exit 1 ;;
219			esac
220			;;
221	Linux)	buildPlatform=linux ;;
222	*)		echo Unsupported platform: ${platform}
223			exit 1 ;;
224esac
225
226# create output directory
227if [ "$currentDir" = "$sourceDir" ]; then
228	outputDir=$currentDir/generated
229else
230	outputDir=$currentDir
231fi
232buildOutputDir=$outputDir/build
233buildAttributesDir=$outputDir/attributes
234mkdir -p $buildOutputDir || exit 1
235
236# build cross tools from sources
237if [ -n "$buildCrossTools" ]; then
238	"$sourceDir/build/scripts/build_cross_tools"  "$sourceDir" \
239		"$buildCrossTools" || exit 1
240	crossToolsPrefix=$outputDir/cross-tools/bin/i586-pc-beos-
241fi
242
243# cross tools
244if [ -n "$crossToolsPrefix" ]; then
245	get_build_tool_path AR ar
246	get_build_tool_path CC gcc
247	get_build_tool_path LD ld
248	get_build_tool_path OBJCOPY objcopy
249	get_build_tool_path RANLIB ranlib
250fi
251
252# prepare gcc settings
253standard_gcc_settings
254
255# Generate BuildConfig
256cat << EOF > $buildOutputDir/BuildConfig
257# BuildConfig
258# Note: This file has been automatically generated by configure.
259
260FLOPPY_PATH			?= "${floppy}" ;
261BOCHS_DEBUG_HACK	?= ${bochs_debug} ;
262INCLUDE_GPL_ADDONS	?= ${include_gpl_addons} ;
263TARGET_PLATFORM 	?= ${target} ;
264HOST_PLATFORM		?= ${buildPlatform} ;
265
266HAIKU_GCC_RAW_VERSION	?= ${haikuGCCVersion} ;
267HAIKU_GCC_MACHINE		?= ${haikuGCCMachine} ;
268HAIKU_GCC_LIB_DIR		?= ${HAIKU_GCC_LIB_DIR} ;
269HAIKU_GCC_HEADERS_DIR	?= ${HAIKU_GCC_HEADERS_DIR} ;
270HAIKU_GCC_LIBGCC		?= ${HAIKU_GCC_LIBGCC} ;
271
272HAIKU_STATIC_LIBSTDC++	?= ${haikuStaticLibStdCxx} ;
273HAIKU_SHARED_LIBSTDC++	?= ${haikuSharedLibStdCxx} ;
274HAIKU_STATIC_LIBSUPC++	?= ${haikuStaticLibSupCxx} ;
275HAIKU_SHARED_LIBSUPC++	?= ${haikuSharedLibSupCxx} ;
276HAIKU_C++_HEADERS_DIR	?= ${haikuCxxHeadersDir} ;
277
278HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
279
280HAIKU_AR			?= ${HAIKU_AR} ;
281HAIKU_CC			?= ${HAIKU_CC} ;
282HAIKU_LD			?= ${HAIKU_LD} ;
283HAIKU_OBJCOPY		?= ${HAIKU_OBJCOPY} ;
284HAIKU_RANLIB		?= ${HAIKU_RANLIB} ;
285HAIKU_CPPFLAGS		?= ${HAIKU_CPPFLAGS} ;
286HAIKU_CCFLAGS		?= ${HAIKU_CCFLAGS} ;
287HAIKU_CXXFLAGS		?= ${HAIKU_CXXFLAGS} ;
288HAIKU_LDFLAGS		?= ${HAIKU_LDFLAGS} ;
289HAIKU_ARFLAGS		?= ${HAIKU_ARFLAGS} ;
290HAIKU_UNARFLAGS		?= ${HAIKU_UNARFLAGS} ;
291
292HOST_GCC_RAW_VERSION	?= ${hostGCCVersion} ;
293
294EOF
295
296# Libgcc.a objects
297
298cat << EOF > $buildOutputDir/libgccObjects
299# libgcc.a objects to be linked against libroot.so
300# Note: This file has been automatically generated by configure.
301
302HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
303EOF
304
305# Generate Timezones binaries bindings
306
307timezoneSources="africa antarctica asia australasia europe northamerica
308	southamerica pacificnew etcetera factory backward"
309
310cat << EOF > $buildOutputDir/Timezones
311# Timezones used for the build
312# Note: This file has been automatically generated by configure.
313
314HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
315
316EOF
317
318for source in ${timezoneSources}; do
319	f=$sourceDir/src/data/etc/timezones/$source
320
321TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' $f `
322
323cat << EOF >> $buildOutputDir/Timezones
324TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
325EOF
326done
327
328# Generate a boot strap Jamfile in the output directory, if it is not in
329# the source dir.
330
331if [ "$currentDir" != "$sourceDir" ]; then
332
333cat << EOF > $outputDir/Jamfile
334# automatically generated Jamfile
335
336HAIKU_TOP			= ${sourceDir} ;
337HAIKU_OUTPUT_DIR	= ${outputDir} ;
338
339include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
340
341EOF
342
343fi
344
345