xref: /haiku/configure (revision 7c6ab83094f7346004bfa89e88ae6fea8097e699)
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:
15825700d3SAugustin Cavalier  --help                      Prints out this help.
16825700d3SAugustin Cavalier  --update                    Re-runs last configure invocation [must be given
17825700d3SAugustin Cavalier                              as first option!]
18e173a1ecSIngo Weinhold  --bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo>
19e173a1ecSIngo Weinhold                              Prepare for a bootstrap build. No pre-built
20e173a1ecSIngo Weinhold                              packages will be used, instead they will be built
21e173a1ecSIngo Weinhold                              from the sources (in several phases).
22e173a1ecSIngo Weinhold                              <haikuporter> is the path to the haikuporter tool
23e173a1ecSIngo Weinhold                              suitable for the host platform.
24e173a1ecSIngo Weinhold                              <HaikuPorts cross repo> is the path to a checked
25e173a1ecSIngo Weinhold                              out HaikuPorts cross-compilation repository.
26e173a1ecSIngo Weinhold                              <HaikuPorts repo> is the path to a checked out
27e173a1ecSIngo Weinhold                              HaikuPorts repository.
2814d8c772SAlexander von Gluck IV  --build-cross-tools <arch>
2914d8c772SAlexander von Gluck IV                              Assume cross compilation.
3014d8c772SAlexander von Gluck IV                              Toolchain will be compiled and placed in the
3114d8c772SAlexander von Gluck IV                              output directory under "cross-tools". The
3214d8c772SAlexander von Gluck IV                              HAIKU_* tools variables will be set accordingly.
3320ab75e6SIngo Weinhold                              <arch> specifies the target architecture, either
345bd0fbd1SAlexander von Gluck IV                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k",
35c59cde3dSAlexander von Gluck IV                              "arm", "arm64", "riscv64", "sparc"
36c0e8cc1aSIngo Weinhold                              This option and --cross-tools-prefix can be
37c0e8cc1aSIngo Weinhold                              specified multiple times. The first cross tools
38c0e8cc1aSIngo Weinhold                              specify the primary tools, the subsequent ones the
39c0e8cc1aSIngo Weinhold                              secondary tools (for "hybrid" images).
40eccc7665SIngo Weinhold  --cross-tools-prefix <prefix>
41eccc7665SIngo Weinhold                              Assume cross compilation. <prefix> should be a
42eccc7665SIngo Weinhold                              path to the directory where the cross
43eccc7665SIngo Weinhold                              compilation tools are located, plus the platform
440da9c208SIngo Weinhold                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
45eccc7665SIngo Weinhold                              This overrides the HAIKU_* tool variables.
4614d8c772SAlexander von Gluck IV  --cross-tools-source <buildtools dir>
4714d8c772SAlexander von Gluck IV                              Toolchain sources for cross compilation.
4814d8c772SAlexander von Gluck IV                              <buildtools dir> defines the location of the
4914d8c772SAlexander von Gluck IV                              buildtools sources.
50a66c32ddSIngo Weinhold  --distro-compatibility <level>
51a66c32ddSIngo Weinhold                              The distribution's level of compatibility with
52a66c32ddSIngo Weinhold                              the official Haiku distribution. The generated
53a66c32ddSIngo Weinhold                              files will contain the respective trademarks
54a66c32ddSIngo Weinhold                              accordingly.
55a66c32ddSIngo Weinhold                              official -- the official Haiku distribution.
56a66c32ddSIngo Weinhold                              compatible -- a Haiku Compatible (tm) distro.
57a66c32ddSIngo Weinhold                              default -- any other distro (default value).
582ebcd86dSIngo Weinhold  --host-only                 Configure for building tools for the build host
592ebcd86dSIngo Weinhold                              only. Haiku cannot be built when configured like
602ebcd86dSIngo Weinhold                              this.
6176fa0be3SIngo Weinhold  --include-sources           Includes the source code of projects that require
6276fa0be3SIngo Weinhold                              either an offer of source code or a copy of the
6376fa0be3SIngo Weinhold                              patched sources. This is preferable when
6476fa0be3SIngo Weinhold                              distributing on physical mediums.
651974210fSFrançois Revol  --include-3rdparty          Include 3rdparty/ in the build system.
664880ae01SJessica Hamilton  -j<n>                       Only relevant for --build-cross-tools. Is passed
674880ae01SJessica Hamilton                              on to the make building the build tools.
68aa2e5ecaSOliver Tappe  --no-downloads              Do not download anything. Useful when trying to
69aa2e5ecaSOliver Tappe                              bootstrap and build Haiku from source only.
70e9e00b80SJessica Hamilton  --sysroot                   The location of the cross-compiler sysroot,
71e9e00b80SJessica Hamilton                              primarily for CI environments or cross-compilers
72e9e00b80SJessica Hamilton                              used outside of the Haiku build system.
73483b28e4SIngo Weinhold  --target-arch <arch>        Haiku only: Specify the target architecture to
74483b28e4SIngo Weinhold                              build for. Must be one of the architectures of the
75483b28e4SIngo Weinhold                              host system. The installed build tools for that
76483b28e4SIngo Weinhold                              architecture will be used.
77483b28e4SIngo Weinhold                              This option can be specified multiple times. The
78483b28e4SIngo Weinhold                              first occurrence specifies the primary
79483b28e4SIngo Weinhold                              architecture of the Haiku to build, subsequent
80483b28e4SIngo Weinhold                              ones the secondary architectures.
81d73993ffSAugustin Cavalier  --use-clang <arch>          Build with host Clang instead of GCC cross
82d73993ffSAugustin Cavalier                              compiler, targeting <arch>
83eccc7665SIngo Weinhold  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
845a34a443SFrançois Revol                              process, but uses more memory.
85ed38d2efSJerome Duval  --use-gcc-graphite          Build with GCC Graphite engine for loop
86a5c952dbSAugustin Cavalier                              optimizations. (Only for GCC 4+.)
870385b065SIngo Weinhold  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
88fc2c93fbSAugustin Cavalier  --no-full-xattr             Do not use Linux/*BSD/Darwin's native extended file
89fc2c93fbSAugustin Cavalier                              attributes as Haiku attributes. If they are still
90fc2c93fbSAugustin Cavalier                              available, they will be used to store hashes for
91fc2c93fbSAugustin Cavalier                              the attribute emulation layer.
92fc2c93fbSAugustin Cavalier  --no-xattr                  Do not use Linux/*BSD/Darwin's native extended file
93fc2c93fbSAugustin Cavalier                              attributes for Haiku extended attributes at all,
94fc2c93fbSAugustin Cavalier                              even if they are available.
954da6cf84SFrançois Revol  --with-gdb <gdb sources dir>
964da6cf84SFrançois Revol                              specify the path to a GDB source dir, to build
974da6cf84SFrançois Revol                              GDB for each arch we build the cross-tools for.
9804be20a7SJérôme Duval  --use-stack-protector       Build with stack protection enabled
9931f27c4dSAlexander von Gluck IV  --efi-signing-key           Private keyfile to sign any EFI bootloaders
100b6554e72SJessica Hamilton  --with-python <python>      Specify python to use, instead of system
101b6554e72SJessica Hamilton                              default.
102338b8dc3SIngo Weinhold
103338b8dc3SIngo Weinholdenvironment variables:
10463701e7dSOliver Tappe  CC                          The host compiler. Defaults to "gcc".
10565706842SAugustin Cavalier  HAIKU_AR_<arch>             The static library archiver for <arch>.
106c0e8cc1aSIngo Weinhold                              Defaults to "ar".
10765706842SAugustin Cavalier  HAIKU_CC_<arch>             The compiler for <arch>. Defaults to "gcc".
10865706842SAugustin Cavalier  HAIKU_LD_<arch>             The <arch> linker. Defaults to "ld".
10965706842SAugustin Cavalier  HAIKU_OBJCOPY_<arch>        The <arch> objcopy to be used. Defaults to
110c0e8cc1aSIngo Weinhold                              "objcopy".
11165706842SAugustin Cavalier  HAIKU_RANLIB_<arch>         The static library indexer for <arch>. Defaults
112c0e8cc1aSIngo Weinhold                              to "ranlib".
11365706842SAugustin Cavalier  HAIKU_STRIP_<arch>          The <arch> strip command. Defaults to "strip".
114a04a520bSJonathan Schleifer  HAIKU_NASM                  The nasm assembler (x86 and x86_64 only).
115c0e8cc1aSIngo Weinhold  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
116c0e8cc1aSIngo Weinhold                              <arch>. Defaults to "".
117c0e8cc1aSIngo Weinhold  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
118c0e8cc1aSIngo Weinhold                              Defaults to "".
119c0e8cc1aSIngo Weinhold  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
120c0e8cc1aSIngo Weinhold                              Defaults to "".
121252e4f62SAugustin Cavalier  HAIKU_LINKFLAGS_<arch>      The flags passed to the compiler when linking for
122252e4f62SAugustin Cavalier                              target architecture <arch>. Defaults to "".
123c0e8cc1aSIngo Weinhold  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
124c0e8cc1aSIngo Weinhold                              Defaults to "".
125c0e8cc1aSIngo Weinhold  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
126c0e8cc1aSIngo Weinhold                              architecture <arch> for archiving. Defaults to
127241b61a7SAugustin Cavalier                              "cru".
128c0e8cc1aSIngo Weinhold  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
129c0e8cc1aSIngo Weinhold                              architecture <arch> for unarchiving. Defaults to
130c0e8cc1aSIngo Weinhold                              "x".
13164f6da31SIngo Weinhold
132c0e8cc1aSIngo WeinholdNon-default output directories:
13364f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
13464f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
13564f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
13664f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
13764f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
13864f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
13964f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
14064f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
14164f6da31SIngo Weinhold  non-default location and running jam.
14264f6da31SIngo Weinhold
14364f6da31SIngo Weinhold
144022fa244SIngo WeinholdEOF
145022fa244SIngo Weinhold}
146022fa244SIngo Weinhold
147022fa244SIngo Weinhold# assertparam
148022fa244SIngo Weinhold#
149022fa244SIngo Weinhold# Checks whether at least one parameter is left.
150022fa244SIngo Weinhold#
151022fa244SIngo Weinholdassertparam()
152022fa244SIngo Weinhold{
15320ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
154022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
155022fa244SIngo Weinhold		exit 1
156022fa244SIngo Weinhold	fi
157022fa244SIngo Weinhold}
158022fa244SIngo Weinhold
15920ab75e6SIngo Weinhold# assertparams
16020ab75e6SIngo Weinhold#
16120ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
16220ab75e6SIngo Weinhold#
16320ab75e6SIngo Weinholdassertparams()
16420ab75e6SIngo Weinhold{
16520ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
16620ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
16720ab75e6SIngo Weinhold		exit 1
16820ab75e6SIngo Weinhold	fi
16920ab75e6SIngo Weinhold}
17020ab75e6SIngo Weinhold
171e173a1ecSIngo Weinhold# absolute_path
172e173a1ecSIngo Weinhold#
173e173a1ecSIngo Weinhold# returns the absolute path of a given path.
174e173a1ecSIngo Weinhold#
175e173a1ecSIngo Weinholdabsolute_path()
176e173a1ecSIngo Weinhold{
1776a4f3954SFrançois Revol	if [ "x$1" != "x${1#/}" ]; then
178e173a1ecSIngo Weinhold		echo "$1"
179e173a1ecSIngo Weinhold	else
180e173a1ecSIngo Weinhold		echo "`pwd`/$1"
181e173a1ecSIngo Weinhold	fi
182e173a1ecSIngo Weinhold}
183e173a1ecSIngo Weinhold
18439d444a3SArvind S Raj# check_dir_exists
18539d444a3SArvind S Raj#
18639d444a3SArvind S Raj# check if a directory exists or not
18739d444a3SArvind S Raj#
18839d444a3SArvind S Rajcheck_dir_exists()
18939d444a3SArvind S Raj{
19039d444a3SArvind S Raj	if [ -d "$1" ]; then
19139d444a3SArvind S Raj		return 0
19239d444a3SArvind S Raj	else
19339d444a3SArvind S Raj		return 1
19439d444a3SArvind S Raj	fi
19539d444a3SArvind S Raj}
19639d444a3SArvind S Raj
197502882dbSJessica Hamilton# check_file_exists
198502882dbSJessica Hamilton#
199502882dbSJessica Hamilton# check if a file exists or not
200502882dbSJessica Hamilton#
201502882dbSJessica Hamiltoncheck_file_exists()
202502882dbSJessica Hamilton{
203502882dbSJessica Hamilton	if [ -f "$1" ]; then
204502882dbSJessica Hamilton		return 0
205502882dbSJessica Hamilton	else
206502882dbSJessica Hamilton		return 1
207502882dbSJessica Hamilton	fi
208502882dbSJessica Hamilton}
209502882dbSJessica Hamilton
2109a001156SOliver Tappe# real_path
2119a001156SOliver Tappe#
2129a001156SOliver Tappe# returns the realpath of a symbolic link.
2139a001156SOliver Tappe#
2149a001156SOliver Tappereal_path()
2159a001156SOliver Tappe{
2169a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
2179a001156SOliver Tappe}
2189a001156SOliver Tappe
2193facc270SAugustin Cavalier# relative_to
2203facc270SAugustin Cavalier#
2213facc270SAugustin Cavalier# returns $1 relative to $2
2223facc270SAugustin Cavalier#
2233facc270SAugustin Cavalierrelative_to()
2243facc270SAugustin Cavalier{
2253facc270SAugustin Cavalier	perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' \
2261d91b371SAugustin Cavalier		"$1" "$2"
2273facc270SAugustin Cavalier}
2283facc270SAugustin Cavalier
229e5d446fcSAlexander von Gluck IV# valid_toolchain
230e5d446fcSAlexander von Gluck IV#
2311f839e89Swaddlesplash# check if a toolchain is valid
232e5d446fcSAlexander von Gluck IV#
233e5d446fcSAlexander von Gluck IVvalid_toolchain()
234e5d446fcSAlexander von Gluck IV{
235e5d446fcSAlexander von Gluck IV	TRIPLET="$1"
236e5d446fcSAlexander von Gluck IV	BASE="$2"
2371f839e89Swaddlesplash	SOURCE="$3"
238e5d446fcSAlexander von Gluck IV	if [ ! -d "$BASE" ]; then
2391f839e89Swaddlesplash		return 1
240e5d446fcSAlexander von Gluck IV	fi
241e5d446fcSAlexander von Gluck IV	if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
2421f839e89Swaddlesplash		[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
2431f839e89Swaddlesplash			[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
2441f839e89Swaddlesplash		return $?
245e5d446fcSAlexander von Gluck IV	fi
2461f839e89Swaddlesplash	return 1
247e5d446fcSAlexander von Gluck IV}
248e5d446fcSAlexander von Gluck IV
24947320dd0SAugustin Cavalier# is_legacy_gcc
25047320dd0SAugustin Cavalier#
25147320dd0SAugustin Cavalier# Determines if the specified GCC version is a "legacy" (i.e. GCC < 4) one.
25247320dd0SAugustin Cavalier#
25347320dd0SAugustin Cavalieris_legacy_gcc()
25447320dd0SAugustin Cavalier{
25547320dd0SAugustin Cavalier	if [ `echo $1 | cut -d'.' -f1` -lt 4 ]; then
25647320dd0SAugustin Cavalier		echo 1
25747320dd0SAugustin Cavalier	else
25847320dd0SAugustin Cavalier		echo 0
25947320dd0SAugustin Cavalier	fi
26047320dd0SAugustin Cavalier}
26147320dd0SAugustin Cavalier
26209c5682dSIngo Weinhold# standard_gcc_settings
26309c5682dSIngo Weinhold#
26409c5682dSIngo Weinhold# Sets the variables for a GCC platform.
26509c5682dSIngo Weinhold#
26609c5682dSIngo Weinholdstandard_gcc_settings()
26709c5682dSIngo Weinhold{
26865706842SAugustin Cavalier	local gcc="$1"
269c0e8cc1aSIngo Weinhold
270138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
271b29b48b1SMatt Madia		readlink="greadlink -e"
272138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
273b29b48b1SMatt Madia		readlink=realpath
2749a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
275b29b48b1SMatt Madia		readlink="readlink -e"
2769a001156SOliver Tappe	else
2779a001156SOliver Tappe		readlink=real_path
278b4b6d83cSMatt Madia	fi
279138f5fb4SIngo Weinhold
28009c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
281c0e8cc1aSIngo Weinhold	local gcclib=`$gcc -print-libgcc-file-name`
282c0e8cc1aSIngo Weinhold	local gccdir=`dirname ${gcclib}`
2835b0f7b1bSOliver Tappe
284c0e8cc1aSIngo Weinhold	local gccRawVersion=`$gcc -dumpversion`
285c0e8cc1aSIngo Weinhold	local gccMachine=`$gcc -dumpmachine`
286338b8dc3SIngo Weinhold
287fc8967f1SIngo Weinhold	# determine architecture from machine triple
288c0e8cc1aSIngo Weinhold	case $gccMachine in
289c0e8cc1aSIngo Weinhold		arm-*)		targetCpu=arm;;
2901f52c921SJaroslaw Pelczar		aarch64-*)	targetCpu=arm64;;
291c0e8cc1aSIngo Weinhold		i?86-*)		targetCpu=x86;;
292c0e8cc1aSIngo Weinhold		m68k-*)		targetCpu=m68k;;
293c0e8cc1aSIngo Weinhold		powerpc-*)	targetCpu=ppc;;
2945bd0fbd1SAlexander von Gluck IV		riscv64-*)	targetCpu=riscv64;;
2955629675aSAdrien Destugues		sparc64-*)	targetCpu=sparc;;
296c0e8cc1aSIngo Weinhold		x86_64-*)	targetCpu=x86_64;;
297fc8967f1SIngo Weinhold		*)
298c0e8cc1aSIngo Weinhold			echo "Unsupported gcc target machine: $gccMachine" >&2
299fc8967f1SIngo Weinhold			exit 1
300fc8967f1SIngo Weinhold			;;
301fc8967f1SIngo Weinhold	esac
302fc8967f1SIngo Weinhold
303c0e8cc1aSIngo Weinhold	local targetArch=$targetCpu
304fc8967f1SIngo Weinhold
305c0e8cc1aSIngo Weinhold	case $gccRawVersion in
3066cc8eecfSOliver Tappe		2.9*)
3075b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
3085b0f7b1bSOliver Tappe			# if an older one is installed
309c0e8cc1aSIngo Weinhold			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
3105b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
3115b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
3125b0f7b1bSOliver Tappe				exit 1;
3135b0f7b1bSOliver Tappe			fi
314aaeadfcbSAlex Smith
315c0e8cc1aSIngo Weinhold			targetArch=x86_gcc2
3165b0f7b1bSOliver Tappe			;;
3178b5934c9SIngo Weinhold	esac
31865ad1ba3SAlex Smith
319c0e8cc1aSIngo Weinhold	local bootLibgcc
320c0e8cc1aSIngo Weinhold	local bootLibSupCxx
32166a7f29fSJérôme Duval	local bootCxxHeaders
3224df4b48fSJérôme Duval	local boot32Libgcc
3234df4b48fSJérôme Duval	local boot32LibSupCxx
3244df4b48fSJérôme Duval	local boot32CxxHeaders
325c0e8cc1aSIngo Weinhold	case $gccMachine in
3264591ebc9SAlex Smith		x86_64-*)
32766a7f29fSJérôme Duval			# Boot loader is 32-bit, need the 32-bit libs and c++ config
3284df4b48fSJérôme Duval			boot32Libgcc=`$gcc -m32 -print-file-name=libgcc.a`
3294df4b48fSJérôme Duval			boot32LibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
3304df4b48fSJérôme Duval			bootLibgcc=`$gcc -print-file-name=libgcc.a`
3314df4b48fSJérôme Duval			bootLibSupCxx=`$gcc -print-file-name=libsupc++.a`
33266a7f29fSJérôme Duval
33366a7f29fSJérôme Duval			local headersBase=$gccdir/../../../..
33466a7f29fSJérôme Duval			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
33566a7f29fSJérôme Duval			if [ ! -d $headers ]; then
33666a7f29fSJérôme Duval				headers=$headersBase/include/c++/$gccRawVersion
33766a7f29fSJérôme Duval			fi
3384df4b48fSJérôme Duval			boot32CxxHeaders="$headers/$gccMachine/32"
3394df4b48fSJérôme Duval			bootCxxHeaders="$headers/$gccMachine"
3404591ebc9SAlex Smith			;;
341338b8dc3SIngo Weinhold	esac
342c0e8cc1aSIngo Weinhold
343c0e8cc1aSIngo Weinhold	# determine whether graphite loop optimization should/can be used
344c0e8cc1aSIngo Weinhold	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
345c0e8cc1aSIngo Weinhold	if [ -z "$useGraphite" ]; then
346c0e8cc1aSIngo Weinhold		useGraphite=$useGccGraphiteDefault
347c0e8cc1aSIngo Weinhold	fi
348c0e8cc1aSIngo Weinhold
349c0e8cc1aSIngo Weinhold	if [ "$useGraphite" != 0 ]; then
350c0e8cc1aSIngo Weinhold		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
351c0e8cc1aSIngo Weinhold		if [ $? != 0 ]; then
352c0e8cc1aSIngo Weinhold			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
353c0e8cc1aSIngo Weinhold			useGraphite=0
354c0e8cc1aSIngo Weinhold		fi
355c0e8cc1aSIngo Weinhold	fi
356c0e8cc1aSIngo Weinhold
357c0e8cc1aSIngo Weinhold	set_variable HAIKU_CPU_$targetArch $targetCpu
358c0e8cc1aSIngo Weinhold
359c0e8cc1aSIngo Weinhold	get_build_tool_path CC_$targetArch "$gcc"
36047320dd0SAugustin Cavalier	set_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch \
36147320dd0SAugustin Cavalier		`is_legacy_gcc $gccRawVersion`
362a7bddff1SJonathan Schleifer	set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
363c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
364c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
36566a7f29fSJérôme Duval	set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
36611ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
36711ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
3684df4b48fSJérôme Duval	set_variable HAIKU_BOOT_32_CXX_HEADERS_DIR_$targetArch "$boot32CxxHeaders"
3694df4b48fSJérôme Duval	set_variable HAIKU_BOOT_32_LIBSUPCXX_$targetArch "$boot32LibSupCxx"
3704df4b48fSJérôme Duval	set_variable HAIKU_BOOT_32_LIBGCC_$targetArch $boot32Libgcc
371c0e8cc1aSIngo Weinhold	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
372c0e8cc1aSIngo Weinhold
373c0e8cc1aSIngo Weinhold	standard_gcc_settings_targetArch=$targetArch
374c0e8cc1aSIngo Weinhold}
375c0e8cc1aSIngo Weinhold
376c0e8cc1aSIngo Weinhold# set_variable
377c0e8cc1aSIngo Weinhold#
378c0e8cc1aSIngo Weinhold# Set the value of a variable.
379c0e8cc1aSIngo Weinhold#
380c0e8cc1aSIngo Weinholdset_variable()
381c0e8cc1aSIngo Weinhold{
382c0e8cc1aSIngo Weinhold	eval "$1=\"$2\""
383c0e8cc1aSIngo Weinhold}
384c0e8cc1aSIngo Weinhold
385c0e8cc1aSIngo Weinhold# get_variable
386c0e8cc1aSIngo Weinhold#
387c0e8cc1aSIngo Weinhold# Echo the value of a variable.
388c0e8cc1aSIngo Weinhold#
389c0e8cc1aSIngo Weinholdget_variable()
390c0e8cc1aSIngo Weinhold{
391c0e8cc1aSIngo Weinhold	eval "echo \${$1}"
39209c5682dSIngo Weinhold}
39309c5682dSIngo Weinhold
394338b8dc3SIngo Weinhold# set_default_value
395338b8dc3SIngo Weinhold#
396338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
397338b8dc3SIngo Weinhold#
398338b8dc3SIngo Weinholdset_default_value()
399338b8dc3SIngo Weinhold{
4000838a930SJérôme Duval	eval "$1=\${$1-$2}"
401338b8dc3SIngo Weinhold}
402338b8dc3SIngo Weinhold
403338b8dc3SIngo Weinhold# get_build_tool_path
404338b8dc3SIngo Weinhold#
405338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
406338b8dc3SIngo Weinhold#
407338b8dc3SIngo Weinholdget_build_tool_path()
408338b8dc3SIngo Weinhold{
409338b8dc3SIngo Weinhold	local var="HAIKU_$1"
41065706842SAugustin Cavalier	local varval="`get_variable $var`"
41165706842SAugustin Cavalier	local cmd="$2"
412d73993ffSAugustin Cavalier
413e042a53bSAugustin Cavalier	if [ ! -z "$varval" ]; then
414d73993ffSAugustin Cavalier		# this variable is already set (probably by user) so grab its contents
415e042a53bSAugustin Cavalier		cmd=$varval
416d73993ffSAugustin Cavalier	fi
417d73993ffSAugustin Cavalier
418d73993ffSAugustin Cavalier	local path=${cmd%% *}
419338b8dc3SIngo Weinhold
420338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
42165706842SAugustin Cavalier		# get absolute path from relative path
422a559f87aSFrançois Revol		local oldPwd="`pwd`"
423a559f87aSFrançois Revol		cd "`dirname "$path"`"
424a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
425338b8dc3SIngo Weinhold		cd $oldPwd
426338b8dc3SIngo Weinhold	else
4277fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
428d73993ffSAugustin Cavalier			echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
429338b8dc3SIngo Weinhold			exit 1
430338b8dc3SIngo Weinhold		}
431338b8dc3SIngo Weinhold	fi
432338b8dc3SIngo Weinhold
43365706842SAugustin Cavalier	if test "${cmd#* }" != "$cmd"; then
43465706842SAugustin Cavalier		# $cmd contains arguments, so preserve them (and only them)
43565706842SAugustin Cavalier		cmd=${cmd#* }
43665706842SAugustin Cavalier	else
43765706842SAugustin Cavalier		# $cmd does not contain arguments, so unset it
43865706842SAugustin Cavalier		cmd=
43965706842SAugustin Cavalier	fi
44065706842SAugustin Cavalier	eval "$var=\"$path $cmd\""
441338b8dc3SIngo Weinhold}
442338b8dc3SIngo Weinhold
443a5c952dbSAugustin Cavalier# check_native_xattrs
444a5c952dbSAugustin Cavalier#
445a5c952dbSAugustin Cavalier# Checks the host platform's support for extended attributes.
446a5c952dbSAugustin Cavalier# 0: no support, 1: only enough for xattr-ref, 2: full support
447a5c952dbSAugustin Cavalier#
448a5c952dbSAugustin Cavaliercheck_native_xattrs()
449a5c952dbSAugustin Cavalier{
450a5c952dbSAugustin Cavalier	local xattr_set=
451a5c952dbSAugustin Cavalier	local xattr_set_args=
452a5c952dbSAugustin Cavalier	local xattr_get=
453a5c952dbSAugustin Cavalier	local xattr_get_args=
454a5c952dbSAugustin Cavalier	case $HOST_PLATFORM in
455503ef6d4SAugustin Cavalier		haiku_host)
456503ef6d4SAugustin Cavalier			xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
457503ef6d4SAugustin Cavalier			xattr_get="catattr"; xattr_get_args="\$NAME"
458503ef6d4SAugustin Cavalier			;;
459a5c952dbSAugustin Cavalier		darwin)
460a5c952dbSAugustin Cavalier			xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
461a5c952dbSAugustin Cavalier			xattr_get="xattr"; xattr_get_args="-p \$NAME"
462a5c952dbSAugustin Cavalier			;;
463a5c952dbSAugustin Cavalier		freebsd)
464a5c952dbSAugustin Cavalier			xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
465a5c952dbSAugustin Cavalier			xattr_get="getextattr"; xattr_get_args="user \$NAME"
466a5c952dbSAugustin Cavalier			;;
467f6381021SAugustin Cavalier		linux)
468a5c952dbSAugustin Cavalier			xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
469a5c952dbSAugustin Cavalier			xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
470a5c952dbSAugustin Cavalier			;;
471a5c952dbSAugustin Cavalier		*)
472a5c952dbSAugustin Cavalier			return 0
473a5c952dbSAugustin Cavalier			;;
474a5c952dbSAugustin Cavalier	esac
475a5c952dbSAugustin Cavalier	if ! type $xattr_set >/dev/null 2>&1; then
476a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_set, assuming host has no extended attributes"
477a5c952dbSAugustin Cavalier		return 0
478a5c952dbSAugustin Cavalier	elif ! type $xattr_get >/dev/null 2>&1; then
479a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_get, assuming host has no extended attributes"
480a5c952dbSAugustin Cavalier		return 0
481a5c952dbSAugustin Cavalier	fi
482a5c952dbSAugustin Cavalier
48343f5f35aSAugustin Cavalier	mkdir -p "$outputDir"
484a5c952dbSAugustin Cavalier	echo "xattr test file" >"$outputDir/xattrtest"
485a5c952dbSAugustin Cavalier	local i=0
486a5c952dbSAugustin Cavalier	# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
487a5c952dbSAugustin Cavalier	# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
488a5c952dbSAugustin Cavalier	while [ $i -lt 2 ]; do
489a5c952dbSAugustin Cavalier		local j=0
490a5c952dbSAugustin Cavalier		while [ $j -lt 3 ]; do
491a5c952dbSAugustin Cavalier			NAME=attr$j
492a5c952dbSAugustin Cavalier			VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
493a5c952dbSAugustin Cavalier			if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
494a5c952dbSAugustin Cavalier				echo "$0: warning: could not generate test data for extended attributes"
495a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
496a5c952dbSAugustin Cavalier				return $i
497a5c952dbSAugustin Cavalier			elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
498a5c952dbSAugustin Cavalier					"$outputDir/xattrtest" >/dev/null 2>&1 ; then
499a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
500a5c952dbSAugustin Cavalier				return $i
501a5c952dbSAugustin Cavalier			fi
502a5c952dbSAugustin Cavalier			j=$((j+1))
503a5c952dbSAugustin Cavalier		done
504a5c952dbSAugustin Cavalier		i=$((i+1))
505a5c952dbSAugustin Cavalier	done
506a5c952dbSAugustin Cavalier	rm "$outputDir/xattrtest"
507a5c952dbSAugustin Cavalier	return 2
508a5c952dbSAugustin Cavalier}
509a5c952dbSAugustin Cavalier
510483b28e4SIngo Weinholdis_in_list()
511483b28e4SIngo Weinhold{
512483b28e4SIngo Weinhold	local element
513483b28e4SIngo Weinhold	for element in $2; do
514483b28e4SIngo Weinhold		if [ "$1" = "$element" ]; then
515483b28e4SIngo Weinhold			return 0
516483b28e4SIngo Weinhold		fi
517483b28e4SIngo Weinhold	done
518483b28e4SIngo Weinhold	return 1
519483b28e4SIngo Weinhold}
520483b28e4SIngo Weinhold
5217f9beaf1SOliver Tappe# check for --help or -h and show usage immediately
5227f9beaf1SOliver Tappeif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
5238b420c2fSOliver Tappe	usage; exit 0;
5248b420c2fSOliver Tappefi
5258b420c2fSOliver Tappe
526338b8dc3SIngo Weinhold# get cwd and the source directory
527338b8dc3SIngo WeinholdcurrentDir=`pwd`
5286e7c6fe5SIngo Weinholdcd `dirname "$0"`
529338b8dc3SIngo WeinholdsourceDir=`pwd`
5306e7c6fe5SIngo Weinholdcd "$currentDir"
531338b8dc3SIngo Weinhold
532a107d3b4SAugustin Cavalier# determine output directory
533a107d3b4SAugustin Cavalierif [ "$currentDir" = "$sourceDir" ]; then
534a107d3b4SAugustin Cavalier	outputDir=$currentDir/generated
535a107d3b4SAugustin Cavalierelse
536a107d3b4SAugustin Cavalier	outputDir=$currentDir
537a107d3b4SAugustin Cavalierfi
538a107d3b4SAugustin CavalierbuildOutputDir="$outputDir/build"
539a107d3b4SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
540a107d3b4SAugustin CavalierbuildConfigFile="$buildOutputDir/BuildConfig"
541a107d3b4SAugustin Cavalier
542a107d3b4SAugustin Cavalier# check for update request
543a107d3b4SAugustin Cavalierif [ "$1" = "--update" ]; then
544a107d3b4SAugustin Cavalier	if ! [ -e "$buildConfigFile" ]; then
545a107d3b4SAugustin Cavalier		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
546a107d3b4SAugustin Cavalier		exit 1
547a107d3b4SAugustin Cavalier	fi
548a107d3b4SAugustin Cavalier	# get last configure invocation and flags from BuildConfig and call ourselves with it
549a107d3b4SAugustin Cavalier	lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
550a107d3b4SAugustin Cavalier	lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
551a107d3b4SAugustin Cavalier	lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
552a107d3b4SAugustin Cavalier	lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
553a107d3b4SAugustin Cavalier	if [ -z "$lastConfig" ]; then
554a107d3b4SAugustin Cavalier		echo "$0 --update: The previous configure invocation was not properly" \
555a107d3b4SAugustin Cavalier			"encoded into '$buildConfigFile' - updating not possible."
556a107d3b4SAugustin Cavalier		exit 1
557a107d3b4SAugustin Cavalier	fi
5581d91b371SAugustin Cavalier	cd "$lastPwd"
559a107d3b4SAugustin Cavalier	if [ -n "$lastEnv" ]; then
560a107d3b4SAugustin Cavalier		export $lastEnv
561a107d3b4SAugustin Cavalier	fi
562a107d3b4SAugustin Cavalier	$lastConfig $lastArgs
563a107d3b4SAugustin Cavalier	exit $?
564a107d3b4SAugustin Cavalierfi
565a107d3b4SAugustin Cavalier
56655d267a4SFrançois Revol# backup the passed arguments
56755d267a4SFrançois RevolconfigureArgs="$@"
568825700d3SAugustin CavalierconfigurePath=$0
5696f582441SKacper KasperconfigureDir=`dirname $configurePath`
570825700d3SAugustin Cavalier
571825700d3SAugustin Cavalier# backup relevant environs
572825700d3SAugustin CavalierconfigureEnvirons=
573825700d3SAugustin Cavalierfor var in `env`; do
574825700d3SAugustin Cavalier	case "$var" in
5757d72ed01SAugustin Cavalier		CC\=*|HAIKU*\=*|JAMSHELL\=*)
576825700d3SAugustin Cavalier			configureEnvirons="$configureEnvirons $var"
577825700d3SAugustin Cavalier			;;
578825700d3SAugustin Cavalier	esac
579825700d3SAugustin Cavalierdone
58055d267a4SFrançois Revol
581a107d3b4SAugustin Cavalier# ensure umask is not too restrictive
58202f3646aSAugustin Cavalierif [ `umask` -gt 22 ]; then
58302f3646aSAugustin Cavalier	echo Your umask is too restrictive "(should be <= 0022;" is actually `umask`")"
58402f3646aSAugustin Cavalier	echo
58502f3646aSAugustin Cavalier	echo Additionally, if the source tree was cloned with a too-restrictive umask,
58602f3646aSAugustin Cavalier	echo you will need to run \"git checkout\" again to fix this.
587a107d3b4SAugustin Cavalier	exit 1
588a107d3b4SAugustin Cavalierfi
589a107d3b4SAugustin Cavalier
5907c4641d0SOliver Tappe# internal default parameter values
591022fa244SIngo Weinhold#
59252a38012Sejakowatzplatform=`uname`
5935abd9a46SIngo WeinholdplatformMachine=`uname  -m`
594c0e8cc1aSIngo WeinholdtargetArchs=
595338b8dc3SIngo WeinholdbuildCrossTools=
59629ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
59760d8d8fcSIngo WeinholdbuildCrossToolsJobs=
598c2b76f7fSJonathan SchleiferuseClang=0
599c0e8cc1aSIngo WeinholduseGccGraphiteDefault=0
600c0e8cc1aSIngo WeinholdunknownArchIndex=1
601483b28e4SIngo WeinholdhaikuTargetArchs=
6024da6cf84SFrançois RevolgdbSources=
6037c4641d0SOliver Tappe
60463701e7dSOliver Tappeif [ -z "$CC" ]; then
60563701e7dSOliver Tappe	CC=gcc
60663701e7dSOliver Tappefi
6070bbef5d7SAugustin Cavalierif [ $(is_legacy_gcc $($CC -dumpversion)) -ne 0 ]; then
6080bbef5d7SAugustin Cavalier	echo The host tools cannot be built with a legacy version of GCC.
6090bbef5d7SAugustin Cavalier	echo Please specify a more modern compiler in the "CC" environ.
6100bbef5d7SAugustin Cavalier	exit 1
6110bbef5d7SAugustin Cavalierfi
61263701e7dSOliver Tappe
6132a1cc90eSJohn Scipione# detect the build platform
6142a1cc90eSJohn Scipionecase "${platform}" in
6152a1cc90eSJohn Scipione	Darwin)  HOST_PLATFORM=darwin ;;
6162a1cc90eSJohn Scipione	FreeBSD) HOST_PLATFORM=freebsd
6172a1cc90eSJohn Scipione	         if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
6182a1cc90eSJohn Scipione	         	echo Unsupported platform: FreeBSD ${platformMachine}
6192a1cc90eSJohn Scipione	         	exit 1
6202a1cc90eSJohn Scipione	         fi ;;
6212a1cc90eSJohn Scipione	Haiku)   HOST_PLATFORM=haiku_host ;;
6222a1cc90eSJohn Scipione	Linux)   HOST_PLATFORM=linux ;;
6232a1cc90eSJohn Scipione	OpenBSD) HOST_PLATFORM=openbsd ;;
6242a1cc90eSJohn Scipione	*)       echo Unsupported platform: ${platform}
6252a1cc90eSJohn Scipione	         exit 1 ;;
6262a1cc90eSJohn Scipioneesac
6272a1cc90eSJohn Scipione
6282a1cc90eSJohn Scipionecase $HOST_PLATFORM in
6292a1cc90eSJohn Scipione	darwin|freebsd|openbsd) statCmd='stat -f' ;;
6302a1cc90eSJohn Scipione	*)                      statCmd='stat -c' ;;
6312a1cc90eSJohn Scipioneesac
6322a1cc90eSJohn Scipione
6332a1cc90eSJohn Scipione# ensure git checkout was not done with a restrictive umask
6342a1cc90eSJohn Scipioneif [ `$statCmd '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
6352a1cc90eSJohn Scipione	echo "The source tree was cloned with a umask > 0022. It seems you"
6362a1cc90eSJohn Scipione	echo have already corrected your umask, but not re-checked-out the
6372a1cc90eSJohn Scipione	echo source tree. Try running:
6382a1cc90eSJohn Scipione	echo "	git checkout --force"
6392a1cc90eSJohn Scipione	echo to fix this problem.
6402a1cc90eSJohn Scipione	exit 1
6412a1cc90eSJohn Scipionefi
6422a1cc90eSJohn Scipione
6437c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
6447c4641d0SOliver Tappe#
6456f582441SKacper KasperGIT_DIR=`git -C "$configureDir" rev-parse --git-dir | sed 's/^gitdir: //'`
64663701e7dSOliver TappeHOST_GCC_MACHINE=`$CC -dumpmachine`
64776fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
6487c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
6497c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
6507c4641d0SOliver TappeTARGET_PLATFORM=haiku
6517c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
6527986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
653fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR=
654fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR_REF=
6552ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY=0
656f04f7042SNiels Sascha ReedijkHOST_EXTENDED_REGEX_SED="sed -r"
65763701e7dSOliver TappeHOST_GCC_LD=`$CC -print-prog-name=ld`
65863701e7dSOliver TappeHOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
6592a5d0aafSIngo WeinholdHOST_SHA256=
660e173a1ecSIngo WeinholdHOST_HAIKU_PORTER=
661e173a1ecSIngo WeinholdHAIKU_PORTS=
662e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS=
663c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP=0
664aa2e5ecaSOliver TappeHAIKU_NO_DOWNLOADS=0
6652a5d0aafSIngo Weinhold
666c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS=
667c0e8cc1aSIngo Weinhold
668a04a520bSJonathan Schleiferset_default_value HAIKU_NASM		nasm
669c0e8cc1aSIngo Weinhold
6703942ca0dSIngo Weinholdif sha256sum < /dev/null > /dev/null 2>&1; then
6712a5d0aafSIngo Weinhold	HOST_SHA256=sha256sum
6723942ca0dSIngo Weinholdelif sha256 < /dev/null > /dev/null 2>&1; then
6732a5d0aafSIngo Weinhold	HOST_SHA256="sha256 -q"
674b5a871b1SNiels Sascha Reedijkelif shasum < /dev/null > /dev/null 2>&1; then
675b5a871b1SNiels Sascha Reedijk	HOST_SHA256="shasum -a 256"
6762a5d0aafSIngo Weinholdelse
6772a5d0aafSIngo Weinhold	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
6782a5d0aafSIngo Weinhold	exit 1
6792a5d0aafSIngo Weinholdfi
680338b8dc3SIngo Weinhold
68184edb1a1SAxel DörflerhaikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
682a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
683af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
684483b28e4SIngo WeinholdsupportedTargetArchs="
685483b28e4SIngo Weinhold	arm
686fb4cc984SAugustin Cavalier	arm64
687483b28e4SIngo Weinhold	m68k
688483b28e4SIngo Weinhold	ppc
6895bd0fbd1SAlexander von Gluck IV	riscv64
690f23db0edSPulkoMandy	sparc
691483b28e4SIngo Weinhold	x86
692483b28e4SIngo Weinhold	x86_64
693483b28e4SIngo Weinhold	x86_gcc2
694483b28e4SIngo Weinhold	"
695af4bf973SOliver Tappe
696022fa244SIngo Weinhold# parse parameters
697022fa244SIngo Weinhold#
69820ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
699022fa244SIngo Weinhold	case "$1" in
700e9e00b80SJessica Hamilton		--sysroot)
701e9e00b80SJessica Hamilton			assertparam "$1" $#
702e9e00b80SJessica Hamilton			crossToolsSysroot=$2
703e9e00b80SJessica Hamilton			shift 2
704e9e00b80SJessica Hamilton			;;
705e173a1ecSIngo Weinhold		--bootstrap)
706e173a1ecSIngo Weinhold			assertparams "$1" 3 $#
707e173a1ecSIngo Weinhold			HOST_HAIKU_PORTER="`absolute_path $2`"
708e173a1ecSIngo Weinhold			HAIKU_PORTS_CROSS="`absolute_path $3`"
709e173a1ecSIngo Weinhold			HAIKU_PORTS="`absolute_path $4`"
710c9dd05ffSJonathan Schleifer			HAIKU_IS_BOOTSTRAP=1
711c9dd05ffSJonathan Schleifer			HAIKU_NO_DOWNLOADS=1
712502882dbSJessica Hamilton			check_file_exists "$HOST_HAIKU_PORTER" || (
713502882dbSJessica Hamilton				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
71439d444a3SArvind S Raj				exit 1
71539d444a3SArvind S Raj			)
71639d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS" || (
71739d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS" >&2
71839d444a3SArvind S Raj				exit 1
71939d444a3SArvind S Raj			)
72039d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS_CROSS" || (
72139d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
72239d444a3SArvind S Raj				exit 1
72339d444a3SArvind S Raj			)
724e173a1ecSIngo Weinhold			shift 4
725e173a1ecSIngo Weinhold			;;
72614d8c772SAlexander von Gluck IV		--cross-tools-source)
72714d8c772SAlexander von Gluck IV			assertparam "$1" $#
72814d8c772SAlexander von Gluck IV			buildCrossTools=$2
72914d8c772SAlexander von Gluck IV			shift 2
73014d8c772SAlexander von Gluck IV			;;
731c0e8cc1aSIngo Weinhold		--build-cross-tools)
732c0e8cc1aSIngo Weinhold			assertparam "$1" $#
733c0e8cc1aSIngo Weinhold			targetArch=$2
734c0e8cc1aSIngo Weinhold			shift 2
735c0e8cc1aSIngo Weinhold			case "$targetArch" in
736c0e8cc1aSIngo Weinhold				x86_gcc2)	targetMachine=i586-pc-haiku;;
737c0e8cc1aSIngo Weinhold				x86)		targetMachine=i586-pc-haiku;;
738c0e8cc1aSIngo Weinhold				x86_64)		targetMachine=x86_64-unknown-haiku;;
739c0e8cc1aSIngo Weinhold				ppc)		targetMachine=powerpc-apple-haiku;;
740c0e8cc1aSIngo Weinhold				m68k)		targetMachine=m68k-unknown-haiku;;
741c0e8cc1aSIngo Weinhold				arm)		targetMachine=arm-unknown-haiku;;
7421f52c921SJaroslaw Pelczar				arm64)		targetMachine=aarch64-unknown-haiku;;
7435bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
7445629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
745c0e8cc1aSIngo Weinhold				*)
746101564e4SAugustin Cavalier					echo "Unsupported target architecture: $targetArch" >&2
747c0e8cc1aSIngo Weinhold					exit 1
748c0e8cc1aSIngo Weinhold					;;
749c0e8cc1aSIngo Weinhold			esac
750c0e8cc1aSIngo Weinhold			set_variable buildCrossToolsMachine_$targetArch $targetMachine
751c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
7529b0dd528SIngo Weinhold			;;
7539b0dd528SIngo Weinhold		--cross-tools-prefix)
7549b0dd528SIngo Weinhold			assertparam "$1" $#
755c0e8cc1aSIngo Weinhold			targetArch=unknown${unknownArchIndex}
756c0e8cc1aSIngo Weinhold			set_variable crossToolsPrefix_$targetArch "$2"
757c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
758d68208faSMatt Madia			unknownArchIndex=$(($unknownArchIndex + 1))
7599b0dd528SIngo Weinhold			shift 2
7609b0dd528SIngo Weinhold			;;
761a66c32ddSIngo Weinhold		--distro-compatibility)
7629b0dd528SIngo Weinhold			assertparam "$1" $#
7637c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
7647c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
765a66c32ddSIngo Weinhold				official)	;;
766a66c32ddSIngo Weinhold				compatible)	;;
767a66c32ddSIngo Weinhold				default)	;;
768a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
7697c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
770a66c32ddSIngo Weinhold							exit 1;;
771a66c32ddSIngo Weinhold			esac
7729b0dd528SIngo Weinhold			shift 2
7739b0dd528SIngo Weinhold			;;
7742ebcd86dSIngo Weinhold		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
77576fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
7767c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
77760d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
778aa2e5ecaSOliver Tappe		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
779483b28e4SIngo Weinhold		--target-arch)
780483b28e4SIngo Weinhold			assertparam "$1" $#
781483b28e4SIngo Weinhold			targetArch=$2
782483b28e4SIngo Weinhold			shift 2
783483b28e4SIngo Weinhold			if [ ! "$platform" = Haiku ]; then
784483b28e4SIngo Weinhold				echo "--target-arch can only be specified on Haiku." >&2
785483b28e4SIngo Weinhold				exit 1
786483b28e4SIngo Weinhold			fi
787483b28e4SIngo Weinhold			is_in_list "$targetArch" "$supportedTargetArchs" || (
788483b28e4SIngo Weinhold				echo "Unsupported target architecture: \"$targetArch\"" >&2
789483b28e4SIngo Weinhold				exit 1
790483b28e4SIngo Weinhold			)
791483b28e4SIngo Weinhold			haikuTargetArchs="$haikuTargetArchs $targetArch"
792483b28e4SIngo Weinhold			;;
793d73993ffSAugustin Cavalier		--use-clang)
794d73993ffSAugustin Cavalier			assertparam "$1" $#
795d73993ffSAugustin Cavalier			targetArch=$2
796d73993ffSAugustin Cavalier			useClang=1
797d73993ffSAugustin Cavalier			case "$targetArch" in
798d73993ffSAugustin Cavalier				x86)		targetMachine=i586-pc-haiku;;
799d73993ffSAugustin Cavalier				x86_64)		targetMachine=x86_64-unknown-haiku;;
800d9f698eaSAugustin Cavalier				ppc)		targetMachine=powerpc-apple-haiku;;
80120dbf032SAlexander von Gluck IV				arm)		targetMachine=arm-unknown-haiku;;
8021f52c921SJaroslaw Pelczar				arm64)		targetMachine=aarch64-unknown-haiku;;
8035bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
8045629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
805d73993ffSAugustin Cavalier				*)
806d73993ffSAugustin Cavalier					echo "Unsupported target architecture: $2" >&2
807d73993ffSAugustin Cavalier					exit 1
808d73993ffSAugustin Cavalier					;;
809d73993ffSAugustin Cavalier			esac
81065706842SAugustin Cavalier			get_build_tool_path clang clang
81136f28382SAugustin Cavalier			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
81236f28382SAugustin Cavalier					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
81365706842SAugustin Cavalier				set_variable crossToolsPrefix_$targetArch llvm-
81465706842SAugustin Cavalier			fi
8155924b6e4SAugustin Cavalier			clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
816583db6f5SAlexander von Gluck IV			if [ `echo $clangVersion | cut -d'.' -f1` -lt 7 ]; then
8175924b6e4SAugustin Cavalier				echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
8185924b6e4SAugustin Cavalier				echo "Please install a newer version."
8195924b6e4SAugustin Cavalier				exit 1
8205924b6e4SAugustin Cavalier			fi
821d73993ffSAugustin Cavalier			targetArchs="$targetArchs $targetArch"
822d73993ffSAugustin Cavalier			shift 2
823d73993ffSAugustin Cavalier			;;
8247c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
825c0e8cc1aSIngo Weinhold		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
8267986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
827fc2c93fbSAugustin Cavalier		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
828fc2c93fbSAugustin Cavalier		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
8294da6cf84SFrançois Revol		--with-gdb)	gdbSources=$2; shift 2;;
83004be20a7SJérôme Duval		--use-stack-protector)	HAIKU_USE_STACK_PROTECTOR=1; shift 1;;
83131f27c4dSAlexander von Gluck IV		--efi-signing-key)
83231f27c4dSAlexander von Gluck IV			assertparam "$1" $#
83331f27c4dSAlexander von Gluck IV			HAIKU_EFI_SIGNING_KEY="$2"
83431f27c4dSAlexander von Gluck IV			shift 2
83531f27c4dSAlexander von Gluck IV			;;
836b6554e72SJessica Hamilton		--with-python)	pythonPath=$2; shift 2;;
837022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
838022fa244SIngo Weinhold	esac
839022fa244SIngo Weinholddone
840022fa244SIngo Weinhold
8410962132cSAlex Smith# check for case-sensitive filesystem
8420962132cSAlex Smithmkdir haikuCaseTest 2>/dev/null
8430962132cSAlex Smithmkdir haikucasetest 2>/dev/null
8440962132cSAlex SmithcaseInsensitive=$?
84597f5a0bdSAlex Smithrmdir haikuCaseTest haikucasetest 2>/dev/null
8460962132cSAlex Smithif [ $caseInsensitive != 0 ]; then
8473ecc5287SMichael Lotz	echo "You need a case-sensitive file-system to build Haiku."
8480962132cSAlex Smith	if [ $HOST_PLATFORM = "darwin" ]; then
8497a05e252SJohn Scipione		echo "You can create a case-sensitive disk image using Disk Utility."
8503ecc5287SMichael Lotz	fi
8510962132cSAlex Smith	exit 1
8523ecc5287SMichael Lotzfi
8533ecc5287SMichael Lotz
854a5c952dbSAugustin Cavalier# check xattr support
855503ef6d4SAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
856a5c952dbSAugustin Cavalier	check_native_xattrs
857a5c952dbSAugustin Cavalier	attrSupport=$?
858fc2c93fbSAugustin Cavalier	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
859fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR=1
860a5c952dbSAugustin Cavalier	elif [ $attrSupport = 1 ]; then
861fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR_REF=1
862a5c952dbSAugustin Cavalier	fi
863a5c952dbSAugustin Cavalierfi
864fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
865fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
866a5c952dbSAugustin Cavalier
867f04f7042SNiels Sascha Reedijk# determine how to invoke sed with extended regexp support for non-GNU sed
868f04f7042SNiels Sascha Reedijkif [ $HOST_PLATFORM = "darwin" ]; then
869f04f7042SNiels Sascha Reedijk	HOST_EXTENDED_REGEX_SED="sed -E"
870f04f7042SNiels Sascha Reedijkfi
871f04f7042SNiels Sascha Reedijk
8727d72ed01SAugustin Cavalier# pick a JAMSHELL
8737d72ed01SAugustin Cavalierif [ "$JAMSHELL" = "" ]; then
8747d72ed01SAugustin Cavalier	if check_file_exists /bin/dash; then
8757d72ed01SAugustin Cavalier		JAMSHELL=/bin/dash
8767d72ed01SAugustin Cavalier	else
8777d72ed01SAugustin Cavalier		JAMSHELL=/bin/sh
8787d72ed01SAugustin Cavalier	fi
8797d72ed01SAugustin Cavalierfi
8807d72ed01SAugustin Cavalierif ! $JAMSHELL -c true; then
8817d72ed01SAugustin Cavalier	echo "$JAMSHELL does not work! Please specify a working JAMSHELL."
8827d72ed01SAugustin Cavalier	exit 1
8837d72ed01SAugustin Cavalierfi
8847d72ed01SAugustin Cavalier
8852b200496SAugustin Cavalier# locate python
886b6554e72SJessica Hamiltonif [ -n "$pythonPath" ] && "$pythonPath" --version < /dev/null > /dev/null 2>&1; then
887b6554e72SJessica Hamilton	HOST_PYTHON="$pythonPath"
888b6554e72SJessica Hamiltonelif python3 --version < /dev/null > /dev/null 2>&1; then
88917dc34acSAndrew Lindesay	HOST_PYTHON="python3"
8902b200496SAugustin Cavalierelif python --version < /dev/null > /dev/null 2>&1; then
89117dc34acSAndrew Lindesay	HOST_PYTHON="python"
89217dc34acSAndrew Lindesayelse
89317dc34acSAndrew Lindesay	echo "a python interpreter is required"
89417dc34acSAndrew Lindesay	exit 1
89517dc34acSAndrew Lindesayfi
89617dc34acSAndrew Lindesay
897c4057093SJessica Hamilton# check is python is new enough
898c4057093SJessica Hamilton# usage of python by HDS requires at least 3.9
899c4057093SJessica HamiltonPYTHON_VERSION=$("$HOST_PYTHON" --version | sed -e 's/Python //')
900c4057093SJessica Hamilton
901c4057093SJessica Hamiltoncase $PYTHON_VERSION in
902c4057093SJessica Hamilton	2.* | 3.[1-8].*)
903c4057093SJessica Hamilton		echo "Python $PYTHON_VERSION is too old, need at least Python 3.9"
904c4057093SJessica Hamilton		exit 1
905c4057093SJessica Hamilton		;;
906c4057093SJessica Hamilton	*)
907c4057093SJessica Hamilton		;;
908c4057093SJessica Hamiltonesac
909c4057093SJessica Hamilton
910*7c6ab830SJessica Hamilton# check if wget supports --retry-on-host-error
911*7c6ab830SJessica Hamiltonif wget --retry-on-host-error --version > /dev/null 2>&1; then
912*7c6ab830SJessica Hamilton	HOST_WGET_RETRY_ON_HOST_ERROR=1
913*7c6ab830SJessica Hamiltonfi
914*7c6ab830SJessica Hamilton
915cb721c59SFrançois Revol# check if nasm can actually output ELF files
916cb721c59SFrançois Revol# (the stock version in OSX can't)
917cb721c59SFrançois Revol# XXX: should probably only test for x86* arch
9183e6c09cdSAdrien Destuguesif [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
919cb721c59SFrançois Revol	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
920cb721c59SFrançois Revol	if [ $HOST_PLATFORM = "darwin" ]; then
921cb721c59SFrançois Revol		echo "You can install it from Mac Ports."
922cb721c59SFrançois Revol		echo "Mac Ports is available at: http://www.macports.org/"
923cb721c59SFrançois Revol	fi
924cb721c59SFrançois Revol	exit 1
925cb721c59SFrançois Revolfi
926cb721c59SFrançois Revol
927338b8dc3SIngo Weinhold# create output directory
9286e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
929338b8dc3SIngo Weinhold
9302ebcd86dSIngo Weinholdif [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
9312ebcd86dSIngo Weinhold	invalidCommand=$sourceDir/build/scripts/host_build_only
9322ebcd86dSIngo Weinhold	HAIKU_AR=$invalidCommand
9332ebcd86dSIngo Weinhold	HAIKU_CC=$invalidCommand
9342ebcd86dSIngo Weinhold	HAIKU_LD=$invalidCommand
9352ebcd86dSIngo Weinhold	HAIKU_OBJCOPY=$invalidCommand
9362ebcd86dSIngo Weinhold	HAIKU_RANLIB=$invalidCommand
9372ebcd86dSIngo Weinhold	HAIKU_ELFEDIT=$invalidCommand
938d6f80927SJonathan Schleifer	HAIKU_NASM=$invalidCommand
9392ebcd86dSIngo Weinhold	HAIKU_STRIP=$invalidCommand
9402ebcd86dSIngo Weinholdelse
941483b28e4SIngo Weinhold	# On Haiku determine target architectures and tools automatically.
942c0e8cc1aSIngo Weinhold	if [ -z "$targetArchs" ]; then
943483b28e4SIngo Weinhold		if [ $HOST_PLATFORM != haiku_host ]; then
944483b28e4SIngo Weinhold			echo "Please specify the build tools to use or build (via" \
945eaef83a9SJeroen Oortwijn				"--cross-tools-prefix or --build-cross-tools) or specify a" \
946483b28e4SIngo Weinhold				"host-only build (--host-only)." >&2
9477f9beaf1SOliver Tappe			echo "For more info, invoke $0 --help"
948483b28e4SIngo Weinhold			exit 1
949483b28e4SIngo Weinhold		fi
950483b28e4SIngo Weinhold
951483b28e4SIngo Weinhold		# determine primary architecture
952dda53eaeSIngo Weinhold		targetArch=`package list -i /system/packages/haiku-*.hpkg \
953483b28e4SIngo Weinhold			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
954483b28e4SIngo Weinhold		is_in_list "$targetArch" "$supportedTargetArchs" || (
955483b28e4SIngo Weinhold			echo "Unsupported target architecture: \"$targetArch\"" >&2
956483b28e4SIngo Weinhold			exit 1
957483b28e4SIngo Weinhold		)
958c0e8cc1aSIngo Weinhold		targetArchs=$targetArch
959483b28e4SIngo Weinhold
960c0e8cc1aSIngo Weinhold		set_default_value HAIKU_AR_$targetArch			ar
961c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CC_$targetArch			gcc
962c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LD_$targetArch			ld
963c0e8cc1aSIngo Weinhold		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
964c0e8cc1aSIngo Weinhold		set_default_value HAIKU_RANLIB_$targetArch		ranlib
965c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
966c0e8cc1aSIngo Weinhold		set_default_value HAIKU_STRIP_$targetArch		strip
967483b28e4SIngo Weinhold
968483b28e4SIngo Weinhold		# determine secondary architectures
969483b28e4SIngo Weinhold		for targetArch in $supportedTargetArchs; do
97080262a91SMatt Madia			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
971483b28e4SIngo Weinhold				targetArchs="$targetArchs $targetArch"
972483b28e4SIngo Weinhold				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
973483b28e4SIngo Weinhold				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
974483b28e4SIngo Weinhold				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
975483b28e4SIngo Weinhold				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
976483b28e4SIngo Weinhold				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
977483b28e4SIngo Weinhold				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
978483b28e4SIngo Weinhold				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
979483b28e4SIngo Weinhold			fi
980483b28e4SIngo Weinhold		done
981483b28e4SIngo Weinhold
982483b28e4SIngo Weinhold		# The target architectures might have been specified explicitly.
983483b28e4SIngo Weinhold		if [ -n "$haikuTargetArchs" ]; then
984483b28e4SIngo Weinhold			for targetArch in $haikuTargetArchs; do
985483b28e4SIngo Weinhold				is_in_list "$targetArch" "$targetArchs" || (
986483b28e4SIngo Weinhold					echo "Unsupported target architecture: \"$targetArch\"." \
987483b28e4SIngo Weinhold						"Only native architectures of the host platform can" \
988483b28e4SIngo Weinhold						"be specified." >&2
989483b28e4SIngo Weinhold					exit 1
990483b28e4SIngo Weinhold				)
991483b28e4SIngo Weinhold			done
992483b28e4SIngo Weinhold			targetArchs="$haikuTargetArchs"
993483b28e4SIngo Weinhold		fi
994c0e8cc1aSIngo Weinhold	fi
995c0e8cc1aSIngo Weinhold
99678b22458SAugustin Cavalier	if [ "$targetArchs" = " x86_gcc2" ]; then
99778b22458SAugustin Cavalier		echo "Building a GCC2-only Haiku is no longer supported."
99878b22458SAugustin Cavalier		echo "Please configure the secondary architecture."
99978b22458SAugustin Cavalier		exit 1
100078b22458SAugustin Cavalier	fi
100178b22458SAugustin Cavalier
100268ccc989SIngo Weinhold	isPrimaryArch=1
1003c0e8cc1aSIngo Weinhold	for targetArch in $targetArchs; do
10046c5fcb4fSAugustin Cavalier		# Note: targetArch is "unknown<n>" at this point if a cross-tools
1005c0e8cc1aSIngo Weinhold		# prefix was specified. The standard_gcc_settings call below will get
1006c0e8cc1aSIngo Weinhold		# the actual architecture.
1007c0e8cc1aSIngo Weinhold
1008c7b5f282SAugustin Cavalier		for existingArch in $HAIKU_PACKAGING_ARCHS; do
1009c7b5f282SAugustin Cavalier			if [ $existingArch = $targetArch ]; then
10106c5fcb4fSAugustin Cavalier				# somehow we wound up with a duplicate arch; skip this one
1011c7b5f282SAugustin Cavalier				targetArch=
1012c7b5f282SAugustin Cavalier				break
1013c7b5f282SAugustin Cavalier			fi
1014c7b5f282SAugustin Cavalier		done
1015c7b5f282SAugustin Cavalier		if [ -z "$targetArch" ]; then
10166c5fcb4fSAugustin Cavalier			continue
10176c5fcb4fSAugustin Cavalier		fi
10186c5fcb4fSAugustin Cavalier
1019c0e8cc1aSIngo Weinhold		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
1020c0e8cc1aSIngo Weinhold
1021338b8dc3SIngo Weinhold		# build cross tools from sources
1022c0e8cc1aSIngo Weinhold		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
1023c0e8cc1aSIngo Weinhold			crossToolsDir="$outputDir/cross-tools-$targetArch"
1024c0e8cc1aSIngo Weinhold			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
1025c0e8cc1aSIngo Weinhold			script="$buildCrossToolsScript"
10268304ec7cSIngo Weinhold			scriptArgs=
1027c0e8cc1aSIngo Weinhold			if [ $targetArch != x86_gcc2 ]; then
10288304ec7cSIngo Weinhold				script="${script}_gcc4"
10298304ec7cSIngo Weinhold				scriptArgs="$targetMachine"
10301e93288eSJérôme Duval				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
10311e93288eSJérôme Duval					$useGccGraphiteDefault
1032c0e8cc1aSIngo Weinhold			fi
103368ccc989SIngo Weinhold			secondaryArch=
103468ccc989SIngo Weinhold			if [ -z "$isPrimaryArch" ]; then
103568ccc989SIngo Weinhold				secondaryArch=$targetArch
103668ccc989SIngo Weinhold			fi
103786de8c37SIngo Weinhold
103886de8c37SIngo Weinhold			case $HOST_PLATFORM in
103986de8c37SIngo Weinhold				freebsd|openbsd)	MAKE=gmake;;
104086de8c37SIngo Weinhold				*)					MAKE=make;;
104186de8c37SIngo Weinhold			esac
104286de8c37SIngo Weinhold
10431f839e89Swaddlesplash			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
104486de8c37SIngo Weinhold				MAKE=$MAKE \
104568ccc989SIngo Weinhold				SECONDARY_ARCH=$secondaryArch \
1046c0e8cc1aSIngo Weinhold				HAIKU_USE_GCC_GRAPHITE=`get_variable \
1047c0e8cc1aSIngo Weinhold					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
1048b3ece905SJérôme Duval				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
10494da6cf84SFrançois Revol				HAIKU_USE_GDB="$gdbSources" \
1050e9e00b80SJessica Hamilton				HAIKU_USE_SYSROOT="$crossToolsSysroot" \
10518304ec7cSIngo Weinhold				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
10528304ec7cSIngo Weinhold					"$crossToolsDir" $buildCrossToolsJobs || exit 1
1053825700d3SAugustin Cavalier			else
1054825700d3SAugustin Cavalier				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
1055825700d3SAugustin Cavalier			fi
1056c0e8cc1aSIngo Weinhold			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
1057338b8dc3SIngo Weinhold		fi
1058338b8dc3SIngo Weinhold
1059c0e8cc1aSIngo Weinhold		# prepare gcc settings and get the actual target architecture
1060a7bddff1SJonathan Schleifer		if [ $useClang = 1 ]; then
1061c44472c5SAugustin Cavalier			gcc="$HAIKU_clang -target ${targetMachine}"
1062ddf7f643SAugustin Cavalier			if [ ! -z "${crossToolsPrefix}" ]; then
1063ddf7f643SAugustin Cavalier				gcc="$gcc -B ${crossToolsPrefix}"
1064ddf7f643SAugustin Cavalier			fi
10651f6fe055SAugustin Cavalier
10661f6fe055SAugustin Cavalier			# Clang's compiler intrinsics are not compatible with GCC's or even
10671f6fe055SAugustin Cavalier			# across versions of Clang, so we must collect them for use in the build.
10681f6fe055SAugustin Cavalier			mkdir -p "$outputDir/clang_headers" || exit 1
106920c61bb7SAugustin Cavalier			clangHeadersDir=`$gcc -print-resource-dir`/include/
107020c61bb7SAugustin Cavalier			case $targetArch in
107120c61bb7SAugustin Cavalier				x86*) cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1 ;;
107220c61bb7SAugustin Cavalier				ppc*) cp $clangHeadersDir/*altivec* "$outputDir/clang_headers" || exit 1 ;;
107320c61bb7SAugustin Cavalier				arm*) cp $clangHeadersDir/*arm* "$outputDir/clang_headers" || exit 1 ;;
107420c61bb7SAugustin Cavalier			esac
1075d73993ffSAugustin Cavalier		elif [ -z "${crossToolsPrefix}" ]; then
1076d73993ffSAugustin Cavalier			gcc=`get_variable HAIKU_CC_$targetArch`
1077a7bddff1SJonathan Schleifer		else
1078c0e8cc1aSIngo Weinhold			gcc="${crossToolsPrefix}gcc"
1079a7bddff1SJonathan Schleifer		fi
1080e22ea41cSJessica Hamilton
1081e22ea41cSJessica Hamilton		if [ -z "$gcc" ]; then
1082e22ea41cSJessica Hamilton			echo "Please specify the build tools to use or build (via" \
1083e22ea41cSJessica Hamilton				"--cross-tools-prefix or --build-cross-tools)." >&2
1084e22ea41cSJessica Hamilton			echo "For more info, invoke $0 --help"
1085e22ea41cSJessica Hamilton			exit 1
1086e22ea41cSJessica Hamilton		fi
1087c0e8cc1aSIngo Weinhold		standard_gcc_settings "$gcc"
1088c0e8cc1aSIngo Weinhold		targetArch=$standard_gcc_settings_targetArch
1089338b8dc3SIngo Weinhold
1090c0e8cc1aSIngo Weinhold		# set default values for flags
1091c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CPPFLAGS_$targetArch	""
1092c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CCFLAGS_$targetArch		""
1093c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CXXFLAGS_$targetArch	""
1094252e4f62SAugustin Cavalier		set_default_value HAIKU_LINKFLAGS_$targetArch	""
1095c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LDFLAGS_$targetArch		""
1096241b61a7SAugustin Cavalier		set_default_value HAIKU_ARFLAGS_$targetArch		cru
1097c0e8cc1aSIngo Weinhold		set_default_value HAIKU_UNARFLAGS_$targetArch	x
1098338b8dc3SIngo Weinhold
1099c0e8cc1aSIngo Weinhold		# Override the cross tools variables, if the tools were built or a
1100c0e8cc1aSIngo Weinhold		# prefix was specified.
11011c307243SAugustin Cavalier		if [ -n "$crossToolsPrefix" ]; then
11021c307243SAugustin Cavalier			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
11031c307243SAugustin Cavalier			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
11041c307243SAugustin Cavalier			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
11051c307243SAugustin Cavalier			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
110677d89de0SAugustin Cavalier
110777d89de0SAugustin Cavalier			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
110877d89de0SAugustin Cavalier			if [ `get_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch` -eq 0 ]; then
110977d89de0SAugustin Cavalier				get_build_tool_path ELFEDIT_$targetArch ${crossToolsPrefix}elfedit
111077d89de0SAugustin Cavalier			fi
11111c307243SAugustin Cavalier		fi
111252a38012Sejakowatz
1113ef57df3dSIngo Weinhold		# check whether the Haiku compiler really targets Haiku
1114c0e8cc1aSIngo Weinhold		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
1115c0e8cc1aSIngo Weinhold		case "$targetMachine" in
1116eedc3d0bSIngo Weinhold			*-*-haiku)	;;
1117c0e8cc1aSIngo Weinhold			*)
1118c0e8cc1aSIngo Weinhold				echo The compiler specified as Haiku target compiler is not a \
1119c0e8cc1aSIngo Weinhold				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
1120eedc3d0bSIngo Weinhold				echo compiler: $HAIKU_CC
1121c0e8cc1aSIngo Weinhold				echo compiler is configured for target: $targetMachine
1122eedc3d0bSIngo Weinhold				exit 1 ;;
1123eedc3d0bSIngo Weinhold		esac
1124c0e8cc1aSIngo Weinhold
1125c0e8cc1aSIngo Weinhold		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
112668ccc989SIngo Weinhold		isPrimaryArch=
1127c0e8cc1aSIngo Weinhold	done
11282ebcd86dSIngo Weinholdfi
1129eedc3d0bSIngo Weinhold
113052a38012Sejakowatz# Generate BuildConfig
11317c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
1132825700d3SAugustin Cavalier# -- WARNING --
1133825700d3SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1134825700d3SAugustin Cavalier# overwritten the next time configure is run.
1135825700d3SAugustin Cavalier#
1136825700d3SAugustin Cavalier#d ${currentDir}
1137825700d3SAugustin Cavalier#c ${configurePath}
1138825700d3SAugustin Cavalier#e ${configureEnvirons}
1139825700d3SAugustin Cavalier#a ${configureArgs}
114052a38012Sejakowatz
11416f582441SKacper KasperGIT_DIR						?= "${GIT_DIR}" ;
11426f582441SKacper Kasper
11437c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
1144b57e7df9SAugustin CavalierTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
1145b57e7df9SAugustin CavalierHAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
1146338b8dc3SIngo Weinhold
1147b57e7df9SAugustin CavalierHAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
114876fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES		?= "${HAIKU_INCLUDE_SOURCES}" ;
11497c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY		?= "${HAIKU_INCLUDE_3RDPARTY}" ;
11507c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY	?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
1151b57e7df9SAugustin Cavalier
11527c4641d0SOliver TappeHAIKU_USE_GCC_PIPE			?= "${HAIKU_USE_GCC_PIPE}" ;
11537986925fSIngo WeinholdHAIKU_HOST_USE_32BIT		?= "${HAIKU_HOST_USE_32BIT}" ;
11547986925fSIngo WeinholdHAIKU_HOST_USE_XATTR		?= "${HAIKU_HOST_USE_XATTR}" ;
1155bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF	?= "${HAIKU_HOST_USE_XATTR_REF}" ;
11562ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY		?= "${HAIKU_HOST_BUILD_ONLY}" ;
1157eccc7665SIngo Weinhold
115834fef46bSAugustin CavalierJAMSHELL					?= ${JAMSHELL} -e -c ;
11597d72ed01SAugustin Cavalier
1160b57e7df9SAugustin CavalierHOST_CC						?= ${CC} ;
11617c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
11627c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
11637c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
1164b57e7df9SAugustin CavalierHOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
11652a5d0aafSIngo WeinholdHOST_SHA256					?= ${HOST_SHA256} ;
116617dc34acSAndrew LindesayHOST_PYTHON					?= ${HOST_PYTHON} ;
1167*7c6ab830SJessica HamiltonHOST_WGET_RETRY_ON_HOST_ERROR			?= ${HOST_WGET_RETRY_ON_HOST_ERROR} ;
1168b57e7df9SAugustin CavalierHAIKU_NASM					?= ${HAIKU_NASM} ;
1169b57e7df9SAugustin Cavalier
11701d91b371SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR	?= "${HAIKU_BUILD_ATTRIBUTES_DIR}" ;
11718b5934c9SIngo Weinhold
1172e173a1ecSIngo WeinholdHOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1173e173a1ecSIngo WeinholdHAIKU_PORTS					?= ${HAIKU_PORTS} ;
1174e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1175c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1176e173a1ecSIngo Weinhold
117731f27c4dSAlexander von Gluck IVHAIKU_BOOT_EFI_PRIVATE_KEYFILE	?= ${HAIKU_EFI_SIGNING_KEY} ;
1178c4786ea6SlilloEOF
1179c4786ea6Slillo
1180c0e8cc1aSIngo Weinholdfor targetArch in $HAIKU_PACKAGING_ARCHS; do
1181c0e8cc1aSIngo Weinhold	variables="
1182c1249957SAugustin Cavalier		HAIKU_CC					HAIKU_CC
118347320dd0SAugustin Cavalier		HAIKU_CC_IS_LEGACY_GCC		HAIKU_CC_IS_LEGACY_GCC
1184c1249957SAugustin Cavalier		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1185c1249957SAugustin Cavalier		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1186c0e8cc1aSIngo Weinhold		HAIKU_CPU					HAIKU_CPU
1187c1249957SAugustin Cavalier		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1188c1249957SAugustin Cavalier		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1189c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1190c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
11914df4b48fSJérôme Duval		HAIKU_BOOT_32_LIBGCC		HAIKU_BOOT_32_LIBGCC
11924df4b48fSJérôme Duval		HAIKU_BOOT_32_LIBSUPC++		HAIKU_BOOT_32_LIBSUPCXX
1193c0e8cc1aSIngo Weinhold		HAIKU_AR					HAIKU_AR
1194c0e8cc1aSIngo Weinhold		HAIKU_LD					HAIKU_LD
1195c0e8cc1aSIngo Weinhold		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1196c0e8cc1aSIngo Weinhold		HAIKU_RANLIB				HAIKU_RANLIB
1197c0e8cc1aSIngo Weinhold		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1198c0e8cc1aSIngo Weinhold		HAIKU_STRIP					HAIKU_STRIP
1199c0e8cc1aSIngo Weinhold		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1200c0e8cc1aSIngo Weinhold		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1201c0e8cc1aSIngo Weinhold		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1202252e4f62SAugustin Cavalier		HAIKU_LINKFLAGS				HAIKU_LINKFLAGS
1203c0e8cc1aSIngo Weinhold		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1204c0e8cc1aSIngo Weinhold		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1205c0e8cc1aSIngo Weinhold		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1206c0e8cc1aSIngo Weinhold		"
1207c0e8cc1aSIngo Weinhold	set -- $variables
1208c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1209c0e8cc1aSIngo Weinhold		value=`get_variable ${2}_$targetArch`
1210c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1211c0e8cc1aSIngo Weinhold		shift 2
1212c0e8cc1aSIngo Weinhold	done
1213b1e5b60cSAxel Dörfler
1214c0e8cc1aSIngo Weinhold	# For variables that may have long values, distribute them over multiple
1215c0e8cc1aSIngo Weinhold	# lines so that jam doesn't hit the maximum line length.
1216c0e8cc1aSIngo Weinhold	variables="
121766a7f29fSJérôme Duval		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
12184df4b48fSJérôme Duval		HAIKU_BOOT_32_C++_HEADERS_DIR	HAIKU_BOOT_32_CXX_HEADERS_DIR
1219c0e8cc1aSIngo Weinhold		"
1220c0e8cc1aSIngo Weinhold	set -- $variables
1221c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1222c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1223c0e8cc1aSIngo Weinhold		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1224c0e8cc1aSIngo Weinhold			>> "$buildConfigFile"
1225c0e8cc1aSIngo Weinhold		echo "    ;" >> "$buildConfigFile"
1226c0e8cc1aSIngo Weinhold		shift 2
1227c0e8cc1aSIngo Weinhold	done
1228c0e8cc1aSIngo Weinholddone
1229b1e5b60cSAxel Dörfler
1230b1e5b60cSAxel Dörfler
12313facc270SAugustin Cavalier# Generate a Jamfile in the output directory.
1232338b8dc3SIngo Weinhold
1233338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
12343facc270SAugustin Cavalier# -- WARNING --
12353facc270SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
12363facc270SAugustin Cavalier# overwritten the next time configure is run.
1237338b8dc3SIngo Weinhold
12383facc270SAugustin CavalierHAIKU_TOP			= $(relative_to "${sourceDir}" "${outputDir}") ;
12393facc270SAugustin CavalierHAIKU_OUTPUT_DIR	= . ;
1240338b8dc3SIngo Weinhold
1241338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1242338b8dc3SIngo Weinhold
1243338b8dc3SIngo WeinholdEOF
1244d73993ffSAugustin Cavalier
1245d73993ffSAugustin Cavalierecho "Configured successfully!"
1246