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