xref: /haiku/configure (revision 65ad1ba320d945c9626f471c4fb0972ae49440b5)
152a38012Sejakowatz#!/bin/sh
252a38012Sejakowatz#
3338b8dc3SIngo Weinhold# configure [ <options> ]
4614026d7Sshatty
5022fa244SIngo Weinhold# usage
6022fa244SIngo Weinhold#
7022fa244SIngo Weinhold# Prints usage.
8022fa244SIngo Weinhold#
9022fa244SIngo Weinholdusage()
10022fa244SIngo Weinhold{
11022fa244SIngo Weinhold	cat << EOF
12022fa244SIngo Weinhold
13022fa244SIngo WeinholdUsage: $0 <options>
14022fa244SIngo Weinholdoptions:
1560d8d8fcSIngo Weinhold  --alternative-gcc-output-dir <dir>
1660d8d8fcSIngo Weinhold                              Build a Haiku installation that supports running
1760d8d8fcSIngo Weinhold                              executables built with a gcc version incompatible
1860d8d8fcSIngo Weinhold                              with the primary gcc (e.g. gcc 2 executables under
1960d8d8fcSIngo Weinhold                              a gcc 4 Haiku or vice versa). <dir> specifies the
2060d8d8fcSIngo Weinhold                              output directory of the other gcc. The directory
2160d8d8fcSIngo Weinhold                              must already be fully configured.
2260d8d8fcSIngo Weinhold                              Note, that a sub-jam will be executed when
2360d8d8fcSIngo Weinhold                              building Haiku. When using a jam that is not
2460d8d8fcSIngo Weinhold                              simply invoked by "jam", the JAM build variable
2560d8d8fcSIngo Weinhold                              needs to be set accordingly.
2660d8d8fcSIngo Weinhold                              To disable building the alternative libraries
2760d8d8fcSIngo Weinhold                              the variable HAIKU_ADD_ALTERNATIVE_GCC_LIBS can be
2860d8d8fcSIngo Weinhold                              unset in the UserBuildConfig file.
29338b8dc3SIngo Weinhold  --build-cross-tools <build tools dir>
30338b8dc3SIngo Weinhold                              Assume cross compilation. <build tools dir>
31338b8dc3SIngo Weinhold                              defines the location of the build tools sources.
32338b8dc3SIngo Weinhold                              They will be compiled and placed in the output
33a5b60fa8SOliver Tappe                              directory under "cross-tools". The HAIKU_* tools
34a5b60fa8SOliver Tappe                              variables will be set accordingly.
3520ab75e6SIngo Weinhold  --build-cross-tools-gcc4 <arch> <build tools dir>
3629ef597dSIngo Weinhold                              Like "--build-cross-tools" just that gcc 4 will
37a5b60fa8SOliver Tappe                              be used for cross-compilation. Note, that the
38a5b60fa8SOliver Tappe                              resulting Haiku installation built with gcc 4
39a5b60fa8SOliver Tappe                              will not be binary compatible with BeOS R5.
4020ab75e6SIngo Weinhold                              <arch> specifies the target architecture, either
4197901ec5SIngo Weinhold                              "x86", "x86_64", "ppc", "m68k", "arm" or "mipsel".
42eccc7665SIngo Weinhold  --cross-tools-prefix <prefix>
43eccc7665SIngo Weinhold                              Assume cross compilation. <prefix> should be a
44eccc7665SIngo Weinhold                              path to the directory where the cross
45eccc7665SIngo Weinhold                              compilation tools are located, plus the platform
460da9c208SIngo Weinhold                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
47eccc7665SIngo Weinhold                              This overrides the HAIKU_* tool variables.
48a66c32ddSIngo Weinhold  --distro-compatibility <level>
49a66c32ddSIngo Weinhold                              The distribution's level of compatibility with
50a66c32ddSIngo Weinhold                              the official Haiku distribution. The generated
51a66c32ddSIngo Weinhold                              files will contain the respective trademarks
52a66c32ddSIngo Weinhold                              accordingly.
53a66c32ddSIngo Weinhold                              official -- the official Haiku distribution.
54a66c32ddSIngo Weinhold                              compatible -- a Haiku Compatible (tm) distro.
55a66c32ddSIngo Weinhold                              default -- any other distro (default value).
5660d8d8fcSIngo Weinhold  --enable-multiuser          Enable experimental multiuser support.
57eccc7665SIngo Weinhold  --help                      Prints out this help.
58eccc7665SIngo Weinhold  --include-gpl-addons        Include GPL licensed add-ons.
5967838392SAxel Dörfler  --include-patented-code     Enable code that is known to implemented patented
6067838392SAxel Dörfler                              ideas and techniques. If this option is not
6167838392SAxel Dörfler                              specified, the resulting distribution may still
6267838392SAxel Dörfler                              implement patented ideas and techniques. This
6367838392SAxel Dörfler                              option only disables code that is currently known
6467838392SAxel Dörfler                              to be problematic.
6576fa0be3SIngo Weinhold  --include-sources           Includes the source code of projects that require
6676fa0be3SIngo Weinhold                              either an offer of source code or a copy of the
6776fa0be3SIngo Weinhold                              patched sources. This is preferable when
6876fa0be3SIngo Weinhold                              distributing on physical mediums.
691974210fSFrançois Revol  --include-3rdparty          Include 3rdparty/ in the build system.
7060d8d8fcSIngo Weinhold  -j<n>                       Only relevant for --build-cross-tools and
7160d8d8fcSIngo Weinhold                              --build-cross-tools-gcc4. Is passed on to the
7260d8d8fcSIngo Weinhold                              make building the build tools.
737c4641d0SOliver Tappe  --target=TARGET             Select build target platform.
747c4641d0SOliver Tappe                              [default=${TARGET_PLATFORM}]
75a17b9c0cSshatty                              valid targets=r5,bone,dano,haiku
767c4641d0SOliver Tappe  --update                    re-runs last configure invocation [must be given
777c4641d0SOliver Tappe                              as first option!]
78eccc7665SIngo Weinhold  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
795a34a443SFrançois Revol                              process, but uses more memory.
800385b065SIngo Weinhold  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
814f4e5272SIngo Weinhold  --use-xattr                 Use Linux xattr support for BeOS attribute
824f4e5272SIngo Weinhold                              emulation. Warning: Make sure your file system
834f4e5272SIngo Weinhold                              supports sufficient attribute sizes (4 KB per
844f4e5272SIngo Weinhold                              file for all attributes won't suffice).
85338b8dc3SIngo Weinhold
86338b8dc3SIngo Weinholdenvironment variables:
87338b8dc3SIngo Weinhold  HAIKU_AR                    The static library archiver. Defaults to "ar".
88338b8dc3SIngo Weinhold  HAIKU_CC                    The compiler. Defaults to "gcc".
89338b8dc3SIngo Weinhold  HAIKU_LD                    The linker. Defaults to "ld".
90338b8dc3SIngo Weinhold  HAIKU_OBJCOPY               The objcopy to be used. Defaults to "objcopy".
91338b8dc3SIngo Weinhold  HAIKU_RANLIB                The static library indexer. Defaults to "ranlib".
9277e84f21SIngo Weinhold  HAIKU_YASM                  The yasm assembler (x86 only).
93338b8dc3SIngo Weinhold  HAIKU_CPPFLAGS              The preprocessor flags. Defaults to "".
94338b8dc3SIngo Weinhold  HAIKU_CCFLAGS               The C flags. Defaults to "".
95338b8dc3SIngo Weinhold  HAIKU_CXXFLAGS              The C++ flags. Defaults to "".
96338b8dc3SIngo Weinhold  HAIKU_LDFLAGS               The linker flags. Defaults to "".
97338b8dc3SIngo Weinhold  HAIKU_ARFLAGS               The flags passed to HAIKU_AR for archiving.
9823eb9a9eSFrançois Revol                              Defaults to "cru".
99338b8dc3SIngo Weinhold  HAIKU_UNARFLAGS             The flags passed to HAIKU_AR for unarchiving.
100338b8dc3SIngo Weinhold                              Defaults to "x".
10164f6da31SIngo Weinhold
10264f6da31SIngo WeinholdNon-standard output directories:
10364f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
10464f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
10564f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
10664f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
10764f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
10864f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
10964f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
11064f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
11164f6da31SIngo Weinhold  non-default location and running jam.
11264f6da31SIngo Weinhold
11364f6da31SIngo Weinhold
114022fa244SIngo WeinholdEOF
115022fa244SIngo Weinhold}
116022fa244SIngo Weinhold
117022fa244SIngo Weinhold# assertparam
118022fa244SIngo Weinhold#
119022fa244SIngo Weinhold# Checks whether at least one parameter is left.
120022fa244SIngo Weinhold#
121022fa244SIngo Weinholdassertparam()
122022fa244SIngo Weinhold{
12320ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
124022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
125022fa244SIngo Weinhold		exit 1
126022fa244SIngo Weinhold	fi
127022fa244SIngo Weinhold}
128022fa244SIngo Weinhold
12920ab75e6SIngo Weinhold# assertparams
13020ab75e6SIngo Weinhold#
13120ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
13220ab75e6SIngo Weinhold#
13320ab75e6SIngo Weinholdassertparams()
13420ab75e6SIngo Weinhold{
13520ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
13620ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
13720ab75e6SIngo Weinhold		exit 1
13820ab75e6SIngo Weinhold	fi
13920ab75e6SIngo Weinhold}
14020ab75e6SIngo Weinhold
1419a001156SOliver Tappe# real_path
1429a001156SOliver Tappe#
1439a001156SOliver Tappe# returns the realpath of a symbolic link.
1449a001156SOliver Tappe#
1459a001156SOliver Tappereal_path()
1469a001156SOliver Tappe{
1479a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
1489a001156SOliver Tappe}
1499a001156SOliver Tappe
15009c5682dSIngo Weinhold# standard_gcc_settings
15109c5682dSIngo Weinhold#
15209c5682dSIngo Weinhold# Sets the variables for a GCC platform.
15309c5682dSIngo Weinhold#
15409c5682dSIngo Weinholdstandard_gcc_settings()
15509c5682dSIngo Weinhold{
156138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
157b29b48b1SMatt Madia		readlink="greadlink -e"
158138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
159b29b48b1SMatt Madia		readlink=realpath
1609a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
161b29b48b1SMatt Madia		readlink="readlink -e"
1629a001156SOliver Tappe	else
1639a001156SOliver Tappe		readlink=real_path
164b4b6d83cSMatt Madia	fi
165138f5fb4SIngo Weinhold
16609c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
167338b8dc3SIngo Weinhold	gcclib=`$HAIKU_CC -print-libgcc-file-name`
16809c5682dSIngo Weinhold	gccdir=`dirname ${gcclib}`
1695b0f7b1bSOliver Tappe
1707c4641d0SOliver Tappe	HAIKU_GCC_RAW_VERSION=`$HAIKU_CC -dumpversion`
1717c4641d0SOliver Tappe	HAIKU_GCC_MACHINE=`$HAIKU_CC -dumpmachine`
172338b8dc3SIngo Weinhold
173338b8dc3SIngo Weinhold	HAIKU_GCC_LIB_DIR=${gccdir}
174338b8dc3SIngo Weinhold	HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a
175338b8dc3SIngo Weinhold	HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o"
17628b5bc75SMichael Lotz	HAIKU_GCC_HEADERS_DIR="${gccdir}/include
17728b5bc75SMichael Lotz		${gccdir}/include-fixed"
1785d978968SIngo Weinhold	HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o`
1795d978968SIngo Weinhold		# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and
1805d978968SIngo Weinhold		# neither needed nor wanted.
1818b5934c9SIngo Weinhold
1827c4641d0SOliver Tappe	case $HAIKU_GCC_RAW_VERSION in
1838b5934c9SIngo Weinhold		4.*)
1845b0f7b1bSOliver Tappe			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
1855b0f7b1bSOliver Tappe			# compiler
1867c4641d0SOliver Tappe			HAIKU_STATIC_LIBSTDCXX=`$HAIKU_CC -print-file-name=libstdc++.a`
1877c4641d0SOliver Tappe			HAIKU_SHARED_LIBSTDCXX=`$HAIKU_CC -print-file-name=libstdc++.so`
1887c4641d0SOliver Tappe			HAIKU_STATIC_LIBSUPCXX=`$HAIKU_CC -print-file-name=libsupc++.a`
1897c4641d0SOliver Tappe			HAIKU_SHARED_LIBSUPCXX=`$HAIKU_CC -print-file-name=libsupc++.so`
19014210488SMichael Lotz
19114210488SMichael Lotz			local headers
1927c4641d0SOliver Tappe			if [ -d $gccdir/../../../../$HAIKU_GCC_MACHINE/include/c++/$HAIKU_GCC_RAW_VERSION ]; then
1937c4641d0SOliver Tappe				headers=$gccdir/../../../../$HAIKU_GCC_MACHINE/include/c++/$HAIKU_GCC_RAW_VERSION
19414210488SMichael Lotz			else
1957c4641d0SOliver Tappe				headers=$gccdir/../../../../include/c++/$HAIKU_GCC_RAW_VERSION
19614210488SMichael Lotz			fi
19714210488SMichael Lotz
1987c4641d0SOliver Tappe			HAIKU_CXX_HEADERS_DIR=$headers
1997c4641d0SOliver Tappe			for d in $HAIKU_GCC_MACHINE backward ext; do
20029ef597dSIngo Weinhold				# Note: We need the line break, otherwise the line might become
20129ef597dSIngo Weinhold				# too long for jam (512 bytes max).
2027c4641d0SOliver Tappe				HAIKU_CXX_HEADERS_DIR="$HAIKU_CXX_HEADERS_DIR
20329ef597dSIngo Weinhold					$headers/$d"
2048b5934c9SIngo Weinhold			done
205274b450aSMarcus Overhagen
2063f9f9f9aSIngo Weinhold			# Unset the HAIKU_{SHARED,STATIC}_LIB{STD,SUP}CXX variables, if the
2073f9f9f9aSIngo Weinhold			# compiler didn't give us actual file names. Otherwise resolve
2083f9f9f9aSIngo Weinhold			# symlinks to avoid problems when copying the libraries to the
2093f9f9f9aSIngo Weinhold			# image.
2108b5934c9SIngo Weinhold
2117c4641d0SOliver Tappe			if [ $HAIKU_STATIC_LIBSTDCXX = libstdc++.a ]; then
2127c4641d0SOliver Tappe				HAIKU_STATIC_LIBSTDCXX=
2133f9f9f9aSIngo Weinhold			else
214b29b48b1SMatt Madia				HAIKU_STATIC_LIBSTDCXX=`$readlink $HAIKU_STATIC_LIBSTDCXX`
2158b5934c9SIngo Weinhold			fi
2163f9f9f9aSIngo Weinhold
217ffe8b20cSIngo Weinhold			if [ $HAIKU_SHARED_LIBSTDCXX = libstdc++.so ]; then
218ffe8b20cSIngo Weinhold				HAIKU_SHARED_LIBSTDCXX=
2193f9f9f9aSIngo Weinhold			else
220b29b48b1SMatt Madia				HAIKU_SHARED_LIBSTDCXX=`$readlink $HAIKU_SHARED_LIBSTDCXX`
221ffe8b20cSIngo Weinhold			fi
2223f9f9f9aSIngo Weinhold
2237c4641d0SOliver Tappe			if [ $HAIKU_STATIC_LIBSUPCXX = libsupc++.a ]; then
2247c4641d0SOliver Tappe				HAIKU_STATIC_LIBSUPCXX=
2253f9f9f9aSIngo Weinhold			else
226b29b48b1SMatt Madia				HAIKU_STATIC_LIBSUPCXX=`$readlink $HAIKU_STATIC_LIBSUPCXX`
227c89fc875SIngo Weinhold			fi
2283f9f9f9aSIngo Weinhold
229ffe8b20cSIngo Weinhold			if [ $HAIKU_SHARED_LIBSUPCXX = libsupc++.so ]; then
230ffe8b20cSIngo Weinhold				HAIKU_SHARED_LIBSUPCXX=
2313f9f9f9aSIngo Weinhold			else
232b29b48b1SMatt Madia				HAIKU_SHARED_LIBSUPCXX=`$readlink $HAIKU_SHARED_LIBSUPCXX`
233ffe8b20cSIngo Weinhold			fi
2348b5934c9SIngo Weinhold		;;
2356cc8eecfSOliver Tappe		2.9*)
2365b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
2375b0f7b1bSOliver Tappe			# if an older one is installed
2387c4641d0SOliver Tappe			if [ $HAIKU_GCC_RAW_VERSION != $haikuRequiredLegacyGCCVersion ]; then
2395b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
2405b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
2415b0f7b1bSOliver Tappe				exit 1;
2425b0f7b1bSOliver Tappe			fi
2435b0f7b1bSOliver Tappe		;;
2448b5934c9SIngo Weinhold	esac
245*65ad1ba3SAlex Smith
246*65ad1ba3SAlex Smith	if [ "$targetArch" = "x86_64" ]; then
247*65ad1ba3SAlex Smith		HAIKU_BOOT_LIBGCC=`$HAIKU_CC -m32 -print-libgcc-file-name`
248*65ad1ba3SAlex Smith		HAIKU_BOOT_LIBSUPCXX=`$HAIKU_CC -m32 -print-file-name=libsupc++.a`
249*65ad1ba3SAlex Smith	else
250*65ad1ba3SAlex Smith		HAIKU_BOOT_LIBGCC=$HAIKU_GCC_LIBGCC
251*65ad1ba3SAlex Smith		HAIKU_BOOT_LIBSUPCXX=$HAIKU_STATIC_LIBSUPCXX
252*65ad1ba3SAlex Smith	fi
25309c5682dSIngo Weinhold}
25409c5682dSIngo Weinhold
255338b8dc3SIngo Weinhold# set_default_value
256338b8dc3SIngo Weinhold#
257338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
258338b8dc3SIngo Weinhold#
259338b8dc3SIngo Weinholdset_default_value()
260338b8dc3SIngo Weinhold{
2610838a930SJérôme Duval	eval "$1=\${$1-$2}"
262338b8dc3SIngo Weinhold}
263338b8dc3SIngo Weinhold
264338b8dc3SIngo Weinhold# get_build_tool_path
265338b8dc3SIngo Weinhold#
266338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
267338b8dc3SIngo Weinhold#
268338b8dc3SIngo Weinholdget_build_tool_path()
269338b8dc3SIngo Weinhold{
270338b8dc3SIngo Weinhold	local var="HAIKU_$1"
271338b8dc3SIngo Weinhold	local tool=$2
272338b8dc3SIngo Weinhold	local path="${crossToolsPrefix}$tool"
273338b8dc3SIngo Weinhold
274338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
275338b8dc3SIngo Weinhold		# get absolute path
276a559f87aSFrançois Revol		local oldPwd="`pwd`"
277a559f87aSFrançois Revol		cd "`dirname "$path"`"
278a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
279338b8dc3SIngo Weinhold		cd $oldPwd
280338b8dc3SIngo Weinhold	else
2817fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
282338b8dc3SIngo Weinhold			echo "Build tool \"$path\" not found." >&2
283338b8dc3SIngo Weinhold			exit 1
284338b8dc3SIngo Weinhold		}
285338b8dc3SIngo Weinhold	fi
286338b8dc3SIngo Weinhold
287338b8dc3SIngo Weinhold	eval "$var=$path"
288338b8dc3SIngo Weinhold}
289338b8dc3SIngo Weinhold
290338b8dc3SIngo Weinhold# get cwd and the source directory
291338b8dc3SIngo WeinholdcurrentDir=`pwd`
2926e7c6fe5SIngo Weinholdcd `dirname "$0"`
293338b8dc3SIngo WeinholdsourceDir=`pwd`
2946e7c6fe5SIngo Weinholdcd "$currentDir"
295338b8dc3SIngo Weinhold
29655d267a4SFrançois Revol# backup the passed arguments
29755d267a4SFrançois RevolconfigureArgs="$@"
29855d267a4SFrançois Revol
2997c4641d0SOliver Tappe# internal default parameter values
300022fa244SIngo Weinhold#
30152a38012Sejakowatzplatform=`uname`
3025abd9a46SIngo WeinholdplatformMachine=`uname  -m`
30377e84f21SIngo WeinholdtargetArch=x86
304338b8dc3SIngo WeinholdcrossToolsPrefix=
305338b8dc3SIngo WeinholdbuildCrossTools=
30629ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
30720ab75e6SIngo WeinholdbuildCrossToolsMachine=
30860d8d8fcSIngo WeinholdbuildCrossToolsJobs=
3097c4641d0SOliver Tappe
3107c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
3117c4641d0SOliver Tappe#
3127c4641d0SOliver TappeHAIKU_GCC_RAW_VERSION=
3137c4641d0SOliver TappeHAIKU_GCC_MACHINE=i586-pc-haiku
3147c4641d0SOliver TappeHAIKU_STATIC_LIBSTDCXX=
3157c4641d0SOliver TappeHAIKU_SHARED_LIBSTDCXX=
3167c4641d0SOliver TappeHAIKU_STATIC_LIBSUPCXX=
3177c4641d0SOliver TappeHAIKU_SHARED_LIBSUPCXX=
3187c4641d0SOliver TappeHAIKU_CXX_HEADERS_DIR=
3197c4641d0SOliver TappeHOST_GCC_RAW_VERSION=`gcc -dumpversion`
3207c4641d0SOliver TappeHOST_GCC_MACHINE=`gcc -dumpmachine`
3217c4641d0SOliver TappeHAIKU_INCLUDE_GPL_ADDONS=0
3227c4641d0SOliver TappeHAIKU_INCLUDE_PATENTED_CODE=0
32376fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
3247c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
3257c4641d0SOliver TappeHAIKU_ENABLE_MULTIUSER=0
3267c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
3277c4641d0SOliver TappeTARGET_PLATFORM=haiku
3287c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
3297986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
3307986925fSIngo WeinholdHAIKU_HOST_USE_XATTR=0
3317c4641d0SOliver TappeHAIKU_ALTERNATIVE_GCC_OUTPUT_DIR=
33251355c10SIngo WeinholdHAIKU_ADD_ALTERNATIVE_GCC_LIBS=0
3337c4641d0SOliver TappeHOST_GCC_LD=`gcc -print-prog-name=ld`
3347c4641d0SOliver TappeHOST_GCC_OBJCOPY=`gcc -print-prog-name=objcopy`
335c505b276SFrançois RevolSFDISK_BINARY=sfdisk
336c505b276SFrançois RevolHOST_SFDISK=$SFDISK_BINARY
337338b8dc3SIngo Weinhold
338c5101477SOliver TappehaikuRequiredLegacyGCCVersion="2.95.3-haiku-111122"
339a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
340af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
341af4bf973SOliver Tappe
342338b8dc3SIngo Weinholdset_default_value HAIKU_AR			ar
343338b8dc3SIngo Weinholdset_default_value HAIKU_CC			gcc
344338b8dc3SIngo Weinholdset_default_value HAIKU_LD			ld
345338b8dc3SIngo Weinholdset_default_value HAIKU_OBJCOPY		objcopy
346338b8dc3SIngo Weinholdset_default_value HAIKU_RANLIB		ranlib
34777e84f21SIngo Weinholdset_default_value HAIKU_YASM		yasm
348338b8dc3SIngo Weinholdset_default_value HAIKU_CPPFLAGS	""
349338b8dc3SIngo Weinholdset_default_value HAIKU_CCFLAGS		""
350338b8dc3SIngo Weinholdset_default_value HAIKU_CXXFLAGS	""
351338b8dc3SIngo Weinholdset_default_value HAIKU_LDFLAGS		""
35223eb9a9eSFrançois Revolset_default_value HAIKU_ARFLAGS		cru
353338b8dc3SIngo Weinholdset_default_value HAIKU_UNARFLAGS	x
35462339647SAxel Dörfler
3557c4641d0SOliver Tappe# determine output directory
3567c4641d0SOliver Tappeif [ "$currentDir" = "$sourceDir" ]; then
3577c4641d0SOliver Tappe	outputDir=$currentDir/generated
3587c4641d0SOliver Tappeelse
3597c4641d0SOliver Tappe	outputDir=$currentDir
3607c4641d0SOliver Tappefi
3617c4641d0SOliver TappebuildOutputDir="$outputDir/build"
3627c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
3637c4641d0SOliver TappebuildConfigFile="$buildOutputDir/BuildConfig"
3647c4641d0SOliver Tappe
3657c4641d0SOliver Tappe# check for update request
3667c4641d0SOliver Tappeif [ "$1" = "--update" ]; then
3677c4641d0SOliver Tappe	if ! [ -e "$buildConfigFile" ]; then
3687c4641d0SOliver Tappe		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
3697c4641d0SOliver Tappe		exit 1
3707c4641d0SOliver Tappe	fi
3717c4641d0SOliver Tappe	if ! type perl >/dev/null 2>&1; then
3727c4641d0SOliver Tappe		echo $0 --update: \'perl\' not found - updating not possible.
3737c4641d0SOliver Tappe		exit 1
3747c4641d0SOliver Tappe	fi
3757c4641d0SOliver Tappe	# convert BuildConfig from jam format to shell format and evaluate it
3767c4641d0SOliver Tappe	shellConfigFile="${buildConfigFile}.shell"
3777c4641d0SOliver Tappe	perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \
3787c4641d0SOliver Tappe		<"$buildConfigFile" >"$shellConfigFile"
3797c4641d0SOliver Tappe	. "$shellConfigFile"
3807c4641d0SOliver Tappe	rm "$shellConfigFile"
3817c4641d0SOliver Tappe	shift
3827c4641d0SOliver Tappefi
3837c4641d0SOliver Tappe
384022fa244SIngo Weinhold# parse parameters
385022fa244SIngo Weinhold#
38620ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
387022fa244SIngo Weinhold	case "$1" in
38860d8d8fcSIngo Weinhold		--alternative-gcc-output-dir)
38960d8d8fcSIngo Weinhold			assertparam "$1" $#
39060d8d8fcSIngo Weinhold			cd $2 || exit 1
3917c4641d0SOliver Tappe			HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR=`pwd`
3927c4641d0SOliver Tappe			HAIKU_ADD_ALTERNATIVE_GCC_LIBS=1
39360d8d8fcSIngo Weinhold			cd $currentDir
39460d8d8fcSIngo Weinhold			shift 2
39560d8d8fcSIngo Weinhold			;;
396a5b60fa8SOliver Tappe		--build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;;
3979b0dd528SIngo Weinhold		--build-cross-tools-gcc4)
3989b0dd528SIngo Weinhold			assertparams "$1" 2 $#
3999b0dd528SIngo Weinhold			buildCrossTools=$3
4009b0dd528SIngo Weinhold			buildCrossToolsScript="${buildCrossToolsScript}_gcc4"
40120ab75e6SIngo Weinhold			case "$2" in
4027c4641d0SOliver Tappe				x86)	HAIKU_GCC_MACHINE=i586-pc-haiku;;
40397901ec5SIngo Weinhold				x86_64)	HAIKU_GCC_MACHINE=x86_64-pc-haiku; targetArch=x86_64;;
4047c4641d0SOliver Tappe				ppc)	HAIKU_GCC_MACHINE=powerpc-apple-haiku; targetArch=ppc;;
4055e4d3774SJohn Scipione				m68k)	HAIKU_GCC_MACHINE=m68k-unknown-haiku; targetArch=m68k;;
4067c4641d0SOliver Tappe				arm)	HAIKU_GCC_MACHINE=arm-unknown-haiku; targetArch=arm;;
4077c4641d0SOliver Tappe				mipsel)	HAIKU_GCC_MACHINE=mipsel-unknown-haiku; targetArch=mips;;
40820ab75e6SIngo Weinhold				*)		echo "Unsupported target architecture: $2"
40920ab75e6SIngo Weinhold						exit 1;;
41020ab75e6SIngo Weinhold			esac
4117c4641d0SOliver Tappe			buildCrossToolsMachine=$HAIKU_GCC_MACHINE
4129b0dd528SIngo Weinhold			shift 3
4139b0dd528SIngo Weinhold			;;
4149b0dd528SIngo Weinhold		--cross-tools-prefix)
4159b0dd528SIngo Weinhold			assertparam "$1" $#
4169b0dd528SIngo Weinhold			crossToolsPrefix=$2
4179b0dd528SIngo Weinhold			shift 2
4189b0dd528SIngo Weinhold			;;
419a66c32ddSIngo Weinhold		--distro-compatibility)
4209b0dd528SIngo Weinhold			assertparam "$1" $#
4217c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
4227c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
423a66c32ddSIngo Weinhold				official)	;;
424a66c32ddSIngo Weinhold				compatible)	;;
425a66c32ddSIngo Weinhold				default)	;;
426a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
4277c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
428a66c32ddSIngo Weinhold							exit 1;;
429a66c32ddSIngo Weinhold			esac
4309b0dd528SIngo Weinhold			shift 2
4319b0dd528SIngo Weinhold			;;
4327c4641d0SOliver Tappe		--enable-multiuser)	HAIKU_ENABLE_MULTIUSER=1; shift 1;;
43360d8d8fcSIngo Weinhold		--help | -h)	usage; exit 0;;
4347c4641d0SOliver Tappe		--include-gpl-addons)	HAIKU_INCLUDE_GPL_ADDONS=1; shift 1;;
4357c4641d0SOliver Tappe		--include-patented-code)	HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
43676fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
4377c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
43860d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
4397c4641d0SOliver Tappe		--target=*)     TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
4407c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
4417986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
4427986925fSIngo Weinhold		--use-xattr)	HAIKU_HOST_USE_XATTR=1; shift 1;;
443022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
444022fa244SIngo Weinhold	esac
445022fa244SIngo Weinholddone
446022fa244SIngo Weinhold
4470df3cc9cSIngo Weinhold# detect the build platform
448338b8dc3SIngo Weinholdcase "${platform}" in
4490df3cc9cSIngo Weinhold	BeOS)	revision=`uname -r`
4500df3cc9cSIngo Weinhold			case "$revision" in
4517c4641d0SOliver Tappe				6.*)	HOST_PLATFORM=dano ;;
4527c4641d0SOliver Tappe				5.1)	HOST_PLATFORM=dano ;;
4537c4641d0SOliver Tappe				5.0.4)	HOST_PLATFORM=bone ;;
4547c4641d0SOliver Tappe				5.0*)	HOST_PLATFORM=r5 ;;
4550df3cc9cSIngo Weinhold				*)		echo Unknown BeOS version: $revision
4560df3cc9cSIngo Weinhold						exit 1 ;;
4570df3cc9cSIngo Weinhold			esac
4580df3cc9cSIngo Weinhold			;;
4597c4641d0SOliver Tappe	Darwin)	HOST_PLATFORM=darwin ;;
4607c4641d0SOliver Tappe	FreeBSD)	HOST_PLATFORM=freebsd
461c505b276SFrançois Revol				SFDISK_BINARY=sfdisk-linux
4627986925fSIngo Weinhold				if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
4635abd9a46SIngo Weinhold					echo Unsupported platform: FreeBSD ${platformMachine}
464308c212cSIngo Weinhold					exit 1
465308c212cSIngo Weinhold				fi	;;
4667c4641d0SOliver Tappe	Haiku)	HOST_PLATFORM=haiku_host ;;
4677c4641d0SOliver Tappe	Linux)	HOST_PLATFORM=linux ;;
4687c4641d0SOliver Tappe	OpenBSD) HOST_PLATFORM=openbsd ;;
4697c4641d0SOliver Tappe	SunOS)	HOST_PLATFORM=sunos ;;
4707c4641d0SOliver Tappe	CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
471338b8dc3SIngo Weinhold	*)		echo Unsupported platform: ${platform}
4724cbe4925SAxel Dörfler			exit 1 ;;
4734cbe4925SAxel Dörfleresac
47452a38012Sejakowatz
475c505b276SFrançois Revol# check common locations for sfdisk
476c505b276SFrançois Revolfor sfdiskDir in /sbin /usr/sbin /usr/local/sbin ; do
477c505b276SFrançois Revol	if [ -e ${sfdiskDir}/${SFDISK_BINARY} ]; then
478c505b276SFrançois Revol		HOST_SFDISK=${sfdiskDir}/${SFDISK_BINARY}
479c505b276SFrançois Revol	fi
480c505b276SFrançois Revoldone
481c505b276SFrançois Revol
4823ecc5287SMichael Lotz# check for case-sensitive filesystem if on darwin
4837c4641d0SOliver Tappeif [ $HOST_PLATFORM = "darwin" ]; then
48419d28b22SJohn Scipione	diskutil info $(pwd)/.. | grep -i "case-sensitive" > /dev/null
4853ecc5287SMichael Lotz	if [ $? != 0 ]; then
4863ecc5287SMichael Lotz		echo "You need a case-sensitive file-system to build Haiku."
4873ecc5287SMichael Lotz		echo "Please see the following guide on how to set one up:"
4883ecc5287SMichael Lotz		echo "http://haiku-os.org/documents/dev/how_to_build_haiku_on_mac_os_x"
4893ecc5287SMichael Lotz		exit 1
4903ecc5287SMichael Lotz	fi
4913ecc5287SMichael Lotzfi
4923ecc5287SMichael Lotz
493338b8dc3SIngo Weinhold# create output directory
4946e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
495338b8dc3SIngo Weinhold
496338b8dc3SIngo Weinhold# build cross tools from sources
497338b8dc3SIngo Weinholdif [ -n "$buildCrossTools" ]; then
49820ab75e6SIngo Weinhold	"$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \
49960d8d8fcSIngo Weinhold		"$buildCrossTools" "$outputDir" $buildCrossToolsJobs || exit 1
5007c4641d0SOliver Tappe	crossToolsPrefix="$outputDir/cross-tools/bin/${HAIKU_GCC_MACHINE}-"
501338b8dc3SIngo Weinholdfi
502338b8dc3SIngo Weinhold
503338b8dc3SIngo Weinhold# cross tools
504338b8dc3SIngo Weinholdif [ -n "$crossToolsPrefix" ]; then
505338b8dc3SIngo Weinhold	get_build_tool_path AR ar
506338b8dc3SIngo Weinhold	get_build_tool_path CC gcc
507338b8dc3SIngo Weinhold	get_build_tool_path LD ld
508338b8dc3SIngo Weinhold	get_build_tool_path OBJCOPY objcopy
509338b8dc3SIngo Weinhold	get_build_tool_path RANLIB ranlib
510338b8dc3SIngo Weinholdfi
511338b8dc3SIngo Weinhold
512338b8dc3SIngo Weinhold# prepare gcc settings
513338b8dc3SIngo Weinholdstandard_gcc_settings
514338b8dc3SIngo Weinhold
515eedc3d0bSIngo Weinhold# check whether the Haiku compiler really targets Haiku or BeOS
5167c4641d0SOliver Tappecase "$HAIKU_GCC_MACHINE" in
517eedc3d0bSIngo Weinhold	*-*-haiku)	;;
518eedc3d0bSIngo Weinhold	*-*-beos)	;;
519eedc3d0bSIngo Weinhold	*) echo The compiler specified as Haiku target compiler is not a valid \
520eedc3d0bSIngo Weinhold			Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
521eedc3d0bSIngo Weinhold	   echo compiler: $HAIKU_CC
5227c4641d0SOliver Tappe	   echo compiler is configured for target: $HAIKU_GCC_MACHINE
523eedc3d0bSIngo Weinhold	   exit 1 ;;
524eedc3d0bSIngo Weinholdesac
525eedc3d0bSIngo Weinhold
52652a38012Sejakowatz# Generate BuildConfig
5277c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
52852a38012Sejakowatz# BuildConfig
529ab2540c4SIngo Weinhold# Note: This file has been automatically generated by configure with the
530ab2540c4SIngo Weinhold# following arguments:
53155d267a4SFrançois Revol# ${configureArgs}
53252a38012Sejakowatz
5337c4641d0SOliver TappeTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
5347c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
535338b8dc3SIngo Weinhold
5367c4641d0SOliver TappeHAIKU_INCLUDE_GPL_ADDONS			?= "${HAIKU_INCLUDE_GPL_ADDONS}" ;
5377c4641d0SOliver TappeHAIKU_INCLUDE_PATENTED_CODE			?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
53876fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES				?= "${HAIKU_INCLUDE_SOURCES}" ;
5397c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY				?= "${HAIKU_INCLUDE_3RDPARTY}" ;
5407c4641d0SOliver TappeHAIKU_ENABLE_MULTIUSER				?= "${HAIKU_ENABLE_MULTIUSER}" ;
5417c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY			?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
5427c4641d0SOliver TappeHAIKU_USE_GCC_PIPE					?= "${HAIKU_USE_GCC_PIPE}" ;
5437986925fSIngo WeinholdHAIKU_HOST_USE_32BIT				?= "${HAIKU_HOST_USE_32BIT}" ;
5447986925fSIngo WeinholdHAIKU_HOST_USE_XATTR				?= "${HAIKU_HOST_USE_XATTR}" ;
5457c4641d0SOliver TappeHAIKU_ALTERNATIVE_GCC_OUTPUT_DIR	?= ${HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR} ;
5467c4641d0SOliver TappeHAIKU_ADD_ALTERNATIVE_GCC_LIBS		?= ${HAIKU_ADD_ALTERNATIVE_GCC_LIBS} ;
547eccc7665SIngo Weinhold
5487c4641d0SOliver TappeHAIKU_GCC_RAW_VERSION		?= ${HAIKU_GCC_RAW_VERSION} ;
5497c4641d0SOliver TappeHAIKU_GCC_MACHINE			?= ${HAIKU_GCC_MACHINE} ;
550338b8dc3SIngo WeinholdHAIKU_GCC_LIB_DIR			?= ${HAIKU_GCC_LIB_DIR} ;
551338b8dc3SIngo WeinholdHAIKU_GCC_HEADERS_DIR		?= ${HAIKU_GCC_HEADERS_DIR} ;
552338b8dc3SIngo WeinholdHAIKU_GCC_LIBGCC			?= ${HAIKU_GCC_LIBGCC} ;
553338b8dc3SIngo Weinhold
5547c4641d0SOliver TappeHAIKU_STATIC_LIBSTDC++		?= ${HAIKU_STATIC_LIBSTDCXX} ;
5557c4641d0SOliver TappeHAIKU_SHARED_LIBSTDC++		?= ${HAIKU_SHARED_LIBSTDCXX} ;
5567c4641d0SOliver TappeHAIKU_STATIC_LIBSUPC++		?= ${HAIKU_STATIC_LIBSUPCXX} ;
5577c4641d0SOliver TappeHAIKU_SHARED_LIBSUPC++		?= ${HAIKU_SHARED_LIBSUPCXX} ;
5587c4641d0SOliver TappeHAIKU_C++_HEADERS_DIR		?= ${HAIKU_CXX_HEADERS_DIR} ;
5598b5934c9SIngo Weinhold
560*65ad1ba3SAlex SmithHAIKU_BOOT_LIBGCC			?= ${HAIKU_BOOT_LIBGCC} ;
561*65ad1ba3SAlex SmithHAIKU_BOOT_LIBSUPC++		?= ${HAIKU_BOOT_LIBSUPCXX} ;
562*65ad1ba3SAlex Smith
5637c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR	?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
564338b8dc3SIngo Weinhold
565338b8dc3SIngo WeinholdHAIKU_AR					?= ${HAIKU_AR} ;
566338b8dc3SIngo WeinholdHAIKU_CC					?= ${HAIKU_CC} ;
567338b8dc3SIngo WeinholdHAIKU_LD					?= ${HAIKU_LD} ;
568338b8dc3SIngo WeinholdHAIKU_OBJCOPY				?= ${HAIKU_OBJCOPY} ;
569338b8dc3SIngo WeinholdHAIKU_RANLIB				?= ${HAIKU_RANLIB} ;
57077e84f21SIngo WeinholdHAIKU_YASM					?= ${HAIKU_YASM} ;
571338b8dc3SIngo WeinholdHAIKU_CPPFLAGS				?= ${HAIKU_CPPFLAGS} ;
572338b8dc3SIngo WeinholdHAIKU_CCFLAGS				?= ${HAIKU_CCFLAGS} ;
573338b8dc3SIngo WeinholdHAIKU_CXXFLAGS				?= ${HAIKU_CXXFLAGS} ;
574338b8dc3SIngo WeinholdHAIKU_LDFLAGS				?= ${HAIKU_LDFLAGS} ;
575338b8dc3SIngo WeinholdHAIKU_ARFLAGS				?= ${HAIKU_ARFLAGS} ;
576338b8dc3SIngo WeinholdHAIKU_UNARFLAGS				?= ${HAIKU_UNARFLAGS} ;
577338b8dc3SIngo Weinhold
5787c4641d0SOliver TappeHOST_GCC_RAW_VERSION		?= ${HOST_GCC_RAW_VERSION} ;
5797c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
5807c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
5817c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
582c505b276SFrançois RevolHOST_SFDISK					?= ${HOST_SFDISK} ;
5838b5934c9SIngo Weinhold
584c4786ea6SlilloEOF
585c4786ea6Slillo
586b1e5b60cSAxel Dörfler# Libgcc.a objects
587b1e5b60cSAxel Dörfler
5886e7c6fe5SIngo Weinholdcat << EOF > "$buildOutputDir/libgccObjects"
589b1e5b60cSAxel Dörfler# libgcc.a objects to be linked against libroot.so
590b1e5b60cSAxel Dörfler# Note: This file has been automatically generated by configure.
591b1e5b60cSAxel Dörfler
592338b8dc3SIngo WeinholdHAIKU_GCC_LIBGCC_OBJECTS	?= ${HAIKU_GCC_LIBGCC_OBJECTS} ;
593b1e5b60cSAxel DörflerEOF
594b1e5b60cSAxel Dörfler
5959b0dd528SIngo Weinhold# Generate a boot strap Jamfile in the output directory.
596338b8dc3SIngo Weinhold
597338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
598338b8dc3SIngo Weinhold# automatically generated Jamfile
599338b8dc3SIngo Weinhold
600338b8dc3SIngo WeinholdHAIKU_TOP			= ${sourceDir} ;
601338b8dc3SIngo WeinholdHAIKU_OUTPUT_DIR	= ${outputDir} ;
602338b8dc3SIngo Weinhold
603338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
604338b8dc3SIngo Weinhold
605338b8dc3SIngo WeinholdEOF
606