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