xref: /haiku/configure (revision b06a48ab8f30b45916a9c157b992827779182163)
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	HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o`
124		# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and
125		# neither needed nor wanted.
126
127	case $haikuGCCVersion in
128		4.*)
129			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
130			# compiler
131			haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a`
132			haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so`
133			haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a`
134			haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so`
135			local headers=$gccdir/../../../../include/c++/$haikuGCCVersion
136			haikuCxxHeadersDir=$headers
137			for d in $haikuGCCMachine backward ext; do
138				# Note: We need the line break, otherwise the line might become
139				# too long for jam (512 bytes max).
140				haikuCxxHeadersDir="$haikuCxxHeadersDir
141					$headers/$d"
142			done
143
144
145			# when not building the crosscompiler, to use cpp headers from
146			# tree first, but fallback to local C++ system headers (like <new>)
147			# if [ "$buildCrossTools" = "" ]; then
148			#	haikuCxxHeadersDir="headers/cpp $haikuCxxHeadersDir"
149			# fi
150
151			if [ $haikuStaticLibStdCxx = libstdc++.a ]; then
152				haikuStaticLibStdCxx=
153			fi
154			if [ $haikuSharedLibStdCxx = libstdc++.so ]; then
155				haikuSharedLibStdCxx=
156			fi
157			if [ $haikuStaticLibSupCxx = libsupc++.a ]; then
158				haikuStaticLibSupCxx=
159			fi
160			if [ $haikuSharedLibSupCxx = libsupc++.so ]; then
161				haikuSharedLibSupCxx=
162			fi
163		;;
164		2.9*)
165			# check for correct (most up-to-date) legacy compiler and complain
166			# if an older one is installed
167			if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then
168				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
169				echo "Please download it from www.haiku-os.org...";
170				exit 1;
171			fi
172		;;
173	esac
174}
175
176# set_default_value
177#
178# Set the value for a variable, if no value is set yet.
179#
180set_default_value()
181{
182	eval "$1=\${$1-$2}"
183}
184
185# get_build_tool_path
186#
187# Gets a usable absolute path of a build tool.
188#
189get_build_tool_path()
190{
191	local var="HAIKU_$1"
192	local tool=$2
193	local path="${crossToolsPrefix}$tool"
194
195	if [ -f "$path" ]; then
196		# get absolute path
197		local oldPwd="`pwd`"
198		cd "`dirname "$path"`"
199		path="`pwd`/`basename "$path"`"
200		cd $oldPwd
201	else
202		which "$path" &> /dev/null || {
203			echo "Build tool \"$path\" not found." >&2
204			exit 1
205		}
206	fi
207
208	eval "$var=$path"
209}
210
211# get cwd and the source directory
212currentDir=`pwd`
213cd `dirname "$0"`
214sourceDir=`pwd`
215cd "$currentDir"
216
217# default parameter values
218#
219platform=`uname`
220haikuGCCVersion=
221haikuGCCMachine=i586-pc-haiku
222haikuStaticLibStdCxx=
223haikuSharedLibStdCxx=
224haikuStaticLibSupCxx=
225haikuSharedLibSupCxx=
226haikuCxxHeadersDir=
227hostGCCVersion=`gcc -dumpversion`
228bochs_debug=0
229include_gpl_addons=0
230include_3rdparty=0
231enable_multiuser=0
232distroCompatibility=default
233target=haiku
234use_gcc_pipe=0
235use_32bit=0
236use_xattr=0
237crossToolsPrefix=
238buildCrossTools=
239buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
240buildCrossToolsMachine=
241alternativeGCCOutputDir=
242
243haikuRequiredLegacyGCCVersion="2.95.3-haiku-080323"
244export haikuRequiredLegacyGCCVersion
245	# version of legacy gcc required to build haiku
246
247set_default_value HAIKU_AR			ar
248set_default_value HAIKU_CC			gcc
249set_default_value HAIKU_LD			ld
250set_default_value HAIKU_OBJCOPY		objcopy
251set_default_value HAIKU_RANLIB		ranlib
252set_default_value HAIKU_CPPFLAGS	""
253set_default_value HAIKU_CCFLAGS		""
254set_default_value HAIKU_CXXFLAGS	""
255set_default_value HAIKU_LDFLAGS		""
256set_default_value HAIKU_ARFLAGS		ru
257set_default_value HAIKU_UNARFLAGS	x
258
259# parse parameters
260#
261while [ $# -gt 0 ] ; do
262	case "$1" in
263		--bochs-debug)	bochs_debug=1; shift 1;;
264		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
265		--build-cross-tools-gcc4)
266			assertparams "$1" 2 $#
267			buildCrossTools=$3
268			buildCrossToolsScript="${buildCrossToolsScript}_gcc4"
269			case "$2" in
270				x86)	haikuGCCMachine=i586-pc-haiku;;
271				ppc)	haikuGCCMachine=powerpc-apple-haiku;;
272				m68k)	haikuGCCMachine=m68k-unknown-haiku;;
273				*)		echo "Unsupported target architecture: $2"
274						exit 1;;
275			esac
276			buildCrossToolsMachine=$haikuGCCMachine
277			shift 3
278			;;
279		--alternative-gcc-output-dir)
280			assertparam "$1" $#
281			cd $2 || exit 1
282			alternativeGCCOutputDir=`pwd`
283			cd $currentDir
284			shift 2
285			;;
286		--cross-tools-prefix)
287			assertparam "$1" $#
288			crossToolsPrefix=$2
289			shift 2
290			;;
291		--help | -h)	usage; exit 0;;
292		--include-gpl-addons)	include_gpl_addons=1; shift 1;;
293		--include-3rdparty)	include_3rdparty=1; shift 1;;
294		--enable-multiuser)	enable_multiuser=1; shift 1;;
295		--distro-compatibility)
296			assertparam "$1" $#
297			distroCompatibility=$2
298			case "$distroCompatibility" in
299				official)	;;
300				compatible)	;;
301				default)	;;
302				*)			echo "Invalid distro compatibility" \
303								"level: $distroCompatibility"
304							exit 1;;
305			esac
306			shift 2
307			;;
308		--target=*)     target=`echo $1 | cut -d'=' -f2-`; shift 1;;
309		--use-gcc-pipe)	use_gcc_pipe=1; shift 1;;
310		--use-32bit)	use_32bit=1; shift 1;;
311		--use-xattr)	use_xattr=1; shift 1;;
312		*)				echo Invalid argument: \`$1\'; exit 1;;
313	esac
314done
315
316# detect the build platform
317case "${platform}" in
318	BeOS)	revision=`uname -r`
319			case "$revision" in
320				6.*)	buildPlatform=dano ;;
321				5.1)	buildPlatform=dano ;;
322				5.0.4)	buildPlatform=bone ;;
323				5.0*)	buildPlatform=r5 ;;
324				*)		echo Unknown BeOS version: $revision
325						exit 1 ;;
326			esac
327			;;
328	Darwin)	buildPlatform=darwin ;;
329	FreeBSD) buildPlatform=freebsd ;;
330	Haiku)	buildPlatform=haiku_host ;;
331	Linux)	buildPlatform=linux ;;
332	SunOS)	buildPlatform=sunos ;;
333	CYGWIN_NT-*) buildPlatform=cygwin ;;
334	*)		echo Unsupported platform: ${platform}
335			exit 1 ;;
336esac
337
338# create output directory
339if [ "$currentDir" = "$sourceDir" ]; then
340	outputDir=$currentDir/generated
341else
342	outputDir=$currentDir
343fi
344buildOutputDir="$outputDir/build"
345buildAttributesDir="$outputDir/attributes"
346mkdir -p "$buildOutputDir" || exit 1
347
348# build cross tools from sources
349if [ -n "$buildCrossTools" ]; then
350	"$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \
351		"$buildCrossTools" "$outputDir" || exit 1
352	crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-"
353fi
354
355# cross tools
356if [ -n "$crossToolsPrefix" ]; then
357	get_build_tool_path AR ar
358	get_build_tool_path CC gcc
359	get_build_tool_path LD ld
360	get_build_tool_path OBJCOPY objcopy
361	get_build_tool_path RANLIB ranlib
362fi
363
364# prepare gcc settings
365standard_gcc_settings
366
367# check whether the Haiku compiler really targets Haiku or BeOS
368case "$haikuGCCMachine" in
369	*-*-haiku)	;;
370	*-*-beos)	;;
371	*) echo The compiler specified as Haiku target compiler is not a valid \
372			Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
373	   echo compiler: $HAIKU_CC
374	   echo compiler is configured for target: $haikuGCCMachine
375	   exit 1 ;;
376esac
377
378# Generate BuildConfig
379cat << EOF > "$buildOutputDir/BuildConfig"
380# BuildConfig
381# Note: This file has been automatically generated by configure.
382
383TARGET_PLATFORM 			?= "${target}" ;
384HOST_PLATFORM				?= "${buildPlatform}" ;
385
386BOCHS_DEBUG_HACK					?= "${bochs_debug}" ;
387INCLUDE_GPL_ADDONS					?= "${include_gpl_addons}" ;
388HAIKU_INCLUDE_3RDPARTY				?= "${include_3rdparty}" ;
389HAIKU_ENABLE_MULTIUSER				?= "${enable_multiuser}" ;
390HAIKU_DISTRO_COMPATIBILITY			?= "${distroCompatibility}" ;
391HAIKU_USE_GCC_PIPE					?= "${use_gcc_pipe}" ;
392HAIKU_HOST_USE_32BIT				?= "${use_32bit}" ;
393HAIKU_HOST_USE_XATTR				?= "${use_xattr}" ;
394HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR	?= ${alternativeGCCOutputDir} ;
395
396HAIKU_GCC_RAW_VERSION		?= ${haikuGCCVersion} ;
397HAIKU_GCC_MACHINE			?= ${haikuGCCMachine} ;
398HAIKU_GCC_LIB_DIR			?= ${HAIKU_GCC_LIB_DIR} ;
399HAIKU_GCC_HEADERS_DIR		?= ${HAIKU_GCC_HEADERS_DIR} ;
400HAIKU_GCC_LIBGCC			?= ${HAIKU_GCC_LIBGCC} ;
401
402HAIKU_STATIC_LIBSTDC++		?= ${haikuStaticLibStdCxx} ;
403HAIKU_SHARED_LIBSTDC++		?= ${haikuSharedLibStdCxx} ;
404HAIKU_STATIC_LIBSUPC++		?= ${haikuStaticLibSupCxx} ;
405HAIKU_SHARED_LIBSUPC++		?= ${haikuSharedLibSupCxx} ;
406HAIKU_C++_HEADERS_DIR		?= ${haikuCxxHeadersDir} ;
407
408HAIKU_BUILD_ATTRIBUTES_DIR	?= ${buildAttributesDir} ;
409
410HAIKU_AR					?= ${HAIKU_AR} ;
411HAIKU_CC					?= ${HAIKU_CC} ;
412HAIKU_LD					?= ${HAIKU_LD} ;
413HAIKU_OBJCOPY				?= ${HAIKU_OBJCOPY} ;
414HAIKU_RANLIB				?= ${HAIKU_RANLIB} ;
415HAIKU_CPPFLAGS				?= ${HAIKU_CPPFLAGS} ;
416HAIKU_CCFLAGS				?= ${HAIKU_CCFLAGS} ;
417HAIKU_CXXFLAGS				?= ${HAIKU_CXXFLAGS} ;
418HAIKU_LDFLAGS				?= ${HAIKU_LDFLAGS} ;
419HAIKU_ARFLAGS				?= ${HAIKU_ARFLAGS} ;
420HAIKU_UNARFLAGS				?= ${HAIKU_UNARFLAGS} ;
421
422HOST_GCC_RAW_VERSION		?= ${hostGCCVersion} ;
423
424EOF
425
426# Libgcc.a objects
427
428cat << EOF > "$buildOutputDir/libgccObjects"
429# libgcc.a objects to be linked against libroot.so
430# Note: This file has been automatically generated by configure.
431
432HAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
433EOF
434
435# Generate Timezones binaries bindings
436
437timezoneSources="africa antarctica asia australasia europe northamerica
438	southamerica pacificnew etcetera factory backward"
439
440cat << EOF > "$buildOutputDir/Timezones"
441# Timezones used for the build
442# Note: This file has been automatically generated by configure.
443
444HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ;
445
446EOF
447
448for source in ${timezoneSources}; do
449	f=$sourceDir/src/data/etc/timezones/$source
450
451TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" `
452
453cat << EOF >> "$buildOutputDir/Timezones"
454TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ;
455EOF
456done
457
458# Generate a boot strap Jamfile in the output directory.
459
460cat << EOF > $outputDir/Jamfile
461# automatically generated Jamfile
462
463HAIKU_TOP			= ${sourceDir} ;
464HAIKU_OUTPUT_DIR	= ${outputDir} ;
465
466include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
467
468EOF
469