xref: /haiku/configure (revision 31f27c4d39887e0ef393db27279b8c154ccb1e4b)
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.
70483b28e4SIngo Weinhold  --target-arch <arch>        Haiku only: Specify the target architecture to
71483b28e4SIngo Weinhold                              build for. Must be one of the architectures of the
72483b28e4SIngo Weinhold                              host system. The installed build tools for that
73483b28e4SIngo Weinhold                              architecture will be used.
74483b28e4SIngo Weinhold                              This option can be specified multiple times. The
75483b28e4SIngo Weinhold                              first occurrence specifies the primary
76483b28e4SIngo Weinhold                              architecture of the Haiku to build, subsequent
77483b28e4SIngo Weinhold                              ones the secondary architectures.
78d73993ffSAugustin Cavalier  --use-clang <arch>          Build with host Clang instead of GCC cross
79d73993ffSAugustin Cavalier                              compiler, targeting <arch>
80eccc7665SIngo Weinhold  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
815a34a443SFrançois Revol                              process, but uses more memory.
82ed38d2efSJerome Duval  --use-gcc-graphite          Build with GCC Graphite engine for loop
83a5c952dbSAugustin Cavalier                              optimizations. (Only for GCC 4+.)
840385b065SIngo Weinhold  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
85fc2c93fbSAugustin Cavalier  --no-full-xattr             Do not use Linux/*BSD/Darwin's native extended file
86fc2c93fbSAugustin Cavalier                              attributes as Haiku attributes. If they are still
87fc2c93fbSAugustin Cavalier                              available, they will be used to store hashes for
88fc2c93fbSAugustin Cavalier                              the attribute emulation layer.
89fc2c93fbSAugustin Cavalier  --no-xattr                  Do not use Linux/*BSD/Darwin's native extended file
90fc2c93fbSAugustin Cavalier                              attributes for Haiku extended attributes at all,
91fc2c93fbSAugustin Cavalier                              even if they are available.
924da6cf84SFrançois Revol  --with-gdb <gdb sources dir>
934da6cf84SFrançois Revol                              specify the path to a GDB source dir, to build
944da6cf84SFrançois Revol                              GDB for each arch we build the cross-tools for.
9504be20a7SJérôme Duval  --use-stack-protector       Build with stack protection enabled
96*31f27c4dSAlexander von Gluck IV  --efi-signing-key           Private keyfile to sign any EFI bootloaders
97338b8dc3SIngo Weinhold
98338b8dc3SIngo Weinholdenvironment variables:
9963701e7dSOliver Tappe  CC                          The host compiler. Defaults to "gcc".
10065706842SAugustin Cavalier  HAIKU_AR_<arch>             The static library archiver for <arch>.
101c0e8cc1aSIngo Weinhold                              Defaults to "ar".
10265706842SAugustin Cavalier  HAIKU_CC_<arch>             The compiler for <arch>. Defaults to "gcc".
10365706842SAugustin Cavalier  HAIKU_LD_<arch>             The <arch> linker. Defaults to "ld".
10465706842SAugustin Cavalier  HAIKU_OBJCOPY_<arch>        The <arch> objcopy to be used. Defaults to
105c0e8cc1aSIngo Weinhold                              "objcopy".
10665706842SAugustin Cavalier  HAIKU_RANLIB_<arch>         The static library indexer for <arch>. Defaults
107c0e8cc1aSIngo Weinhold                              to "ranlib".
10865706842SAugustin Cavalier  HAIKU_STRIP_<arch>          The <arch> strip command. Defaults to "strip".
109a04a520bSJonathan Schleifer  HAIKU_NASM                  The nasm assembler (x86 and x86_64 only).
110c0e8cc1aSIngo Weinhold  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
111c0e8cc1aSIngo Weinhold                              <arch>. Defaults to "".
112c0e8cc1aSIngo Weinhold  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
113c0e8cc1aSIngo Weinhold                              Defaults to "".
114c0e8cc1aSIngo Weinhold  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
115c0e8cc1aSIngo Weinhold                              Defaults to "".
116252e4f62SAugustin Cavalier  HAIKU_LINKFLAGS_<arch>      The flags passed to the compiler when linking for
117252e4f62SAugustin Cavalier                              target architecture <arch>. Defaults to "".
118c0e8cc1aSIngo Weinhold  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
119c0e8cc1aSIngo Weinhold                              Defaults to "".
120c0e8cc1aSIngo Weinhold  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
121c0e8cc1aSIngo Weinhold                              architecture <arch> for archiving. Defaults to
122241b61a7SAugustin Cavalier                              "cru".
123c0e8cc1aSIngo Weinhold  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
124c0e8cc1aSIngo Weinhold                              architecture <arch> for unarchiving. Defaults to
125c0e8cc1aSIngo Weinhold                              "x".
12664f6da31SIngo Weinhold
127c0e8cc1aSIngo WeinholdNon-default output directories:
12864f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
12964f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
13064f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
13164f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
13264f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
13364f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
13464f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
13564f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
13664f6da31SIngo Weinhold  non-default location and running jam.
13764f6da31SIngo Weinhold
13864f6da31SIngo Weinhold
139022fa244SIngo WeinholdEOF
140022fa244SIngo Weinhold}
141022fa244SIngo Weinhold
142022fa244SIngo Weinhold# assertparam
143022fa244SIngo Weinhold#
144022fa244SIngo Weinhold# Checks whether at least one parameter is left.
145022fa244SIngo Weinhold#
146022fa244SIngo Weinholdassertparam()
147022fa244SIngo Weinhold{
14820ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
149022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
150022fa244SIngo Weinhold		exit 1
151022fa244SIngo Weinhold	fi
152022fa244SIngo Weinhold}
153022fa244SIngo Weinhold
15420ab75e6SIngo Weinhold# assertparams
15520ab75e6SIngo Weinhold#
15620ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
15720ab75e6SIngo Weinhold#
15820ab75e6SIngo Weinholdassertparams()
15920ab75e6SIngo Weinhold{
16020ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
16120ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
16220ab75e6SIngo Weinhold		exit 1
16320ab75e6SIngo Weinhold	fi
16420ab75e6SIngo Weinhold}
16520ab75e6SIngo Weinhold
166e173a1ecSIngo Weinhold# absolute_path
167e173a1ecSIngo Weinhold#
168e173a1ecSIngo Weinhold# returns the absolute path of a given path.
169e173a1ecSIngo Weinhold#
170e173a1ecSIngo Weinholdabsolute_path()
171e173a1ecSIngo Weinhold{
1726a4f3954SFrançois Revol	if [ "x$1" != "x${1#/}" ]; then
173e173a1ecSIngo Weinhold		echo "$1"
174e173a1ecSIngo Weinhold	else
175e173a1ecSIngo Weinhold		echo "`pwd`/$1"
176e173a1ecSIngo Weinhold	fi
177e173a1ecSIngo Weinhold}
178e173a1ecSIngo Weinhold
17939d444a3SArvind S Raj# check_dir_exists
18039d444a3SArvind S Raj#
18139d444a3SArvind S Raj# check if a directory exists or not
18239d444a3SArvind S Raj#
18339d444a3SArvind S Rajcheck_dir_exists()
18439d444a3SArvind S Raj{
18539d444a3SArvind S Raj	if [ -d "$1" ]; then
18639d444a3SArvind S Raj		return 0
18739d444a3SArvind S Raj	else
18839d444a3SArvind S Raj		return 1
18939d444a3SArvind S Raj	fi
19039d444a3SArvind S Raj}
19139d444a3SArvind S Raj
192502882dbSJessica Hamilton# check_file_exists
193502882dbSJessica Hamilton#
194502882dbSJessica Hamilton# check if a file exists or not
195502882dbSJessica Hamilton#
196502882dbSJessica Hamiltoncheck_file_exists()
197502882dbSJessica Hamilton{
198502882dbSJessica Hamilton	if [ -f "$1" ]; then
199502882dbSJessica Hamilton		return 0
200502882dbSJessica Hamilton	else
201502882dbSJessica Hamilton		return 1
202502882dbSJessica Hamilton	fi
203502882dbSJessica Hamilton}
204502882dbSJessica Hamilton
2059a001156SOliver Tappe# real_path
2069a001156SOliver Tappe#
2079a001156SOliver Tappe# returns the realpath of a symbolic link.
2089a001156SOliver Tappe#
2099a001156SOliver Tappereal_path()
2109a001156SOliver Tappe{
2119a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
2129a001156SOliver Tappe}
2139a001156SOliver Tappe
2143facc270SAugustin Cavalier# relative_to
2153facc270SAugustin Cavalier#
2163facc270SAugustin Cavalier# returns $1 relative to $2
2173facc270SAugustin Cavalier#
2183facc270SAugustin Cavalierrelative_to()
2193facc270SAugustin Cavalier{
2203facc270SAugustin Cavalier	perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' \
2211d91b371SAugustin Cavalier		"$1" "$2"
2223facc270SAugustin Cavalier}
2233facc270SAugustin Cavalier
224e5d446fcSAlexander von Gluck IV# valid_toolchain
225e5d446fcSAlexander von Gluck IV#
2261f839e89Swaddlesplash# check if a toolchain is valid
227e5d446fcSAlexander von Gluck IV#
228e5d446fcSAlexander von Gluck IVvalid_toolchain()
229e5d446fcSAlexander von Gluck IV{
230e5d446fcSAlexander von Gluck IV	TRIPLET="$1"
231e5d446fcSAlexander von Gluck IV	BASE="$2"
2321f839e89Swaddlesplash	SOURCE="$3"
233e5d446fcSAlexander von Gluck IV	if [ ! -d "$BASE" ]; then
2341f839e89Swaddlesplash		return 1
235e5d446fcSAlexander von Gluck IV	fi
236e5d446fcSAlexander von Gluck IV	if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
2371f839e89Swaddlesplash		[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
2381f839e89Swaddlesplash			[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
2391f839e89Swaddlesplash		return $?
240e5d446fcSAlexander von Gluck IV	fi
2411f839e89Swaddlesplash	return 1
242e5d446fcSAlexander von Gluck IV}
243e5d446fcSAlexander von Gluck IV
24447320dd0SAugustin Cavalier# is_legacy_gcc
24547320dd0SAugustin Cavalier#
24647320dd0SAugustin Cavalier# Determines if the specified GCC version is a "legacy" (i.e. GCC < 4) one.
24747320dd0SAugustin Cavalier#
24847320dd0SAugustin Cavalieris_legacy_gcc()
24947320dd0SAugustin Cavalier{
25047320dd0SAugustin Cavalier	if [ `echo $1 | cut -d'.' -f1` -lt 4 ]; then
25147320dd0SAugustin Cavalier		echo 1
25247320dd0SAugustin Cavalier	else
25347320dd0SAugustin Cavalier		echo 0
25447320dd0SAugustin Cavalier	fi
25547320dd0SAugustin Cavalier}
25647320dd0SAugustin Cavalier
25709c5682dSIngo Weinhold# standard_gcc_settings
25809c5682dSIngo Weinhold#
25909c5682dSIngo Weinhold# Sets the variables for a GCC platform.
26009c5682dSIngo Weinhold#
26109c5682dSIngo Weinholdstandard_gcc_settings()
26209c5682dSIngo Weinhold{
26365706842SAugustin Cavalier	local gcc="$1"
264c0e8cc1aSIngo Weinhold
265138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
266b29b48b1SMatt Madia		readlink="greadlink -e"
267138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
268b29b48b1SMatt Madia		readlink=realpath
2699a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
270b29b48b1SMatt Madia		readlink="readlink -e"
2719a001156SOliver Tappe	else
2729a001156SOliver Tappe		readlink=real_path
273b4b6d83cSMatt Madia	fi
274138f5fb4SIngo Weinhold
27509c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
276c0e8cc1aSIngo Weinhold	local gcclib=`$gcc -print-libgcc-file-name`
277c0e8cc1aSIngo Weinhold	local gccdir=`dirname ${gcclib}`
2785b0f7b1bSOliver Tappe
279c0e8cc1aSIngo Weinhold	local gccRawVersion=`$gcc -dumpversion`
280c0e8cc1aSIngo Weinhold	local gccMachine=`$gcc -dumpmachine`
281338b8dc3SIngo Weinhold
282fc8967f1SIngo Weinhold	# determine architecture from machine triple
283c0e8cc1aSIngo Weinhold	case $gccMachine in
284c0e8cc1aSIngo Weinhold		arm-*)		targetCpu=arm;;
2851f52c921SJaroslaw Pelczar		aarch64-*)	targetCpu=arm64;;
286c0e8cc1aSIngo Weinhold		i?86-*)		targetCpu=x86;;
287c0e8cc1aSIngo Weinhold		m68k-*)		targetCpu=m68k;;
288c0e8cc1aSIngo Weinhold		powerpc-*)	targetCpu=ppc;;
2895bd0fbd1SAlexander von Gluck IV		riscv64-*)	targetCpu=riscv64;;
2905629675aSAdrien Destugues		sparc64-*)	targetCpu=sparc;;
291c0e8cc1aSIngo Weinhold		x86_64-*)	targetCpu=x86_64;;
292fc8967f1SIngo Weinhold		*)
293c0e8cc1aSIngo Weinhold			echo "Unsupported gcc target machine: $gccMachine" >&2
294fc8967f1SIngo Weinhold			exit 1
295fc8967f1SIngo Weinhold			;;
296fc8967f1SIngo Weinhold	esac
297fc8967f1SIngo Weinhold
298c0e8cc1aSIngo Weinhold	local targetArch=$targetCpu
299fc8967f1SIngo Weinhold
300c0e8cc1aSIngo Weinhold	case $gccRawVersion in
3016cc8eecfSOliver Tappe		2.9*)
3025b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
3035b0f7b1bSOliver Tappe			# if an older one is installed
304c0e8cc1aSIngo Weinhold			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
3055b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
3065b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
3075b0f7b1bSOliver Tappe				exit 1;
3085b0f7b1bSOliver Tappe			fi
309aaeadfcbSAlex Smith
310c0e8cc1aSIngo Weinhold			targetArch=x86_gcc2
3115b0f7b1bSOliver Tappe			;;
3128b5934c9SIngo Weinhold	esac
31365ad1ba3SAlex Smith
314c0e8cc1aSIngo Weinhold	local bootLibgcc
315c0e8cc1aSIngo Weinhold	local bootLibSupCxx
31666a7f29fSJérôme Duval	local bootCxxHeaders
317c0e8cc1aSIngo Weinhold	case $gccMachine in
3184591ebc9SAlex Smith		x86_64-*)
31966a7f29fSJérôme Duval			# Boot loader is 32-bit, need the 32-bit libs and c++ config
32011ae3c5fSOliver Tappe			bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a`
321c0e8cc1aSIngo Weinhold			bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
32266a7f29fSJérôme Duval
32366a7f29fSJérôme Duval			local headersBase=$gccdir/../../../..
32466a7f29fSJérôme Duval			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
32566a7f29fSJérôme Duval			if [ ! -d $headers ]; then
32666a7f29fSJérôme Duval				headers=$headersBase/include/c++/$gccRawVersion
32766a7f29fSJérôme Duval			fi
32866a7f29fSJérôme Duval			bootCxxHeaders="$headers/$gccMachine/32"
3294591ebc9SAlex Smith			;;
330338b8dc3SIngo Weinhold	esac
331c0e8cc1aSIngo Weinhold
332c0e8cc1aSIngo Weinhold	# determine whether graphite loop optimization should/can be used
333c0e8cc1aSIngo Weinhold	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
334c0e8cc1aSIngo Weinhold	if [ -z "$useGraphite" ]; then
335c0e8cc1aSIngo Weinhold		useGraphite=$useGccGraphiteDefault
336c0e8cc1aSIngo Weinhold	fi
337c0e8cc1aSIngo Weinhold
338c0e8cc1aSIngo Weinhold	if [ "$useGraphite" != 0 ]; then
339c0e8cc1aSIngo Weinhold		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
340c0e8cc1aSIngo Weinhold		if [ $? != 0 ]; then
341c0e8cc1aSIngo Weinhold			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
342c0e8cc1aSIngo Weinhold			useGraphite=0
343c0e8cc1aSIngo Weinhold		fi
344c0e8cc1aSIngo Weinhold	fi
345c0e8cc1aSIngo Weinhold
346c0e8cc1aSIngo Weinhold	set_variable HAIKU_CPU_$targetArch $targetCpu
347c0e8cc1aSIngo Weinhold
348c0e8cc1aSIngo Weinhold	get_build_tool_path CC_$targetArch "$gcc"
34947320dd0SAugustin Cavalier	set_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch \
35047320dd0SAugustin Cavalier		`is_legacy_gcc $gccRawVersion`
351a7bddff1SJonathan Schleifer	set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
352c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
353c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
354c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
35566a7f29fSJérôme Duval	set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
35611ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
35711ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
358c0e8cc1aSIngo Weinhold	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
359c0e8cc1aSIngo Weinhold
360c0e8cc1aSIngo Weinhold	standard_gcc_settings_targetArch=$targetArch
361c0e8cc1aSIngo Weinhold}
362c0e8cc1aSIngo Weinhold
363c0e8cc1aSIngo Weinhold# set_variable
364c0e8cc1aSIngo Weinhold#
365c0e8cc1aSIngo Weinhold# Set the value of a variable.
366c0e8cc1aSIngo Weinhold#
367c0e8cc1aSIngo Weinholdset_variable()
368c0e8cc1aSIngo Weinhold{
369c0e8cc1aSIngo Weinhold	eval "$1=\"$2\""
370c0e8cc1aSIngo Weinhold}
371c0e8cc1aSIngo Weinhold
372c0e8cc1aSIngo Weinhold# get_variable
373c0e8cc1aSIngo Weinhold#
374c0e8cc1aSIngo Weinhold# Echo the value of a variable.
375c0e8cc1aSIngo Weinhold#
376c0e8cc1aSIngo Weinholdget_variable()
377c0e8cc1aSIngo Weinhold{
378c0e8cc1aSIngo Weinhold	eval "echo \${$1}"
37909c5682dSIngo Weinhold}
38009c5682dSIngo Weinhold
381338b8dc3SIngo Weinhold# set_default_value
382338b8dc3SIngo Weinhold#
383338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
384338b8dc3SIngo Weinhold#
385338b8dc3SIngo Weinholdset_default_value()
386338b8dc3SIngo Weinhold{
3870838a930SJérôme Duval	eval "$1=\${$1-$2}"
388338b8dc3SIngo Weinhold}
389338b8dc3SIngo Weinhold
390338b8dc3SIngo Weinhold# get_build_tool_path
391338b8dc3SIngo Weinhold#
392338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
393338b8dc3SIngo Weinhold#
394338b8dc3SIngo Weinholdget_build_tool_path()
395338b8dc3SIngo Weinhold{
396338b8dc3SIngo Weinhold	local var="HAIKU_$1"
39765706842SAugustin Cavalier	local varval="`get_variable $var`"
39865706842SAugustin Cavalier	local cmd="$2"
399d73993ffSAugustin Cavalier
400e042a53bSAugustin Cavalier	if [ ! -z "$varval" ]; then
401d73993ffSAugustin Cavalier		# this variable is already set (probably by user) so grab its contents
402e042a53bSAugustin Cavalier		cmd=$varval
403d73993ffSAugustin Cavalier	fi
404d73993ffSAugustin Cavalier
405d73993ffSAugustin Cavalier	local path=${cmd%% *}
406338b8dc3SIngo Weinhold
407338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
40865706842SAugustin Cavalier		# get absolute path from relative path
409a559f87aSFrançois Revol		local oldPwd="`pwd`"
410a559f87aSFrançois Revol		cd "`dirname "$path"`"
411a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
412338b8dc3SIngo Weinhold		cd $oldPwd
413338b8dc3SIngo Weinhold	else
4147fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
415d73993ffSAugustin Cavalier			echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
416338b8dc3SIngo Weinhold			exit 1
417338b8dc3SIngo Weinhold		}
418338b8dc3SIngo Weinhold	fi
419338b8dc3SIngo Weinhold
42065706842SAugustin Cavalier	if test "${cmd#* }" != "$cmd"; then
42165706842SAugustin Cavalier		# $cmd contains arguments, so preserve them (and only them)
42265706842SAugustin Cavalier		cmd=${cmd#* }
42365706842SAugustin Cavalier	else
42465706842SAugustin Cavalier		# $cmd does not contain arguments, so unset it
42565706842SAugustin Cavalier		cmd=
42665706842SAugustin Cavalier	fi
42765706842SAugustin Cavalier	eval "$var=\"$path $cmd\""
428338b8dc3SIngo Weinhold}
429338b8dc3SIngo Weinhold
430a5c952dbSAugustin Cavalier# check_native_xattrs
431a5c952dbSAugustin Cavalier#
432a5c952dbSAugustin Cavalier# Checks the host platform's support for extended attributes.
433a5c952dbSAugustin Cavalier# 0: no support, 1: only enough for xattr-ref, 2: full support
434a5c952dbSAugustin Cavalier#
435a5c952dbSAugustin Cavaliercheck_native_xattrs()
436a5c952dbSAugustin Cavalier{
437a5c952dbSAugustin Cavalier	local xattr_set=
438a5c952dbSAugustin Cavalier	local xattr_set_args=
439a5c952dbSAugustin Cavalier	local xattr_get=
440a5c952dbSAugustin Cavalier	local xattr_get_args=
441a5c952dbSAugustin Cavalier	case $HOST_PLATFORM in
442503ef6d4SAugustin Cavalier		haiku_host)
443503ef6d4SAugustin Cavalier			xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
444503ef6d4SAugustin Cavalier			xattr_get="catattr"; xattr_get_args="\$NAME"
445503ef6d4SAugustin Cavalier			;;
446a5c952dbSAugustin Cavalier		darwin)
447a5c952dbSAugustin Cavalier			xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
448a5c952dbSAugustin Cavalier			xattr_get="xattr"; xattr_get_args="-p \$NAME"
449a5c952dbSAugustin Cavalier			;;
450a5c952dbSAugustin Cavalier		freebsd)
451a5c952dbSAugustin Cavalier			xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
452a5c952dbSAugustin Cavalier			xattr_get="getextattr"; xattr_get_args="user \$NAME"
453a5c952dbSAugustin Cavalier			;;
454f6381021SAugustin Cavalier		linux)
455a5c952dbSAugustin Cavalier			xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
456a5c952dbSAugustin Cavalier			xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
457a5c952dbSAugustin Cavalier			;;
458a5c952dbSAugustin Cavalier		*)
459a5c952dbSAugustin Cavalier			return 0
460a5c952dbSAugustin Cavalier			;;
461a5c952dbSAugustin Cavalier	esac
462a5c952dbSAugustin Cavalier	if ! type $xattr_set >/dev/null 2>&1; then
463a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_set, assuming host has no extended attributes"
464a5c952dbSAugustin Cavalier		return 0
465a5c952dbSAugustin Cavalier	elif ! type $xattr_get >/dev/null 2>&1; then
466a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_get, assuming host has no extended attributes"
467a5c952dbSAugustin Cavalier		return 0
468a5c952dbSAugustin Cavalier	fi
469a5c952dbSAugustin Cavalier
47043f5f35aSAugustin Cavalier	mkdir -p "$outputDir"
471a5c952dbSAugustin Cavalier	echo "xattr test file" >"$outputDir/xattrtest"
472a5c952dbSAugustin Cavalier	local i=0
473a5c952dbSAugustin Cavalier	# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
474a5c952dbSAugustin Cavalier	# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
475a5c952dbSAugustin Cavalier	while [ $i -lt 2 ]; do
476a5c952dbSAugustin Cavalier		local j=0
477a5c952dbSAugustin Cavalier		while [ $j -lt 3 ]; do
478a5c952dbSAugustin Cavalier			NAME=attr$j
479a5c952dbSAugustin Cavalier			VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
480a5c952dbSAugustin Cavalier			if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
481a5c952dbSAugustin Cavalier				echo "$0: warning: could not generate test data for extended attributes"
482a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
483a5c952dbSAugustin Cavalier				return $i
484a5c952dbSAugustin Cavalier			elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
485a5c952dbSAugustin Cavalier					"$outputDir/xattrtest" >/dev/null 2>&1 ; then
486a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
487a5c952dbSAugustin Cavalier				return $i
488a5c952dbSAugustin Cavalier			fi
489a5c952dbSAugustin Cavalier			j=$((j+1))
490a5c952dbSAugustin Cavalier		done
491a5c952dbSAugustin Cavalier		i=$((i+1))
492a5c952dbSAugustin Cavalier	done
493a5c952dbSAugustin Cavalier	rm "$outputDir/xattrtest"
494a5c952dbSAugustin Cavalier	return 2
495a5c952dbSAugustin Cavalier}
496a5c952dbSAugustin Cavalier
497483b28e4SIngo Weinholdis_in_list()
498483b28e4SIngo Weinhold{
499483b28e4SIngo Weinhold	local element
500483b28e4SIngo Weinhold	for element in $2; do
501483b28e4SIngo Weinhold		if [ "$1" = "$element" ]; then
502483b28e4SIngo Weinhold			return 0
503483b28e4SIngo Weinhold		fi
504483b28e4SIngo Weinhold	done
505483b28e4SIngo Weinhold	return 1
506483b28e4SIngo Weinhold}
507483b28e4SIngo Weinhold
5087f9beaf1SOliver Tappe# check for --help or -h and show usage immediately
5097f9beaf1SOliver Tappeif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
5108b420c2fSOliver Tappe	usage; exit 0;
5118b420c2fSOliver Tappefi
5128b420c2fSOliver Tappe
513338b8dc3SIngo Weinhold# get cwd and the source directory
514338b8dc3SIngo WeinholdcurrentDir=`pwd`
5156e7c6fe5SIngo Weinholdcd `dirname "$0"`
516338b8dc3SIngo WeinholdsourceDir=`pwd`
5176e7c6fe5SIngo Weinholdcd "$currentDir"
518338b8dc3SIngo Weinhold
519a107d3b4SAugustin Cavalier# determine output directory
520a107d3b4SAugustin Cavalierif [ "$currentDir" = "$sourceDir" ]; then
521a107d3b4SAugustin Cavalier	outputDir=$currentDir/generated
522a107d3b4SAugustin Cavalierelse
523a107d3b4SAugustin Cavalier	outputDir=$currentDir
524a107d3b4SAugustin Cavalierfi
525a107d3b4SAugustin CavalierbuildOutputDir="$outputDir/build"
526a107d3b4SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
527a107d3b4SAugustin CavalierbuildConfigFile="$buildOutputDir/BuildConfig"
528a107d3b4SAugustin Cavalier
529a107d3b4SAugustin Cavalier# check for update request
530a107d3b4SAugustin Cavalierif [ "$1" = "--update" ]; then
531a107d3b4SAugustin Cavalier	if ! [ -e "$buildConfigFile" ]; then
532a107d3b4SAugustin Cavalier		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
533a107d3b4SAugustin Cavalier		exit 1
534a107d3b4SAugustin Cavalier	fi
535a107d3b4SAugustin Cavalier	# get last configure invocation and flags from BuildConfig and call ourselves with it
536a107d3b4SAugustin Cavalier	lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
537a107d3b4SAugustin Cavalier	lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
538a107d3b4SAugustin Cavalier	lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
539a107d3b4SAugustin Cavalier	lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
540a107d3b4SAugustin Cavalier	if [ -z "$lastConfig" ]; then
541a107d3b4SAugustin Cavalier		echo "$0 --update: The previous configure invocation was not properly" \
542a107d3b4SAugustin Cavalier			"encoded into '$buildConfigFile' - updating not possible."
543a107d3b4SAugustin Cavalier		exit 1
544a107d3b4SAugustin Cavalier	fi
5451d91b371SAugustin Cavalier	cd "$lastPwd"
546a107d3b4SAugustin Cavalier	if [ -n "$lastEnv" ]; then
547a107d3b4SAugustin Cavalier		export $lastEnv
548a107d3b4SAugustin Cavalier	fi
549a107d3b4SAugustin Cavalier	$lastConfig $lastArgs
550a107d3b4SAugustin Cavalier	exit $?
551a107d3b4SAugustin Cavalierfi
552a107d3b4SAugustin Cavalier
55355d267a4SFrançois Revol# backup the passed arguments
55455d267a4SFrançois RevolconfigureArgs="$@"
555825700d3SAugustin CavalierconfigurePath=$0
556825700d3SAugustin Cavalier
557825700d3SAugustin Cavalier# backup relevant environs
558825700d3SAugustin CavalierconfigureEnvirons=
559825700d3SAugustin Cavalierfor var in `env`; do
560825700d3SAugustin Cavalier	case "$var" in
5617d72ed01SAugustin Cavalier		CC\=*|HAIKU*\=*|JAMSHELL\=*)
562825700d3SAugustin Cavalier			configureEnvirons="$configureEnvirons $var"
563825700d3SAugustin Cavalier			;;
564825700d3SAugustin Cavalier	esac
565825700d3SAugustin Cavalierdone
56655d267a4SFrançois Revol
567a107d3b4SAugustin Cavalier# ensure umask is not too restrictive
56802f3646aSAugustin Cavalierif [ `umask` -gt 22 ]; then
56902f3646aSAugustin Cavalier	echo Your umask is too restrictive "(should be <= 0022;" is actually `umask`")"
57002f3646aSAugustin Cavalier	echo
57102f3646aSAugustin Cavalier	echo Additionally, if the source tree was cloned with a too-restrictive umask,
57202f3646aSAugustin Cavalier	echo you will need to run \"git checkout\" again to fix this.
573a107d3b4SAugustin Cavalier	exit 1
574a107d3b4SAugustin Cavalierfi
575a107d3b4SAugustin Cavalier
5767c4641d0SOliver Tappe# internal default parameter values
577022fa244SIngo Weinhold#
57852a38012Sejakowatzplatform=`uname`
5795abd9a46SIngo WeinholdplatformMachine=`uname  -m`
580c0e8cc1aSIngo WeinholdtargetArchs=
581338b8dc3SIngo WeinholdbuildCrossTools=
58229ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
58360d8d8fcSIngo WeinholdbuildCrossToolsJobs=
584c2b76f7fSJonathan SchleiferuseClang=0
585c0e8cc1aSIngo WeinholduseGccGraphiteDefault=0
586c0e8cc1aSIngo WeinholdunknownArchIndex=1
587483b28e4SIngo WeinholdhaikuTargetArchs=
5884da6cf84SFrançois RevolgdbSources=
5897c4641d0SOliver Tappe
59063701e7dSOliver Tappeif [ -z "$CC" ]; then
59163701e7dSOliver Tappe	CC=gcc
59263701e7dSOliver Tappefi
59363701e7dSOliver Tappe
5942a1cc90eSJohn Scipione# detect the build platform
5952a1cc90eSJohn Scipionecase "${platform}" in
5962a1cc90eSJohn Scipione	Darwin)  HOST_PLATFORM=darwin ;;
5972a1cc90eSJohn Scipione	FreeBSD) HOST_PLATFORM=freebsd
5982a1cc90eSJohn Scipione	         if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
5992a1cc90eSJohn Scipione	         	echo Unsupported platform: FreeBSD ${platformMachine}
6002a1cc90eSJohn Scipione	         	exit 1
6012a1cc90eSJohn Scipione	         fi ;;
6022a1cc90eSJohn Scipione	Haiku)   HOST_PLATFORM=haiku_host ;;
6032a1cc90eSJohn Scipione	Linux)   HOST_PLATFORM=linux ;;
6042a1cc90eSJohn Scipione	OpenBSD) HOST_PLATFORM=openbsd ;;
6052a1cc90eSJohn Scipione	*)       echo Unsupported platform: ${platform}
6062a1cc90eSJohn Scipione	         exit 1 ;;
6072a1cc90eSJohn Scipioneesac
6082a1cc90eSJohn Scipione
6092a1cc90eSJohn Scipionecase $HOST_PLATFORM in
6102a1cc90eSJohn Scipione	darwin|freebsd|openbsd) statCmd='stat -f' ;;
6112a1cc90eSJohn Scipione	*)                      statCmd='stat -c' ;;
6122a1cc90eSJohn Scipioneesac
6132a1cc90eSJohn Scipione
6142a1cc90eSJohn Scipione# ensure git checkout was not done with a restrictive umask
6152a1cc90eSJohn Scipioneif [ `$statCmd '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
6162a1cc90eSJohn Scipione	echo "The source tree was cloned with a umask > 0022. It seems you"
6172a1cc90eSJohn Scipione	echo have already corrected your umask, but not re-checked-out the
6182a1cc90eSJohn Scipione	echo source tree. Try running:
6192a1cc90eSJohn Scipione	echo "	git checkout --force"
6202a1cc90eSJohn Scipione	echo to fix this problem.
6212a1cc90eSJohn Scipione	exit 1
6222a1cc90eSJohn Scipionefi
6232a1cc90eSJohn Scipione
6247c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
6257c4641d0SOliver Tappe#
62663701e7dSOliver TappeHOST_GCC_RAW_VERSION=`$CC -dumpversion`
62747320dd0SAugustin CavalierHOST_CC_IS_LEGACY_GCC=`is_legacy_gcc $HOST_GCC_RAW_VERSION`
62863701e7dSOliver TappeHOST_GCC_MACHINE=`$CC -dumpmachine`
62976fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
6307c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
6317c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
6327c4641d0SOliver TappeTARGET_PLATFORM=haiku
6337c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
6347986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
635fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR=
636fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR_REF=
6372ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY=0
638f04f7042SNiels Sascha ReedijkHOST_EXTENDED_REGEX_SED="sed -r"
63963701e7dSOliver TappeHOST_GCC_LD=`$CC -print-prog-name=ld`
64063701e7dSOliver TappeHOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
6412a5d0aafSIngo WeinholdHOST_SHA256=
642e173a1ecSIngo WeinholdHOST_HAIKU_PORTER=
643e173a1ecSIngo WeinholdHAIKU_PORTS=
644e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS=
645c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP=0
646aa2e5ecaSOliver TappeHAIKU_NO_DOWNLOADS=0
6472a5d0aafSIngo Weinhold
648c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS=
649c0e8cc1aSIngo Weinhold
650a04a520bSJonathan Schleiferset_default_value HAIKU_NASM		nasm
651c0e8cc1aSIngo Weinhold
6523942ca0dSIngo Weinholdif sha256sum < /dev/null > /dev/null 2>&1; then
6532a5d0aafSIngo Weinhold	HOST_SHA256=sha256sum
6543942ca0dSIngo Weinholdelif sha256 < /dev/null > /dev/null 2>&1; then
6552a5d0aafSIngo Weinhold	HOST_SHA256="sha256 -q"
656b5a871b1SNiels Sascha Reedijkelif shasum < /dev/null > /dev/null 2>&1; then
657b5a871b1SNiels Sascha Reedijk	HOST_SHA256="shasum -a 256"
6582a5d0aafSIngo Weinholdelse
6592a5d0aafSIngo Weinhold	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
6602a5d0aafSIngo Weinhold	exit 1
6612a5d0aafSIngo Weinholdfi
662338b8dc3SIngo Weinhold
66384edb1a1SAxel DörflerhaikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
664a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
665af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
666483b28e4SIngo WeinholdsupportedTargetArchs="
667483b28e4SIngo Weinhold	arm
668fb4cc984SAugustin Cavalier	arm64
669483b28e4SIngo Weinhold	m68k
670483b28e4SIngo Weinhold	ppc
6715bd0fbd1SAlexander von Gluck IV	riscv64
672f23db0edSPulkoMandy	sparc
673483b28e4SIngo Weinhold	x86
674483b28e4SIngo Weinhold	x86_64
675483b28e4SIngo Weinhold	x86_gcc2
676483b28e4SIngo Weinhold	"
677af4bf973SOliver Tappe
678022fa244SIngo Weinhold# parse parameters
679022fa244SIngo Weinhold#
68020ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
681022fa244SIngo Weinhold	case "$1" in
682e173a1ecSIngo Weinhold		--bootstrap)
683e173a1ecSIngo Weinhold			assertparams "$1" 3 $#
684e173a1ecSIngo Weinhold			HOST_HAIKU_PORTER="`absolute_path $2`"
685e173a1ecSIngo Weinhold			HAIKU_PORTS_CROSS="`absolute_path $3`"
686e173a1ecSIngo Weinhold			HAIKU_PORTS="`absolute_path $4`"
687c9dd05ffSJonathan Schleifer			HAIKU_IS_BOOTSTRAP=1
688c9dd05ffSJonathan Schleifer			HAIKU_NO_DOWNLOADS=1
689502882dbSJessica Hamilton			check_file_exists "$HOST_HAIKU_PORTER" || (
690502882dbSJessica Hamilton				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
69139d444a3SArvind S Raj				exit 1
69239d444a3SArvind S Raj			)
69339d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS" || (
69439d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS" >&2
69539d444a3SArvind S Raj				exit 1
69639d444a3SArvind S Raj			)
69739d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS_CROSS" || (
69839d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
69939d444a3SArvind S Raj				exit 1
70039d444a3SArvind S Raj			)
701e173a1ecSIngo Weinhold			shift 4
702e173a1ecSIngo Weinhold			;;
70314d8c772SAlexander von Gluck IV		--cross-tools-source)
70414d8c772SAlexander von Gluck IV			assertparam "$1" $#
70514d8c772SAlexander von Gluck IV			buildCrossTools=$2
70614d8c772SAlexander von Gluck IV			shift 2
70714d8c772SAlexander von Gluck IV			;;
708c0e8cc1aSIngo Weinhold		--build-cross-tools)
709c0e8cc1aSIngo Weinhold			assertparam "$1" $#
710c0e8cc1aSIngo Weinhold			targetArch=$2
711c0e8cc1aSIngo Weinhold			shift 2
712c0e8cc1aSIngo Weinhold			case "$targetArch" in
713c0e8cc1aSIngo Weinhold				x86_gcc2)	targetMachine=i586-pc-haiku;;
714c0e8cc1aSIngo Weinhold				x86)		targetMachine=i586-pc-haiku;;
715c0e8cc1aSIngo Weinhold				x86_64)		targetMachine=x86_64-unknown-haiku;;
716c0e8cc1aSIngo Weinhold				ppc)		targetMachine=powerpc-apple-haiku;;
717c0e8cc1aSIngo Weinhold				m68k)		targetMachine=m68k-unknown-haiku;;
718c0e8cc1aSIngo Weinhold				arm)		targetMachine=arm-unknown-haiku;;
7191f52c921SJaroslaw Pelczar				arm64)		targetMachine=aarch64-unknown-haiku;;
7205bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
7215629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
722c0e8cc1aSIngo Weinhold				*)
723101564e4SAugustin Cavalier					echo "Unsupported target architecture: $targetArch" >&2
724c0e8cc1aSIngo Weinhold					exit 1
725c0e8cc1aSIngo Weinhold					;;
726c0e8cc1aSIngo Weinhold			esac
727c0e8cc1aSIngo Weinhold			set_variable buildCrossToolsMachine_$targetArch $targetMachine
728c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
7299b0dd528SIngo Weinhold			;;
7309b0dd528SIngo Weinhold		--cross-tools-prefix)
7319b0dd528SIngo Weinhold			assertparam "$1" $#
732c0e8cc1aSIngo Weinhold			targetArch=unknown${unknownArchIndex}
733c0e8cc1aSIngo Weinhold			set_variable crossToolsPrefix_$targetArch "$2"
734c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
735d68208faSMatt Madia			unknownArchIndex=$(($unknownArchIndex + 1))
7369b0dd528SIngo Weinhold			shift 2
7379b0dd528SIngo Weinhold			;;
738a66c32ddSIngo Weinhold		--distro-compatibility)
7399b0dd528SIngo Weinhold			assertparam "$1" $#
7407c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
7417c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
742a66c32ddSIngo Weinhold				official)	;;
743a66c32ddSIngo Weinhold				compatible)	;;
744a66c32ddSIngo Weinhold				default)	;;
745a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
7467c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
747a66c32ddSIngo Weinhold							exit 1;;
748a66c32ddSIngo Weinhold			esac
7499b0dd528SIngo Weinhold			shift 2
7509b0dd528SIngo Weinhold			;;
7512ebcd86dSIngo Weinhold		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
75276fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
7537c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
75460d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
755aa2e5ecaSOliver Tappe		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
756483b28e4SIngo Weinhold		--target-arch)
757483b28e4SIngo Weinhold			assertparam "$1" $#
758483b28e4SIngo Weinhold			targetArch=$2
759483b28e4SIngo Weinhold			shift 2
760483b28e4SIngo Weinhold			if [ ! "$platform" = Haiku ]; then
761483b28e4SIngo Weinhold				echo "--target-arch can only be specified on Haiku." >&2
762483b28e4SIngo Weinhold				exit 1
763483b28e4SIngo Weinhold			fi
764483b28e4SIngo Weinhold			is_in_list "$targetArch" "$supportedTargetArchs" || (
765483b28e4SIngo Weinhold				echo "Unsupported target architecture: \"$targetArch\"" >&2
766483b28e4SIngo Weinhold				exit 1
767483b28e4SIngo Weinhold			)
768483b28e4SIngo Weinhold			haikuTargetArchs="$haikuTargetArchs $targetArch"
769483b28e4SIngo Weinhold			;;
770d73993ffSAugustin Cavalier		--use-clang)
771d73993ffSAugustin Cavalier			assertparam "$1" $#
772d73993ffSAugustin Cavalier			targetArch=$2
773d73993ffSAugustin Cavalier			useClang=1
774d73993ffSAugustin Cavalier			case "$targetArch" in
775d73993ffSAugustin Cavalier				x86)		targetMachine=i586-pc-haiku;;
776d73993ffSAugustin Cavalier				x86_64)		targetMachine=x86_64-unknown-haiku;;
777d9f698eaSAugustin Cavalier				ppc)		targetMachine=powerpc-apple-haiku;;
77820dbf032SAlexander von Gluck IV				arm)		targetMachine=arm-unknown-haiku;;
7791f52c921SJaroslaw Pelczar				arm64)		targetMachine=aarch64-unknown-haiku;;
7805bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
7815629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
782d73993ffSAugustin Cavalier				*)
783d73993ffSAugustin Cavalier					echo "Unsupported target architecture: $2" >&2
784d73993ffSAugustin Cavalier					exit 1
785d73993ffSAugustin Cavalier					;;
786d73993ffSAugustin Cavalier			esac
78765706842SAugustin Cavalier			get_build_tool_path clang clang
78836f28382SAugustin Cavalier			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
78936f28382SAugustin Cavalier					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
79065706842SAugustin Cavalier				set_variable crossToolsPrefix_$targetArch llvm-
79165706842SAugustin Cavalier			fi
7925924b6e4SAugustin Cavalier			clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
793583db6f5SAlexander von Gluck IV			if [ `echo $clangVersion | cut -d'.' -f1` -lt 7 ]; then
7945924b6e4SAugustin Cavalier				echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
7955924b6e4SAugustin Cavalier				echo "Please install a newer version."
7965924b6e4SAugustin Cavalier				exit 1
7975924b6e4SAugustin Cavalier			fi
798d73993ffSAugustin Cavalier			targetArchs="$targetArchs $targetArch"
799d73993ffSAugustin Cavalier			shift 2
800d73993ffSAugustin Cavalier			;;
8017c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
802c0e8cc1aSIngo Weinhold		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
8037986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
804fc2c93fbSAugustin Cavalier		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
805fc2c93fbSAugustin Cavalier		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
8064da6cf84SFrançois Revol		--with-gdb)	gdbSources=$2; shift 2;;
80704be20a7SJérôme Duval		--use-stack-protector)	HAIKU_USE_STACK_PROTECTOR=1; shift 1;;
808*31f27c4dSAlexander von Gluck IV		--efi-signing-key)
809*31f27c4dSAlexander von Gluck IV			assertparam "$1" $#
810*31f27c4dSAlexander von Gluck IV			HAIKU_EFI_SIGNING_KEY="$2"
811*31f27c4dSAlexander von Gluck IV			shift 2
812*31f27c4dSAlexander von Gluck IV			;;
813022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
814022fa244SIngo Weinhold	esac
815022fa244SIngo Weinholddone
816022fa244SIngo Weinhold
8170962132cSAlex Smith# check for case-sensitive filesystem
8180962132cSAlex Smithmkdir haikuCaseTest 2>/dev/null
8190962132cSAlex Smithmkdir haikucasetest 2>/dev/null
8200962132cSAlex SmithcaseInsensitive=$?
82197f5a0bdSAlex Smithrmdir haikuCaseTest haikucasetest 2>/dev/null
8220962132cSAlex Smithif [ $caseInsensitive != 0 ]; then
8233ecc5287SMichael Lotz	echo "You need a case-sensitive file-system to build Haiku."
8240962132cSAlex Smith	if [ $HOST_PLATFORM = "darwin" ]; then
8257a05e252SJohn Scipione		echo "You can create a case-sensitive disk image using Disk Utility."
8263ecc5287SMichael Lotz	fi
8270962132cSAlex Smith	exit 1
8283ecc5287SMichael Lotzfi
8293ecc5287SMichael Lotz
830a5c952dbSAugustin Cavalier# check xattr support
831503ef6d4SAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
832a5c952dbSAugustin Cavalier	check_native_xattrs
833a5c952dbSAugustin Cavalier	attrSupport=$?
834fc2c93fbSAugustin Cavalier	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
835fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR=1
836a5c952dbSAugustin Cavalier	elif [ $attrSupport = 1 ]; then
837fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR_REF=1
838a5c952dbSAugustin Cavalier	fi
839a5c952dbSAugustin Cavalierfi
840fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
841fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
842a5c952dbSAugustin Cavalier
843f04f7042SNiels Sascha Reedijk# determine how to invoke sed with extended regexp support for non-GNU sed
844f04f7042SNiels Sascha Reedijkif [ $HOST_PLATFORM = "darwin" ]; then
845f04f7042SNiels Sascha Reedijk	HOST_EXTENDED_REGEX_SED="sed -E"
846f04f7042SNiels Sascha Reedijkfi
847f04f7042SNiels Sascha Reedijk
8487d72ed01SAugustin Cavalier# pick a JAMSHELL
8497d72ed01SAugustin Cavalierif [ "$JAMSHELL" = "" ]; then
8507d72ed01SAugustin Cavalier	if check_file_exists /bin/dash; then
8517d72ed01SAugustin Cavalier		JAMSHELL=/bin/dash
8527d72ed01SAugustin Cavalier	else
8537d72ed01SAugustin Cavalier		JAMSHELL=/bin/sh
8547d72ed01SAugustin Cavalier	fi
8557d72ed01SAugustin Cavalierfi
8567d72ed01SAugustin Cavalierif ! $JAMSHELL -c true; then
8577d72ed01SAugustin Cavalier	echo "$JAMSHELL does not work! Please specify a working JAMSHELL."
8587d72ed01SAugustin Cavalier	exit 1
8597d72ed01SAugustin Cavalierfi
8607d72ed01SAugustin Cavalier
8612b200496SAugustin Cavalier# locate python
8622b200496SAugustin Cavalierif python3 --version < /dev/null > /dev/null 2>&1; then
86317dc34acSAndrew Lindesay	HOST_PYTHON="python3"
8642b200496SAugustin Cavalierelif python --version < /dev/null > /dev/null 2>&1; then
86517dc34acSAndrew Lindesay	HOST_PYTHON="python"
86617dc34acSAndrew Lindesayelse
86717dc34acSAndrew Lindesay	echo "a python interpreter is required"
86817dc34acSAndrew Lindesay	exit 1
86917dc34acSAndrew Lindesayfi
87017dc34acSAndrew Lindesay
871cb721c59SFrançois Revol# check if nasm can actually output ELF files
872cb721c59SFrançois Revol# (the stock version in OSX can't)
873cb721c59SFrançois Revol# XXX: should probably only test for x86* arch
8743e6c09cdSAdrien Destuguesif [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
875cb721c59SFrançois Revol	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
876cb721c59SFrançois Revol	if [ $HOST_PLATFORM = "darwin" ]; then
877cb721c59SFrançois Revol		echo "You can install it from Mac Ports."
878cb721c59SFrançois Revol		echo "Mac Ports is available at: http://www.macports.org/"
879cb721c59SFrançois Revol	fi
880cb721c59SFrançois Revol	exit 1
881cb721c59SFrançois Revolfi
882cb721c59SFrançois Revol
883338b8dc3SIngo Weinhold# create output directory
8846e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
885338b8dc3SIngo Weinhold
8862ebcd86dSIngo Weinholdif [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
8872ebcd86dSIngo Weinhold	invalidCommand=$sourceDir/build/scripts/host_build_only
8882ebcd86dSIngo Weinhold	HAIKU_AR=$invalidCommand
8892ebcd86dSIngo Weinhold	HAIKU_CC=$invalidCommand
8902ebcd86dSIngo Weinhold	HAIKU_LD=$invalidCommand
8912ebcd86dSIngo Weinhold	HAIKU_OBJCOPY=$invalidCommand
8922ebcd86dSIngo Weinhold	HAIKU_RANLIB=$invalidCommand
8932ebcd86dSIngo Weinhold	HAIKU_ELFEDIT=$invalidCommand
894d6f80927SJonathan Schleifer	HAIKU_NASM=$invalidCommand
8952ebcd86dSIngo Weinhold	HAIKU_STRIP=$invalidCommand
8962ebcd86dSIngo Weinholdelse
897483b28e4SIngo Weinhold	# On Haiku determine target architectures and tools automatically.
898c0e8cc1aSIngo Weinhold	if [ -z "$targetArchs" ]; then
899483b28e4SIngo Weinhold		if [ $HOST_PLATFORM != haiku_host ]; then
900483b28e4SIngo Weinhold			echo "Please specify the build tools to use or build (via" \
901eaef83a9SJeroen Oortwijn				"--cross-tools-prefix or --build-cross-tools) or specify a" \
902483b28e4SIngo Weinhold				"host-only build (--host-only)." >&2
9037f9beaf1SOliver Tappe			echo "For more info, invoke $0 --help"
904483b28e4SIngo Weinhold			exit 1
905483b28e4SIngo Weinhold		fi
906483b28e4SIngo Weinhold
907483b28e4SIngo Weinhold		# determine primary architecture
908dda53eaeSIngo Weinhold		targetArch=`package list -i /system/packages/haiku-*.hpkg \
909483b28e4SIngo Weinhold			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
910483b28e4SIngo Weinhold		is_in_list "$targetArch" "$supportedTargetArchs" || (
911483b28e4SIngo Weinhold			echo "Unsupported target architecture: \"$targetArch\"" >&2
912483b28e4SIngo Weinhold			exit 1
913483b28e4SIngo Weinhold		)
914c0e8cc1aSIngo Weinhold		targetArchs=$targetArch
915483b28e4SIngo Weinhold
916c0e8cc1aSIngo Weinhold		set_default_value HAIKU_AR_$targetArch			ar
917c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CC_$targetArch			gcc
918c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LD_$targetArch			ld
919c0e8cc1aSIngo Weinhold		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
920c0e8cc1aSIngo Weinhold		set_default_value HAIKU_RANLIB_$targetArch		ranlib
921c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
922c0e8cc1aSIngo Weinhold		set_default_value HAIKU_STRIP_$targetArch		strip
923483b28e4SIngo Weinhold
924483b28e4SIngo Weinhold		# determine secondary architectures
925483b28e4SIngo Weinhold		for targetArch in $supportedTargetArchs; do
92680262a91SMatt Madia			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
927483b28e4SIngo Weinhold				targetArchs="$targetArchs $targetArch"
928483b28e4SIngo Weinhold				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
929483b28e4SIngo Weinhold				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
930483b28e4SIngo Weinhold				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
931483b28e4SIngo Weinhold				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
932483b28e4SIngo Weinhold				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
933483b28e4SIngo Weinhold				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
934483b28e4SIngo Weinhold				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
935483b28e4SIngo Weinhold			fi
936483b28e4SIngo Weinhold		done
937483b28e4SIngo Weinhold
938483b28e4SIngo Weinhold		# The target architectures might have been specified explicitly.
939483b28e4SIngo Weinhold		if [ -n "$haikuTargetArchs" ]; then
940483b28e4SIngo Weinhold			for targetArch in $haikuTargetArchs; do
941483b28e4SIngo Weinhold				is_in_list "$targetArch" "$targetArchs" || (
942483b28e4SIngo Weinhold					echo "Unsupported target architecture: \"$targetArch\"." \
943483b28e4SIngo Weinhold						"Only native architectures of the host platform can" \
944483b28e4SIngo Weinhold						"be specified." >&2
945483b28e4SIngo Weinhold					exit 1
946483b28e4SIngo Weinhold				)
947483b28e4SIngo Weinhold			done
948483b28e4SIngo Weinhold			targetArchs="$haikuTargetArchs"
949483b28e4SIngo Weinhold		fi
950c0e8cc1aSIngo Weinhold	fi
951c0e8cc1aSIngo Weinhold
95278b22458SAugustin Cavalier	if [ "$targetArchs" = " x86_gcc2" ]; then
95378b22458SAugustin Cavalier		echo "Building a GCC2-only Haiku is no longer supported."
95478b22458SAugustin Cavalier		echo "Please configure the secondary architecture."
95578b22458SAugustin Cavalier		exit 1
95678b22458SAugustin Cavalier	fi
95778b22458SAugustin Cavalier
95868ccc989SIngo Weinhold	isPrimaryArch=1
959c0e8cc1aSIngo Weinhold	for targetArch in $targetArchs; do
9606c5fcb4fSAugustin Cavalier		# Note: targetArch is "unknown<n>" at this point if a cross-tools
961c0e8cc1aSIngo Weinhold		# prefix was specified. The standard_gcc_settings call below will get
962c0e8cc1aSIngo Weinhold		# the actual architecture.
963c0e8cc1aSIngo Weinhold
96432b50a88SAugustin Cavalier		if test "${HAIKU_PACKAGING_ARCHS#*$targetArch\b}" != "$HAIKU_PACKAGING_ARCHS"; then
9656c5fcb4fSAugustin Cavalier			# somehow we wound up with a duplicate arch; skip this one
9666c5fcb4fSAugustin Cavalier			continue
9676c5fcb4fSAugustin Cavalier		fi
9686c5fcb4fSAugustin Cavalier
969c0e8cc1aSIngo Weinhold		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
970c0e8cc1aSIngo Weinhold
971338b8dc3SIngo Weinhold		# build cross tools from sources
972c0e8cc1aSIngo Weinhold		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
973c0e8cc1aSIngo Weinhold			crossToolsDir="$outputDir/cross-tools-$targetArch"
974c0e8cc1aSIngo Weinhold			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
975c0e8cc1aSIngo Weinhold			script="$buildCrossToolsScript"
9768304ec7cSIngo Weinhold			scriptArgs=
977c0e8cc1aSIngo Weinhold			if [ $targetArch != x86_gcc2 ]; then
9788304ec7cSIngo Weinhold				script="${script}_gcc4"
9798304ec7cSIngo Weinhold				scriptArgs="$targetMachine"
9801e93288eSJérôme Duval				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
9811e93288eSJérôme Duval					$useGccGraphiteDefault
982c0e8cc1aSIngo Weinhold			fi
98368ccc989SIngo Weinhold			secondaryArch=
98468ccc989SIngo Weinhold			if [ -z "$isPrimaryArch" ]; then
98568ccc989SIngo Weinhold				secondaryArch=$targetArch
98668ccc989SIngo Weinhold			fi
98786de8c37SIngo Weinhold
98886de8c37SIngo Weinhold			case $HOST_PLATFORM in
98986de8c37SIngo Weinhold				freebsd|openbsd)	MAKE=gmake;;
99086de8c37SIngo Weinhold				*)					MAKE=make;;
99186de8c37SIngo Weinhold			esac
99286de8c37SIngo Weinhold
9931f839e89Swaddlesplash			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
99486de8c37SIngo Weinhold				MAKE=$MAKE \
99568ccc989SIngo Weinhold				SECONDARY_ARCH=$secondaryArch \
996c0e8cc1aSIngo Weinhold				HAIKU_USE_GCC_GRAPHITE=`get_variable \
997c0e8cc1aSIngo Weinhold					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
998b3ece905SJérôme Duval				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
9994da6cf84SFrançois Revol				HAIKU_USE_GDB="$gdbSources" \
10008304ec7cSIngo Weinhold				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
10018304ec7cSIngo Weinhold					"$crossToolsDir" $buildCrossToolsJobs || exit 1
1002825700d3SAugustin Cavalier			else
1003825700d3SAugustin Cavalier				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
1004825700d3SAugustin Cavalier			fi
1005c0e8cc1aSIngo Weinhold			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
1006338b8dc3SIngo Weinhold		fi
1007338b8dc3SIngo Weinhold
1008c0e8cc1aSIngo Weinhold		# prepare gcc settings and get the actual target architecture
1009a7bddff1SJonathan Schleifer		if [ $useClang = 1 ]; then
1010c44472c5SAugustin Cavalier			gcc="$HAIKU_clang -target ${targetMachine}"
1011ddf7f643SAugustin Cavalier			if [ ! -z "${crossToolsPrefix}" ]; then
1012ddf7f643SAugustin Cavalier				gcc="$gcc -B ${crossToolsPrefix}"
1013ddf7f643SAugustin Cavalier			fi
10141f6fe055SAugustin Cavalier
10151f6fe055SAugustin Cavalier			# Clang's compiler intrinsics are not compatible with GCC's or even
10161f6fe055SAugustin Cavalier			# across versions of Clang, so we must collect them for use in the build.
10171f6fe055SAugustin Cavalier			mkdir -p "$outputDir/clang_headers" || exit 1
101820c61bb7SAugustin Cavalier			clangHeadersDir=`$gcc -print-resource-dir`/include/
101920c61bb7SAugustin Cavalier			case $targetArch in
102020c61bb7SAugustin Cavalier				x86*) cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1 ;;
102120c61bb7SAugustin Cavalier				ppc*) cp $clangHeadersDir/*altivec* "$outputDir/clang_headers" || exit 1 ;;
102220c61bb7SAugustin Cavalier				arm*) cp $clangHeadersDir/*arm* "$outputDir/clang_headers" || exit 1 ;;
102320c61bb7SAugustin Cavalier			esac
1024d73993ffSAugustin Cavalier		elif [ -z "${crossToolsPrefix}" ]; then
1025d73993ffSAugustin Cavalier			gcc=`get_variable HAIKU_CC_$targetArch`
1026a7bddff1SJonathan Schleifer		else
1027c0e8cc1aSIngo Weinhold			gcc="${crossToolsPrefix}gcc"
1028a7bddff1SJonathan Schleifer		fi
1029c0e8cc1aSIngo Weinhold		standard_gcc_settings "$gcc"
1030c0e8cc1aSIngo Weinhold		targetArch=$standard_gcc_settings_targetArch
1031338b8dc3SIngo Weinhold
1032c0e8cc1aSIngo Weinhold		# set default values for flags
1033c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CPPFLAGS_$targetArch	""
1034c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CCFLAGS_$targetArch		""
1035c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CXXFLAGS_$targetArch	""
1036252e4f62SAugustin Cavalier		set_default_value HAIKU_LINKFLAGS_$targetArch	""
1037c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LDFLAGS_$targetArch		""
1038241b61a7SAugustin Cavalier		set_default_value HAIKU_ARFLAGS_$targetArch		cru
1039c0e8cc1aSIngo Weinhold		set_default_value HAIKU_UNARFLAGS_$targetArch	x
1040338b8dc3SIngo Weinhold
1041c0e8cc1aSIngo Weinhold		# Override the cross tools variables, if the tools were built or a
1042c0e8cc1aSIngo Weinhold		# prefix was specified.
10431c307243SAugustin Cavalier		if [ $useClang = 1 ]; then
10441c307243SAugustin Cavalier			get_build_tool_path LD_$targetArch ld.lld
10451c307243SAugustin Cavalier			get_build_tool_path ELFEDIT_$targetArch elfedit
10461c307243SAugustin Cavalier		elif [ -n "$crossToolsPrefix" ]; then
1047c0e8cc1aSIngo Weinhold			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
1048dbaef850SAugustin Cavalier			if [ `get_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch` -eq 0 ]; then
1049dbaef850SAugustin Cavalier				get_build_tool_path ELFEDIT_$targetArch ${crossToolsPrefix}elfedit
1050dbaef850SAugustin Cavalier			fi
105152a38012Sejakowatz		fi
10521c307243SAugustin Cavalier		if [ -n "$crossToolsPrefix" ]; then
10531c307243SAugustin Cavalier			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
10541c307243SAugustin Cavalier			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
10551c307243SAugustin Cavalier			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
10561c307243SAugustin Cavalier			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
10571c307243SAugustin Cavalier		fi
105852a38012Sejakowatz
1059ef57df3dSIngo Weinhold		# check whether the Haiku compiler really targets Haiku
1060c0e8cc1aSIngo Weinhold		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
1061c0e8cc1aSIngo Weinhold		case "$targetMachine" in
1062eedc3d0bSIngo Weinhold			*-*-haiku)	;;
1063c0e8cc1aSIngo Weinhold			*)
1064c0e8cc1aSIngo Weinhold				echo The compiler specified as Haiku target compiler is not a \
1065c0e8cc1aSIngo Weinhold				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
1066eedc3d0bSIngo Weinhold				echo compiler: $HAIKU_CC
1067c0e8cc1aSIngo Weinhold				echo compiler is configured for target: $targetMachine
1068eedc3d0bSIngo Weinhold				exit 1 ;;
1069eedc3d0bSIngo Weinhold		esac
1070c0e8cc1aSIngo Weinhold
1071c0e8cc1aSIngo Weinhold		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
107268ccc989SIngo Weinhold		isPrimaryArch=
1073c0e8cc1aSIngo Weinhold	done
10742ebcd86dSIngo Weinholdfi
1075eedc3d0bSIngo Weinhold
107652a38012Sejakowatz# Generate BuildConfig
10777c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
1078825700d3SAugustin Cavalier# -- WARNING --
1079825700d3SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1080825700d3SAugustin Cavalier# overwritten the next time configure is run.
1081825700d3SAugustin Cavalier#
1082825700d3SAugustin Cavalier#d ${currentDir}
1083825700d3SAugustin Cavalier#c ${configurePath}
1084825700d3SAugustin Cavalier#e ${configureEnvirons}
1085825700d3SAugustin Cavalier#a ${configureArgs}
108652a38012Sejakowatz
10877c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
1088b57e7df9SAugustin CavalierTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
1089b57e7df9SAugustin CavalierHAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
1090338b8dc3SIngo Weinhold
1091b57e7df9SAugustin CavalierHAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
109276fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES		?= "${HAIKU_INCLUDE_SOURCES}" ;
10937c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY		?= "${HAIKU_INCLUDE_3RDPARTY}" ;
10947c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY	?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
1095b57e7df9SAugustin Cavalier
10967c4641d0SOliver TappeHAIKU_USE_GCC_PIPE			?= "${HAIKU_USE_GCC_PIPE}" ;
10977986925fSIngo WeinholdHAIKU_HOST_USE_32BIT		?= "${HAIKU_HOST_USE_32BIT}" ;
10987986925fSIngo WeinholdHAIKU_HOST_USE_XATTR		?= "${HAIKU_HOST_USE_XATTR}" ;
1099bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF	?= "${HAIKU_HOST_USE_XATTR_REF}" ;
11002ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY		?= "${HAIKU_HOST_BUILD_ONLY}" ;
1101eccc7665SIngo Weinhold
110234fef46bSAugustin CavalierJAMSHELL					?= ${JAMSHELL} -e -c ;
11037d72ed01SAugustin Cavalier
1104b57e7df9SAugustin CavalierHOST_CC						?= ${CC} ;
110547320dd0SAugustin CavalierHOST_CC_IS_LEGACY_GCC		?= ${HOST_CC_IS_LEGACY_GCC} ;
11067c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
11077c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
11087c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
1109b57e7df9SAugustin CavalierHOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
11102a5d0aafSIngo WeinholdHOST_SHA256					?= ${HOST_SHA256} ;
111117dc34acSAndrew LindesayHOST_PYTHON					?= ${HOST_PYTHON} ;
1112b57e7df9SAugustin CavalierHAIKU_NASM					?= ${HAIKU_NASM} ;
1113b57e7df9SAugustin Cavalier
11141d91b371SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR	?= "${HAIKU_BUILD_ATTRIBUTES_DIR}" ;
11158b5934c9SIngo Weinhold
1116e173a1ecSIngo WeinholdHOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1117e173a1ecSIngo WeinholdHAIKU_PORTS					?= ${HAIKU_PORTS} ;
1118e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1119c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1120e173a1ecSIngo Weinhold
1121*31f27c4dSAlexander von Gluck IVHAIKU_BOOT_EFI_PRIVATE_KEYFILE	?= ${HAIKU_EFI_SIGNING_KEY} ;
1122c4786ea6SlilloEOF
1123c4786ea6Slillo
1124c0e8cc1aSIngo Weinholdfor targetArch in $HAIKU_PACKAGING_ARCHS; do
1125c0e8cc1aSIngo Weinhold	variables="
1126c1249957SAugustin Cavalier		HAIKU_CC					HAIKU_CC
112747320dd0SAugustin Cavalier		HAIKU_CC_IS_LEGACY_GCC		HAIKU_CC_IS_LEGACY_GCC
1128c1249957SAugustin Cavalier		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1129c1249957SAugustin Cavalier		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1130c0e8cc1aSIngo Weinhold		HAIKU_CPU					HAIKU_CPU
1131c1249957SAugustin Cavalier		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1132c1249957SAugustin Cavalier		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1133c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1134c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
1135c0e8cc1aSIngo Weinhold		HAIKU_AR					HAIKU_AR
1136c0e8cc1aSIngo Weinhold		HAIKU_LD					HAIKU_LD
1137c0e8cc1aSIngo Weinhold		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1138c0e8cc1aSIngo Weinhold		HAIKU_RANLIB				HAIKU_RANLIB
1139c0e8cc1aSIngo Weinhold		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1140c0e8cc1aSIngo Weinhold		HAIKU_STRIP					HAIKU_STRIP
1141c0e8cc1aSIngo Weinhold		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1142c0e8cc1aSIngo Weinhold		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1143c0e8cc1aSIngo Weinhold		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1144252e4f62SAugustin Cavalier		HAIKU_LINKFLAGS				HAIKU_LINKFLAGS
1145c0e8cc1aSIngo Weinhold		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1146c0e8cc1aSIngo Weinhold		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1147c0e8cc1aSIngo Weinhold		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1148c0e8cc1aSIngo Weinhold		"
1149c0e8cc1aSIngo Weinhold	set -- $variables
1150c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1151c0e8cc1aSIngo Weinhold		value=`get_variable ${2}_$targetArch`
1152c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1153c0e8cc1aSIngo Weinhold		shift 2
1154c0e8cc1aSIngo Weinhold	done
1155b1e5b60cSAxel Dörfler
1156c0e8cc1aSIngo Weinhold	# For variables that may have long values, distribute them over multiple
1157c0e8cc1aSIngo Weinhold	# lines so that jam doesn't hit the maximum line length.
1158c0e8cc1aSIngo Weinhold	variables="
115966a7f29fSJérôme Duval		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
1160c0e8cc1aSIngo Weinhold		"
1161c0e8cc1aSIngo Weinhold	set -- $variables
1162c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1163c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1164c0e8cc1aSIngo Weinhold		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1165c0e8cc1aSIngo Weinhold			>> "$buildConfigFile"
1166c0e8cc1aSIngo Weinhold		echo "    ;" >> "$buildConfigFile"
1167c0e8cc1aSIngo Weinhold		shift 2
1168c0e8cc1aSIngo Weinhold	done
1169c0e8cc1aSIngo Weinholddone
1170b1e5b60cSAxel Dörfler
1171b1e5b60cSAxel Dörfler
11723facc270SAugustin Cavalier# Generate a Jamfile in the output directory.
1173338b8dc3SIngo Weinhold
1174338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
11753facc270SAugustin Cavalier# -- WARNING --
11763facc270SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
11773facc270SAugustin Cavalier# overwritten the next time configure is run.
1178338b8dc3SIngo Weinhold
11793facc270SAugustin CavalierHAIKU_TOP			= $(relative_to "${sourceDir}" "${outputDir}") ;
11803facc270SAugustin CavalierHAIKU_OUTPUT_DIR	= . ;
1181338b8dc3SIngo Weinhold
1182338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1183338b8dc3SIngo Weinhold
1184338b8dc3SIngo WeinholdEOF
1185d73993ffSAugustin Cavalier
1186d73993ffSAugustin Cavalierecho "Configured successfully!"
1187