xref: /haiku/configure (revision 94978fa6a71bdb289ed6a14fa0292adaeceb5380)
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
84# set_default_value
85#
86# Set the value for a variable, if no value is set yet.
87#
88set_default_value()
89{
90	local var=$1;
91	# any better way?
92	(set -u; (eval "echo \${$var}") &> /dev/null) || eval "$var=$2"
93}
94
95# get_build_tool_path
96#
97# Gets a usable absolute path of a build tool.
98#
99get_build_tool_path()
100{
101	local var="HAIKU_$1"
102	local tool=$2
103	local path="${crossToolsPrefix}$tool"
104
105	if [ -f "$path" ]; then
106		# get absolute path
107		local oldPwd=$(pwd)
108		cd $(dirname "$path")
109		path="$(pwd)/$(basename "$path")"
110		cd $oldPwd
111	else
112		which "$path" &> /dev/null || {
113			echo "Build tool \"$path\" not found." >&2
114			exit 1
115		}
116	fi
117
118	eval "$var=$path"
119}
120
121# get cwd and the source directory
122currentDir=`pwd`
123cd `dirname $0`
124sourceDir=`pwd`
125cd $currentDir
126
127# default parameter values
128#
129platform=`uname`
130haikuGCCVersion=
131floppy=
132bochs_debug=0
133include_gpl_addons=0
134target=haiku
135crossToolsPrefix=
136buildCrossTools=
137
138set_default_value HAIKU_AR			ar
139set_default_value HAIKU_CC			gcc
140set_default_value HAIKU_LD			ld
141set_default_value HAIKU_OBJCOPY		objcopy
142set_default_value HAIKU_RANLIB		ranlib
143set_default_value HAIKU_CPPFLAGS	""
144set_default_value HAIKU_CCFLAGS		""
145set_default_value HAIKU_CXXFLAGS	""
146set_default_value HAIKU_LDFLAGS		""
147set_default_value HAIKU_ARFLAGS		ru
148set_default_value HAIKU_UNARFLAGS	x
149
150# parse parameters
151#
152while [ $# \> 0 ] ; do
153	case "$1" in
154		--include-gpl-addons)	include_gpl_addons=1; shift 1;;
155		--floppy)		assertparam "$1" $#; floppy=$2; shift 2;;
156		--bochs-debug)	bochs_debug=1; shift 1;;
157		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
158		--cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;;
159		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
160		--help | -h)	usage; exit 0;;
161		*)				echo Invalid argument: \`$1\'; exit 1;;
162	esac
163done
164
165# check parameters
166#
167if [ -n "$floppy" ]; then
168	case "$floppy" in
169		/*)	;;
170		*)	echo "Warning: non-absolute floppy path. Parameter ignored.";
171			floppy=;;
172	esac
173fi
174
175# detect the build platform
176case "${platform}" in
177	BeOS)	revision=`uname -r`
178			case "$revision" in
179				5.1)	buildPlatform=dano ;;
180				5.0.4)	buildPlatform=bone ;;
181				5.0*)	buildPlatform=r5 ;;
182				*)		echo Unknown BeOS version: $revision
183						exit 1 ;;
184			esac
185			;;
186	Linux)	buildPlatform=linux ;;
187	*)		echo Unsupported platform: ${platform}
188			exit 1 ;;
189esac
190
191# create output directory
192if [ "$currentDir" = "$sourceDir" ]; then
193	outputDir=$currentDir/generated
194else
195	outputDir=$currentDir
196fi
197buildOutputDir=$outputDir/build
198buildAttributesDir=$outputDir/attributes
199mkdir -p $buildOutputDir || exit 1
200
201# build cross tools from sources
202if [ -n "$buildCrossTools" ]; then
203	"$sourceDir/build/scripts/build_cross_tools"  "$sourceDir" \
204		"$buildCrossTools" || exit 1
205	crossToolsPrefix=$outputDir/cross-tools/bin/i586-pc-beos-
206fi
207
208# cross tools
209if [ -n "$crossToolsPrefix" ]; then
210	get_build_tool_path AR ar
211	get_build_tool_path CC gcc
212	get_build_tool_path LD ld
213	get_build_tool_path OBJCOPY objcopy
214	get_build_tool_path RANLIB ranlib
215fi
216
217# prepare gcc settings
218standard_gcc_settings
219
220# Generate BuildConfig
221cat << EOF > $buildOutputDir/BuildConfig
222# BuildConfig
223# Note: This file has been automatically generated by configure.
224
225FLOPPY_PATH			?= "${floppy}" ;
226BOCHS_DEBUG_HACK	?= ${bochs_debug} ;
227INCLUDE_GPL_ADDONS	?= ${include_gpl_addons} ;
228TARGET_PLATFORM 	?= ${target} ;
229HOST_PLATFORM		?= ${buildPlatform} ;
230
231HAIKU_GCC_RAW_VERSION	?= ${haikuGCCVersion} ;
232HAIKU_GCC_MACHINE		?= ${haikuGCCMachine} ;
233HAIKU_GCC_LIB_DIR		?= ${HAIKU_GCC_LIB_DIR} ;
234HAIKU_GCC_HEADERS_DIR	?= ${HAIKU_GCC_HEADERS_DIR} ;
235HAIKU_GCC_LIBGCC		?= ${HAIKU_GCC_LIBGCC} ;
236
237HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
238
239HAIKU_AR			?= ${HAIKU_AR} ;
240HAIKU_CC			?= ${HAIKU_CC} ;
241HAIKU_LD			?= ${HAIKU_LD} ;
242HAIKU_OBJCOPY		?= ${HAIKU_OBJCOPY} ;
243HAIKU_RANLIB		?= ${HAIKU_RANLIB} ;
244HAIKU_CPPFLAGS		?= ${HAIKU_CPPFLAGS} ;
245HAIKU_CCFLAGS		?= ${HAIKU_CCFLAGS} ;
246HAIKU_CXXFLAGS		?= ${HAIKU_CXXFLAGS} ;
247HAIKU_LDFLAGS		?= ${HAIKU_LDFLAGS} ;
248HAIKU_ARFLAGS		?= ${HAIKU_ARFLAGS} ;
249HAIKU_UNARFLAGS		?= ${HAIKU_UNARFLAGS} ;
250
251EOF
252
253# Libgcc.a objects
254
255cat << EOF > $buildOutputDir/libgccObjects
256# libgcc.a objects to be linked against libroot.so
257# Note: This file has been automatically generated by configure.
258
259HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
260EOF
261
262# Generate Timezones binaries bindings
263
264timezoneSources="africa antarctica asia australasia europe northamerica
265	southamerica pacificnew etcetera factory backward"
266
267cat << EOF > $buildOutputDir/Timezones
268# Timezones used for the build
269# Note: This file has been automatically generated by configure.
270
271HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
272
273EOF
274
275for source in ${timezoneSources}; do
276	f=$sourceDir/src/data/etc/timezones/$source
277
278TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' $f `
279
280cat << EOF >> $buildOutputDir/Timezones
281TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
282EOF
283done
284
285# Generate a boot strap Jamfile in the output directory, if it is not in
286# the source dir.
287
288if [ "$currentDir" != "$sourceDir" ]; then
289
290cat << EOF > $outputDir/Jamfile
291# automatically generated Jamfile
292
293HAIKU_TOP			= ${sourceDir} ;
294HAIKU_OUTPUT_DIR	= ${outputDir} ;
295
296include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
297
298EOF
299
300fi
301
302