xref: /haiku/configure (revision c59cde3d69039ab7935cfe78e9adb0cf184ca8a1)
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.
28c0e8cc1aSIngo Weinhold  --build-cross-tools <arch> [ <build tools dir> ]
29338b8dc3SIngo Weinhold                              Assume cross compilation. <build tools dir>
30338b8dc3SIngo Weinhold                              defines the location of the build tools sources.
31338b8dc3SIngo Weinhold                              They will be compiled and placed in the output
32a5b60fa8SOliver Tappe                              directory under "cross-tools". The HAIKU_* tools
33a5b60fa8SOliver Tappe                              variables will be set accordingly.
3420ab75e6SIngo Weinhold                              <arch> specifies the target architecture, either
355bd0fbd1SAlexander von Gluck IV                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k",
36*c59cde3dSAlexander von Gluck IV                              "arm", "arm64", "riscv64", "sparc"
37c0e8cc1aSIngo Weinhold                              This option and --cross-tools-prefix can be
38c0e8cc1aSIngo Weinhold                              specified multiple times. The first cross tools
39c0e8cc1aSIngo Weinhold                              specify the primary tools, the subsequent ones the
40c0e8cc1aSIngo Weinhold                              secondary tools (for "hybrid" images).
41c0e8cc1aSIngo Weinhold                              For the first --build-cross-tools the
42c0e8cc1aSIngo Weinhold                              <build tools dir> argument must be specified and
43c0e8cc1aSIngo Weinhold                              for the subsequent ones it must be omitted.
44eccc7665SIngo Weinhold  --cross-tools-prefix <prefix>
45eccc7665SIngo Weinhold                              Assume cross compilation. <prefix> should be a
46eccc7665SIngo Weinhold                              path to the directory where the cross
47eccc7665SIngo Weinhold                              compilation tools are located, plus the platform
480da9c208SIngo Weinhold                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
49eccc7665SIngo Weinhold                              This overrides the HAIKU_* tool variables.
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.
95338b8dc3SIngo Weinhold
96338b8dc3SIngo Weinholdenvironment variables:
9763701e7dSOliver Tappe  CC                          The host compiler. Defaults to "gcc".
9865706842SAugustin Cavalier  HAIKU_AR_<arch>             The static library archiver for <arch>.
99c0e8cc1aSIngo Weinhold                              Defaults to "ar".
10065706842SAugustin Cavalier  HAIKU_CC_<arch>             The compiler for <arch>. Defaults to "gcc".
10165706842SAugustin Cavalier  HAIKU_LD_<arch>             The <arch> linker. Defaults to "ld".
10265706842SAugustin Cavalier  HAIKU_OBJCOPY_<arch>        The <arch> objcopy to be used. Defaults to
103c0e8cc1aSIngo Weinhold                              "objcopy".
10465706842SAugustin Cavalier  HAIKU_RANLIB_<arch>         The static library indexer for <arch>. Defaults
105c0e8cc1aSIngo Weinhold                              to "ranlib".
10665706842SAugustin Cavalier  HAIKU_STRIP_<arch>          The <arch> strip command. Defaults to "strip".
107a04a520bSJonathan Schleifer  HAIKU_NASM                  The nasm assembler (x86 and x86_64 only).
108c0e8cc1aSIngo Weinhold  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
109c0e8cc1aSIngo Weinhold                              <arch>. Defaults to "".
110c0e8cc1aSIngo Weinhold  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
111c0e8cc1aSIngo Weinhold                              Defaults to "".
112c0e8cc1aSIngo Weinhold  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
113c0e8cc1aSIngo Weinhold                              Defaults to "".
114252e4f62SAugustin Cavalier  HAIKU_LINKFLAGS_<arch>      The flags passed to the compiler when linking for
115252e4f62SAugustin Cavalier                              target architecture <arch>. Defaults to "".
116c0e8cc1aSIngo Weinhold  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
117c0e8cc1aSIngo Weinhold                              Defaults to "".
118c0e8cc1aSIngo Weinhold  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
119c0e8cc1aSIngo Weinhold                              architecture <arch> for archiving. Defaults to
120241b61a7SAugustin Cavalier                              "cru".
121c0e8cc1aSIngo Weinhold  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
122c0e8cc1aSIngo Weinhold                              architecture <arch> for unarchiving. Defaults to
123c0e8cc1aSIngo Weinhold                              "x".
12464f6da31SIngo Weinhold
125c0e8cc1aSIngo WeinholdNon-default output directories:
12664f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
12764f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
12864f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
12964f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
13064f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
13164f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
13264f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
13364f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
13464f6da31SIngo Weinhold  non-default location and running jam.
13564f6da31SIngo Weinhold
13664f6da31SIngo Weinhold
137022fa244SIngo WeinholdEOF
138022fa244SIngo Weinhold}
139022fa244SIngo Weinhold
140022fa244SIngo Weinhold# assertparam
141022fa244SIngo Weinhold#
142022fa244SIngo Weinhold# Checks whether at least one parameter is left.
143022fa244SIngo Weinhold#
144022fa244SIngo Weinholdassertparam()
145022fa244SIngo Weinhold{
14620ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
147022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
148022fa244SIngo Weinhold		exit 1
149022fa244SIngo Weinhold	fi
150022fa244SIngo Weinhold}
151022fa244SIngo Weinhold
15220ab75e6SIngo Weinhold# assertparams
15320ab75e6SIngo Weinhold#
15420ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
15520ab75e6SIngo Weinhold#
15620ab75e6SIngo Weinholdassertparams()
15720ab75e6SIngo Weinhold{
15820ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
15920ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
16020ab75e6SIngo Weinhold		exit 1
16120ab75e6SIngo Weinhold	fi
16220ab75e6SIngo Weinhold}
16320ab75e6SIngo Weinhold
164e173a1ecSIngo Weinhold# absolute_path
165e173a1ecSIngo Weinhold#
166e173a1ecSIngo Weinhold# returns the absolute path of a given path.
167e173a1ecSIngo Weinhold#
168e173a1ecSIngo Weinholdabsolute_path()
169e173a1ecSIngo Weinhold{
1706a4f3954SFrançois Revol	if [ "x$1" != "x${1#/}" ]; then
171e173a1ecSIngo Weinhold		echo "$1"
172e173a1ecSIngo Weinhold	else
173e173a1ecSIngo Weinhold		echo "`pwd`/$1"
174e173a1ecSIngo Weinhold	fi
175e173a1ecSIngo Weinhold}
176e173a1ecSIngo Weinhold
17739d444a3SArvind S Raj# check_dir_exists
17839d444a3SArvind S Raj#
17939d444a3SArvind S Raj# check if a directory exists or not
18039d444a3SArvind S Raj#
18139d444a3SArvind S Rajcheck_dir_exists()
18239d444a3SArvind S Raj{
18339d444a3SArvind S Raj	if [ -d "$1" ]; then
18439d444a3SArvind S Raj		return 0
18539d444a3SArvind S Raj	else
18639d444a3SArvind S Raj		return 1
18739d444a3SArvind S Raj	fi
18839d444a3SArvind S Raj}
18939d444a3SArvind S Raj
190502882dbSJessica Hamilton# check_file_exists
191502882dbSJessica Hamilton#
192502882dbSJessica Hamilton# check if a file exists or not
193502882dbSJessica Hamilton#
194502882dbSJessica Hamiltoncheck_file_exists()
195502882dbSJessica Hamilton{
196502882dbSJessica Hamilton	if [ -f "$1" ]; then
197502882dbSJessica Hamilton		return 0
198502882dbSJessica Hamilton	else
199502882dbSJessica Hamilton		return 1
200502882dbSJessica Hamilton	fi
201502882dbSJessica Hamilton}
202502882dbSJessica Hamilton
2039a001156SOliver Tappe# real_path
2049a001156SOliver Tappe#
2059a001156SOliver Tappe# returns the realpath of a symbolic link.
2069a001156SOliver Tappe#
2079a001156SOliver Tappereal_path()
2089a001156SOliver Tappe{
2099a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
2109a001156SOliver Tappe}
2119a001156SOliver Tappe
2123facc270SAugustin Cavalier# relative_to
2133facc270SAugustin Cavalier#
2143facc270SAugustin Cavalier# returns $1 relative to $2
2153facc270SAugustin Cavalier#
2163facc270SAugustin Cavalierrelative_to()
2173facc270SAugustin Cavalier{
2183facc270SAugustin Cavalier	perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' \
2191d91b371SAugustin Cavalier		"$1" "$2"
2203facc270SAugustin Cavalier}
2213facc270SAugustin Cavalier
222e5d446fcSAlexander von Gluck IV# valid_toolchain
223e5d446fcSAlexander von Gluck IV#
2241f839e89Swaddlesplash# check if a toolchain is valid
225e5d446fcSAlexander von Gluck IV#
226e5d446fcSAlexander von Gluck IVvalid_toolchain()
227e5d446fcSAlexander von Gluck IV{
228e5d446fcSAlexander von Gluck IV	TRIPLET="$1"
229e5d446fcSAlexander von Gluck IV	BASE="$2"
2301f839e89Swaddlesplash	SOURCE="$3"
231e5d446fcSAlexander von Gluck IV	if [ ! -d "$BASE" ]; then
2321f839e89Swaddlesplash		return 1
233e5d446fcSAlexander von Gluck IV	fi
234e5d446fcSAlexander von Gluck IV	if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
2351f839e89Swaddlesplash		[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
2361f839e89Swaddlesplash			[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
2371f839e89Swaddlesplash		return $?
238e5d446fcSAlexander von Gluck IV	fi
2391f839e89Swaddlesplash	return 1
240e5d446fcSAlexander von Gluck IV}
241e5d446fcSAlexander von Gluck IV
24209c5682dSIngo Weinhold# standard_gcc_settings
24309c5682dSIngo Weinhold#
24409c5682dSIngo Weinhold# Sets the variables for a GCC platform.
24509c5682dSIngo Weinhold#
24609c5682dSIngo Weinholdstandard_gcc_settings()
24709c5682dSIngo Weinhold{
24865706842SAugustin Cavalier	local gcc="$1"
249c0e8cc1aSIngo Weinhold
250138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
251b29b48b1SMatt Madia		readlink="greadlink -e"
252138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
253b29b48b1SMatt Madia		readlink=realpath
2549a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
255b29b48b1SMatt Madia		readlink="readlink -e"
2569a001156SOliver Tappe	else
2579a001156SOliver Tappe		readlink=real_path
258b4b6d83cSMatt Madia	fi
259138f5fb4SIngo Weinhold
26009c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
261c0e8cc1aSIngo Weinhold	local gcclib=`$gcc -print-libgcc-file-name`
262c0e8cc1aSIngo Weinhold	local gccdir=`dirname ${gcclib}`
2635b0f7b1bSOliver Tappe
264c0e8cc1aSIngo Weinhold	local gccRawVersion=`$gcc -dumpversion`
265c0e8cc1aSIngo Weinhold	local gccMachine=`$gcc -dumpmachine`
266338b8dc3SIngo Weinhold
267fc8967f1SIngo Weinhold	# determine architecture from machine triple
268c0e8cc1aSIngo Weinhold	case $gccMachine in
269c0e8cc1aSIngo Weinhold		arm-*)		targetCpu=arm;;
270fb4cc984SAugustin Cavalier		arm64-*)	targetCpu=arm64;;
271c0e8cc1aSIngo Weinhold		i?86-*)		targetCpu=x86;;
272c0e8cc1aSIngo Weinhold		m68k-*)		targetCpu=m68k;;
273c0e8cc1aSIngo Weinhold		powerpc-*)	targetCpu=ppc;;
2745bd0fbd1SAlexander von Gluck IV		riscv64-*)	targetCpu=riscv64;;
2755629675aSAdrien Destugues		sparc64-*)	targetCpu=sparc;;
276c0e8cc1aSIngo Weinhold		x86_64-*)	targetCpu=x86_64;;
277fc8967f1SIngo Weinhold		*)
278c0e8cc1aSIngo Weinhold			echo "Unsupported gcc target machine: $gccMachine" >&2
279fc8967f1SIngo Weinhold			exit 1
280fc8967f1SIngo Weinhold			;;
281fc8967f1SIngo Weinhold	esac
282fc8967f1SIngo Weinhold
283c0e8cc1aSIngo Weinhold	local targetArch=$targetCpu
284fc8967f1SIngo Weinhold
285c0e8cc1aSIngo Weinhold	case $gccRawVersion in
2866cc8eecfSOliver Tappe		2.9*)
2875b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
2885b0f7b1bSOliver Tappe			# if an older one is installed
289c0e8cc1aSIngo Weinhold			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
2905b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
2915b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
2925b0f7b1bSOliver Tappe				exit 1;
2935b0f7b1bSOliver Tappe			fi
294aaeadfcbSAlex Smith
295c0e8cc1aSIngo Weinhold			targetArch=x86_gcc2
2965b0f7b1bSOliver Tappe			;;
2978b5934c9SIngo Weinhold	esac
29865ad1ba3SAlex Smith
299c0e8cc1aSIngo Weinhold	local bootLibgcc
300c0e8cc1aSIngo Weinhold	local bootLibSupCxx
30166a7f29fSJérôme Duval	local bootCxxHeaders
302c0e8cc1aSIngo Weinhold	case $gccMachine in
3034591ebc9SAlex Smith		x86_64-*)
30466a7f29fSJérôme Duval			# Boot loader is 32-bit, need the 32-bit libs and c++ config
30511ae3c5fSOliver Tappe			bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a`
306c0e8cc1aSIngo Weinhold			bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
30766a7f29fSJérôme Duval
30866a7f29fSJérôme Duval			local headersBase=$gccdir/../../../..
30966a7f29fSJérôme Duval			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
31066a7f29fSJérôme Duval			if [ ! -d $headers ]; then
31166a7f29fSJérôme Duval				headers=$headersBase/include/c++/$gccRawVersion
31266a7f29fSJérôme Duval			fi
31366a7f29fSJérôme Duval			bootCxxHeaders="$headers/$gccMachine/32"
3144591ebc9SAlex Smith			;;
315338b8dc3SIngo Weinhold	esac
316c0e8cc1aSIngo Weinhold
317c0e8cc1aSIngo Weinhold	# determine whether graphite loop optimization should/can be used
318c0e8cc1aSIngo Weinhold	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
319c0e8cc1aSIngo Weinhold	if [ -z "$useGraphite" ]; then
320c0e8cc1aSIngo Weinhold		useGraphite=$useGccGraphiteDefault
321c0e8cc1aSIngo Weinhold	fi
322c0e8cc1aSIngo Weinhold
323c0e8cc1aSIngo Weinhold	if [ "$useGraphite" != 0 ]; then
324c0e8cc1aSIngo Weinhold		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
325c0e8cc1aSIngo Weinhold		if [ $? != 0 ]; then
326c0e8cc1aSIngo Weinhold			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
327c0e8cc1aSIngo Weinhold			useGraphite=0
328c0e8cc1aSIngo Weinhold		fi
329c0e8cc1aSIngo Weinhold	fi
330c0e8cc1aSIngo Weinhold
331c0e8cc1aSIngo Weinhold	set_variable HAIKU_CPU_$targetArch $targetCpu
332c0e8cc1aSIngo Weinhold
333c0e8cc1aSIngo Weinhold	get_build_tool_path CC_$targetArch "$gcc"
334a7bddff1SJonathan Schleifer	set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
335c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
336c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
337c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
33866a7f29fSJérôme Duval	set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
33911ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
34011ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
341c0e8cc1aSIngo Weinhold	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
342c0e8cc1aSIngo Weinhold
343c0e8cc1aSIngo Weinhold	standard_gcc_settings_targetArch=$targetArch
344c0e8cc1aSIngo Weinhold}
345c0e8cc1aSIngo Weinhold
346c0e8cc1aSIngo Weinhold# set_variable
347c0e8cc1aSIngo Weinhold#
348c0e8cc1aSIngo Weinhold# Set the value of a variable.
349c0e8cc1aSIngo Weinhold#
350c0e8cc1aSIngo Weinholdset_variable()
351c0e8cc1aSIngo Weinhold{
352c0e8cc1aSIngo Weinhold	eval "$1=\"$2\""
353c0e8cc1aSIngo Weinhold}
354c0e8cc1aSIngo Weinhold
355c0e8cc1aSIngo Weinhold# get_variable
356c0e8cc1aSIngo Weinhold#
357c0e8cc1aSIngo Weinhold# Echo the value of a variable.
358c0e8cc1aSIngo Weinhold#
359c0e8cc1aSIngo Weinholdget_variable()
360c0e8cc1aSIngo Weinhold{
361c0e8cc1aSIngo Weinhold	eval "echo \${$1}"
36209c5682dSIngo Weinhold}
36309c5682dSIngo Weinhold
364338b8dc3SIngo Weinhold# set_default_value
365338b8dc3SIngo Weinhold#
366338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
367338b8dc3SIngo Weinhold#
368338b8dc3SIngo Weinholdset_default_value()
369338b8dc3SIngo Weinhold{
3700838a930SJérôme Duval	eval "$1=\${$1-$2}"
371338b8dc3SIngo Weinhold}
372338b8dc3SIngo Weinhold
373338b8dc3SIngo Weinhold# get_build_tool_path
374338b8dc3SIngo Weinhold#
375338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
376338b8dc3SIngo Weinhold#
377338b8dc3SIngo Weinholdget_build_tool_path()
378338b8dc3SIngo Weinhold{
379338b8dc3SIngo Weinhold	local var="HAIKU_$1"
38065706842SAugustin Cavalier	local varval="`get_variable $var`"
38165706842SAugustin Cavalier	local cmd="$2"
382d73993ffSAugustin Cavalier
383e042a53bSAugustin Cavalier	if [ ! -z "$varval" ]; then
384d73993ffSAugustin Cavalier		# this variable is already set (probably by user) so grab its contents
385e042a53bSAugustin Cavalier		cmd=$varval
386d73993ffSAugustin Cavalier	fi
387d73993ffSAugustin Cavalier
388d73993ffSAugustin Cavalier	local path=${cmd%% *}
389338b8dc3SIngo Weinhold
390338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
39165706842SAugustin Cavalier		# get absolute path from relative path
392a559f87aSFrançois Revol		local oldPwd="`pwd`"
393a559f87aSFrançois Revol		cd "`dirname "$path"`"
394a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
395338b8dc3SIngo Weinhold		cd $oldPwd
396338b8dc3SIngo Weinhold	else
3977fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
398d73993ffSAugustin Cavalier			echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
399338b8dc3SIngo Weinhold			exit 1
400338b8dc3SIngo Weinhold		}
401338b8dc3SIngo Weinhold	fi
402338b8dc3SIngo Weinhold
40365706842SAugustin Cavalier	if test "${cmd#* }" != "$cmd"; then
40465706842SAugustin Cavalier		# $cmd contains arguments, so preserve them (and only them)
40565706842SAugustin Cavalier		cmd=${cmd#* }
40665706842SAugustin Cavalier	else
40765706842SAugustin Cavalier		# $cmd does not contain arguments, so unset it
40865706842SAugustin Cavalier		cmd=
40965706842SAugustin Cavalier	fi
41065706842SAugustin Cavalier	eval "$var=\"$path $cmd\""
411338b8dc3SIngo Weinhold}
412338b8dc3SIngo Weinhold
413a5c952dbSAugustin Cavalier# check_native_xattrs
414a5c952dbSAugustin Cavalier#
415a5c952dbSAugustin Cavalier# Checks the host platform's support for extended attributes.
416a5c952dbSAugustin Cavalier# 0: no support, 1: only enough for xattr-ref, 2: full support
417a5c952dbSAugustin Cavalier#
418a5c952dbSAugustin Cavaliercheck_native_xattrs()
419a5c952dbSAugustin Cavalier{
420a5c952dbSAugustin Cavalier	local xattr_set=
421a5c952dbSAugustin Cavalier	local xattr_set_args=
422a5c952dbSAugustin Cavalier	local xattr_get=
423a5c952dbSAugustin Cavalier	local xattr_get_args=
424a5c952dbSAugustin Cavalier	case $HOST_PLATFORM in
425503ef6d4SAugustin Cavalier		haiku_host)
426503ef6d4SAugustin Cavalier			xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
427503ef6d4SAugustin Cavalier			xattr_get="catattr"; xattr_get_args="\$NAME"
428503ef6d4SAugustin Cavalier			;;
429a5c952dbSAugustin Cavalier		darwin)
430a5c952dbSAugustin Cavalier			xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
431a5c952dbSAugustin Cavalier			xattr_get="xattr"; xattr_get_args="-p \$NAME"
432a5c952dbSAugustin Cavalier			;;
433a5c952dbSAugustin Cavalier		freebsd)
434a5c952dbSAugustin Cavalier			xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
435a5c952dbSAugustin Cavalier			xattr_get="getextattr"; xattr_get_args="user \$NAME"
436a5c952dbSAugustin Cavalier			;;
437a5c952dbSAugustin Cavalier		linux)
438a5c952dbSAugustin Cavalier			xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
439a5c952dbSAugustin Cavalier			xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
440a5c952dbSAugustin Cavalier			;;
441a5c952dbSAugustin Cavalier		*)
442a5c952dbSAugustin Cavalier			return 0
443a5c952dbSAugustin Cavalier			;;
444a5c952dbSAugustin Cavalier	esac
445a5c952dbSAugustin Cavalier	if ! type $xattr_set >/dev/null 2>&1; then
446a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_set, assuming host has no extended attributes"
447a5c952dbSAugustin Cavalier		return 0
448a5c952dbSAugustin Cavalier	elif ! type $xattr_get >/dev/null 2>&1; then
449a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_get, assuming host has no extended attributes"
450a5c952dbSAugustin Cavalier		return 0
451a5c952dbSAugustin Cavalier	fi
452a5c952dbSAugustin Cavalier
45343f5f35aSAugustin Cavalier	mkdir -p "$outputDir"
454a5c952dbSAugustin Cavalier	echo "xattr test file" >"$outputDir/xattrtest"
455a5c952dbSAugustin Cavalier	local i=0
456a5c952dbSAugustin Cavalier	# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
457a5c952dbSAugustin Cavalier	# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
458a5c952dbSAugustin Cavalier	while [ $i -lt 2 ]; do
459a5c952dbSAugustin Cavalier		local j=0
460a5c952dbSAugustin Cavalier		while [ $j -lt 3 ]; do
461a5c952dbSAugustin Cavalier			NAME=attr$j
462a5c952dbSAugustin Cavalier			VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
463a5c952dbSAugustin Cavalier			if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
464a5c952dbSAugustin Cavalier				echo "$0: warning: could not generate test data for extended attributes"
465a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
466a5c952dbSAugustin Cavalier				return $i
467a5c952dbSAugustin Cavalier			elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
468a5c952dbSAugustin Cavalier					"$outputDir/xattrtest" >/dev/null 2>&1 ; then
469a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
470a5c952dbSAugustin Cavalier				return $i
471a5c952dbSAugustin Cavalier			fi
472a5c952dbSAugustin Cavalier			j=$((j+1))
473a5c952dbSAugustin Cavalier		done
474a5c952dbSAugustin Cavalier		i=$((i+1))
475a5c952dbSAugustin Cavalier	done
476a5c952dbSAugustin Cavalier	rm "$outputDir/xattrtest"
477a5c952dbSAugustin Cavalier	return 2
478a5c952dbSAugustin Cavalier}
479a5c952dbSAugustin Cavalier
480483b28e4SIngo Weinholdis_in_list()
481483b28e4SIngo Weinhold{
482483b28e4SIngo Weinhold	local element
483483b28e4SIngo Weinhold	for element in $2; do
484483b28e4SIngo Weinhold		if [ "$1" = "$element" ]; then
485483b28e4SIngo Weinhold			return 0
486483b28e4SIngo Weinhold		fi
487483b28e4SIngo Weinhold	done
488483b28e4SIngo Weinhold	return 1
489483b28e4SIngo Weinhold}
490483b28e4SIngo Weinhold
4917f9beaf1SOliver Tappe# check for --help or -h and show usage immediately
4927f9beaf1SOliver Tappeif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
4938b420c2fSOliver Tappe	usage; exit 0;
4948b420c2fSOliver Tappefi
4958b420c2fSOliver Tappe
496338b8dc3SIngo Weinhold# get cwd and the source directory
497338b8dc3SIngo WeinholdcurrentDir=`pwd`
4986e7c6fe5SIngo Weinholdcd `dirname "$0"`
499338b8dc3SIngo WeinholdsourceDir=`pwd`
5006e7c6fe5SIngo Weinholdcd "$currentDir"
501338b8dc3SIngo Weinhold
502a107d3b4SAugustin Cavalier# determine output directory
503a107d3b4SAugustin Cavalierif [ "$currentDir" = "$sourceDir" ]; then
504a107d3b4SAugustin Cavalier	outputDir=$currentDir/generated
505a107d3b4SAugustin Cavalierelse
506a107d3b4SAugustin Cavalier	outputDir=$currentDir
507a107d3b4SAugustin Cavalierfi
508a107d3b4SAugustin CavalierbuildOutputDir="$outputDir/build"
509a107d3b4SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
510a107d3b4SAugustin CavalierbuildConfigFile="$buildOutputDir/BuildConfig"
511a107d3b4SAugustin Cavalier
512a107d3b4SAugustin Cavalier# check for update request
513a107d3b4SAugustin Cavalierif [ "$1" = "--update" ]; then
514a107d3b4SAugustin Cavalier	if ! [ -e "$buildConfigFile" ]; then
515a107d3b4SAugustin Cavalier		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
516a107d3b4SAugustin Cavalier		exit 1
517a107d3b4SAugustin Cavalier	fi
518a107d3b4SAugustin Cavalier	# get last configure invocation and flags from BuildConfig and call ourselves with it
519a107d3b4SAugustin Cavalier	lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
520a107d3b4SAugustin Cavalier	lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
521a107d3b4SAugustin Cavalier	lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
522a107d3b4SAugustin Cavalier	lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
523a107d3b4SAugustin Cavalier	if [ -z "$lastConfig" ]; then
524a107d3b4SAugustin Cavalier		echo "$0 --update: The previous configure invocation was not properly" \
525a107d3b4SAugustin Cavalier			"encoded into '$buildConfigFile' - updating not possible."
526a107d3b4SAugustin Cavalier		exit 1
527a107d3b4SAugustin Cavalier	fi
5281d91b371SAugustin Cavalier	cd "$lastPwd"
529a107d3b4SAugustin Cavalier	if [ -n "$lastEnv" ]; then
530a107d3b4SAugustin Cavalier		export $lastEnv
531a107d3b4SAugustin Cavalier	fi
532a107d3b4SAugustin Cavalier	$lastConfig $lastArgs
533a107d3b4SAugustin Cavalier	exit $?
534a107d3b4SAugustin Cavalierfi
535a107d3b4SAugustin Cavalier
53655d267a4SFrançois Revol# backup the passed arguments
53755d267a4SFrançois RevolconfigureArgs="$@"
538825700d3SAugustin CavalierconfigurePath=$0
539825700d3SAugustin Cavalier
540825700d3SAugustin Cavalier# backup relevant environs
541825700d3SAugustin CavalierconfigureEnvirons=
542825700d3SAugustin Cavalierfor var in `env`; do
543825700d3SAugustin Cavalier	case "$var" in
544825700d3SAugustin Cavalier		CC\=*|HAIKU*\=*)
545825700d3SAugustin Cavalier			configureEnvirons="$configureEnvirons $var"
546825700d3SAugustin Cavalier			;;
547825700d3SAugustin Cavalier	esac
548825700d3SAugustin Cavalierdone
54955d267a4SFrançois Revol
550a107d3b4SAugustin Cavalier# ensure umask is not too restrictive
55102f3646aSAugustin Cavalierif [ `umask` -gt 22 ]; then
55202f3646aSAugustin Cavalier	echo Your umask is too restrictive "(should be <= 0022;" is actually `umask`")"
55302f3646aSAugustin Cavalier	echo
55402f3646aSAugustin Cavalier	echo Additionally, if the source tree was cloned with a too-restrictive umask,
55502f3646aSAugustin Cavalier	echo you will need to run \"git checkout\" again to fix this.
556a107d3b4SAugustin Cavalier	exit 1
557a107d3b4SAugustin Cavalierfi
55802f3646aSAugustin Cavalier# ensure git checkout was not done with a restrictive umask
5591d91b371SAugustin Cavalierif [ `stat -c '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
56002f3646aSAugustin Cavalier	echo "The source tree was cloned with a umask > 0022. It seems you"
56102f3646aSAugustin Cavalier	echo have already corrected your umask, but not re-checked-out the
56202f3646aSAugustin Cavalier	echo source tree. Try running:
56302f3646aSAugustin Cavalier	echo "	git checkout --force"
56402f3646aSAugustin Cavalier	echo to fix this problem.
56502f3646aSAugustin Cavalier	exit 1
56602f3646aSAugustin Cavalierfi
56702f3646aSAugustin Cavalier
568a107d3b4SAugustin Cavalier
5697c4641d0SOliver Tappe# internal default parameter values
570022fa244SIngo Weinhold#
57152a38012Sejakowatzplatform=`uname`
5725abd9a46SIngo WeinholdplatformMachine=`uname  -m`
573c0e8cc1aSIngo WeinholdtargetArchs=
574338b8dc3SIngo WeinholdbuildCrossTools=
57529ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
57660d8d8fcSIngo WeinholdbuildCrossToolsJobs=
577c2b76f7fSJonathan SchleiferuseClang=0
578c0e8cc1aSIngo WeinholduseGccGraphiteDefault=0
579c0e8cc1aSIngo WeinholdunknownArchIndex=1
580483b28e4SIngo WeinholdhaikuTargetArchs=
5814da6cf84SFrançois RevolgdbSources=
5827c4641d0SOliver Tappe
58363701e7dSOliver Tappeif [ -z "$CC" ]; then
58463701e7dSOliver Tappe	CC=gcc
58563701e7dSOliver Tappefi
58663701e7dSOliver Tappe
5877c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
5887c4641d0SOliver Tappe#
58963701e7dSOliver TappeHOST_GCC_RAW_VERSION=`$CC -dumpversion`
59063701e7dSOliver TappeHOST_GCC_MACHINE=`$CC -dumpmachine`
59176fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
5927c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
5937c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
5947c4641d0SOliver TappeTARGET_PLATFORM=haiku
5957c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
5967986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
597fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR=
598fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR_REF=
5992ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY=0
600f04f7042SNiels Sascha ReedijkHOST_EXTENDED_REGEX_SED="sed -r"
60163701e7dSOliver TappeHOST_GCC_LD=`$CC -print-prog-name=ld`
60263701e7dSOliver TappeHOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
6032a5d0aafSIngo WeinholdHOST_SHA256=
604e173a1ecSIngo WeinholdHOST_HAIKU_PORTER=
605e173a1ecSIngo WeinholdHAIKU_PORTS=
606e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS=
607c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP=0
608aa2e5ecaSOliver TappeHAIKU_NO_DOWNLOADS=0
6092a5d0aafSIngo Weinhold
610c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS=
611c0e8cc1aSIngo Weinhold
612a04a520bSJonathan Schleiferset_default_value HAIKU_NASM		nasm
613c0e8cc1aSIngo Weinhold
6143942ca0dSIngo Weinholdif sha256sum < /dev/null > /dev/null 2>&1; then
6152a5d0aafSIngo Weinhold	HOST_SHA256=sha256sum
6163942ca0dSIngo Weinholdelif sha256 < /dev/null > /dev/null 2>&1; then
6172a5d0aafSIngo Weinhold	HOST_SHA256="sha256 -q"
618b5a871b1SNiels Sascha Reedijkelif shasum < /dev/null > /dev/null 2>&1; then
619b5a871b1SNiels Sascha Reedijk	HOST_SHA256="shasum -a 256"
6202a5d0aafSIngo Weinholdelse
6212a5d0aafSIngo Weinhold	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
6222a5d0aafSIngo Weinhold	exit 1
6232a5d0aafSIngo Weinholdfi
624338b8dc3SIngo Weinhold
62584edb1a1SAxel DörflerhaikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
626a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
627af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
628483b28e4SIngo WeinholdsupportedTargetArchs="
629483b28e4SIngo Weinhold	arm
630fb4cc984SAugustin Cavalier	arm64
631483b28e4SIngo Weinhold	m68k
632483b28e4SIngo Weinhold	ppc
6335bd0fbd1SAlexander von Gluck IV	riscv64
634f23db0edSPulkoMandy	sparc
635483b28e4SIngo Weinhold	x86
636483b28e4SIngo Weinhold	x86_64
637483b28e4SIngo Weinhold	x86_gcc2
638483b28e4SIngo Weinhold	"
639af4bf973SOliver Tappe
640022fa244SIngo Weinhold# parse parameters
641022fa244SIngo Weinhold#
64220ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
643022fa244SIngo Weinhold	case "$1" in
644e173a1ecSIngo Weinhold		--bootstrap)
645e173a1ecSIngo Weinhold			assertparams "$1" 3 $#
646e173a1ecSIngo Weinhold			HOST_HAIKU_PORTER="`absolute_path $2`"
647e173a1ecSIngo Weinhold			HAIKU_PORTS_CROSS="`absolute_path $3`"
648e173a1ecSIngo Weinhold			HAIKU_PORTS="`absolute_path $4`"
649c9dd05ffSJonathan Schleifer			HAIKU_IS_BOOTSTRAP=1
650c9dd05ffSJonathan Schleifer			HAIKU_NO_DOWNLOADS=1
651502882dbSJessica Hamilton			check_file_exists "$HOST_HAIKU_PORTER" || (
652502882dbSJessica Hamilton				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
65339d444a3SArvind S Raj				exit 1
65439d444a3SArvind S Raj			)
65539d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS" || (
65639d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS" >&2
65739d444a3SArvind S Raj				exit 1
65839d444a3SArvind S Raj			)
65939d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS_CROSS" || (
66039d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
66139d444a3SArvind S Raj				exit 1
66239d444a3SArvind S Raj			)
663e173a1ecSIngo Weinhold			shift 4
664e173a1ecSIngo Weinhold			;;
665c0e8cc1aSIngo Weinhold		--build-cross-tools)
666c0e8cc1aSIngo Weinhold			if [ -z "$buildCrossTools" ]; then
6679b0dd528SIngo Weinhold				assertparams "$1" 2 $#
668c0e8cc1aSIngo Weinhold				targetArch=$2
6699b0dd528SIngo Weinhold				buildCrossTools=$3
6709b0dd528SIngo Weinhold				shift 3
671c0e8cc1aSIngo Weinhold			else
672c0e8cc1aSIngo Weinhold				assertparam "$1" $#
673c0e8cc1aSIngo Weinhold				targetArch=$2
674c0e8cc1aSIngo Weinhold				shift 2
675c0e8cc1aSIngo Weinhold			fi
676c0e8cc1aSIngo Weinhold			case "$targetArch" in
677c0e8cc1aSIngo Weinhold				x86_gcc2)	targetMachine=i586-pc-haiku;;
678c0e8cc1aSIngo Weinhold				x86)		targetMachine=i586-pc-haiku;;
679c0e8cc1aSIngo Weinhold				x86_64)		targetMachine=x86_64-unknown-haiku;;
680c0e8cc1aSIngo Weinhold				ppc)		targetMachine=powerpc-apple-haiku;;
681c0e8cc1aSIngo Weinhold				m68k)		targetMachine=m68k-unknown-haiku;;
682c0e8cc1aSIngo Weinhold				arm)		targetMachine=arm-unknown-haiku;;
6835bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
6845629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
685c0e8cc1aSIngo Weinhold				*)
686101564e4SAugustin Cavalier					echo "Unsupported target architecture: $targetArch" >&2
687c0e8cc1aSIngo Weinhold					exit 1
688c0e8cc1aSIngo Weinhold					;;
689c0e8cc1aSIngo Weinhold			esac
690c0e8cc1aSIngo Weinhold			set_variable buildCrossToolsMachine_$targetArch $targetMachine
691c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
6929b0dd528SIngo Weinhold			;;
6939b0dd528SIngo Weinhold		--cross-tools-prefix)
6949b0dd528SIngo Weinhold			assertparam "$1" $#
695c0e8cc1aSIngo Weinhold			targetArch=unknown${unknownArchIndex}
696c0e8cc1aSIngo Weinhold			set_variable crossToolsPrefix_$targetArch "$2"
697c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
698d68208faSMatt Madia			unknownArchIndex=$(($unknownArchIndex + 1))
6999b0dd528SIngo Weinhold			shift 2
7009b0dd528SIngo Weinhold			;;
701a66c32ddSIngo Weinhold		--distro-compatibility)
7029b0dd528SIngo Weinhold			assertparam "$1" $#
7037c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
7047c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
705a66c32ddSIngo Weinhold				official)	;;
706a66c32ddSIngo Weinhold				compatible)	;;
707a66c32ddSIngo Weinhold				default)	;;
708a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
7097c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
710a66c32ddSIngo Weinhold							exit 1;;
711a66c32ddSIngo Weinhold			esac
7129b0dd528SIngo Weinhold			shift 2
7139b0dd528SIngo Weinhold			;;
7142ebcd86dSIngo Weinhold		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
71576fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
7167c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
71760d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
718aa2e5ecaSOliver Tappe		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
719483b28e4SIngo Weinhold		--target-arch)
720483b28e4SIngo Weinhold			assertparam "$1" $#
721483b28e4SIngo Weinhold			targetArch=$2
722483b28e4SIngo Weinhold			shift 2
723483b28e4SIngo Weinhold			if [ ! "$platform" = Haiku ]; then
724483b28e4SIngo Weinhold				echo "--target-arch can only be specified on Haiku." >&2
725483b28e4SIngo Weinhold				exit 1
726483b28e4SIngo Weinhold			fi
727483b28e4SIngo Weinhold			is_in_list "$targetArch" "$supportedTargetArchs" || (
728483b28e4SIngo Weinhold				echo "Unsupported target architecture: \"$targetArch\"" >&2
729483b28e4SIngo Weinhold				exit 1
730483b28e4SIngo Weinhold			)
731483b28e4SIngo Weinhold			haikuTargetArchs="$haikuTargetArchs $targetArch"
732483b28e4SIngo Weinhold			;;
733d73993ffSAugustin Cavalier		--use-clang)
734d73993ffSAugustin Cavalier			assertparam "$1" $#
735d73993ffSAugustin Cavalier			targetArch=$2
736d73993ffSAugustin Cavalier			useClang=1
737d73993ffSAugustin Cavalier			case "$targetArch" in
738d73993ffSAugustin Cavalier				x86)		targetMachine=i586-pc-haiku;;
739d73993ffSAugustin Cavalier				x86_64)		targetMachine=x86_64-unknown-haiku;;
740d9f698eaSAugustin Cavalier				ppc)		targetMachine=powerpc-apple-haiku;;
74120dbf032SAlexander von Gluck IV				arm)		targetMachine=arm-unknown-haiku;;
742fb4cc984SAugustin Cavalier				arm64)		targetMachine=arm64-unknown-haiku;;
7435bd0fbd1SAlexander von Gluck IV				riscv64)	targetMachine=riscv64-unknown-haiku;;
7445629675aSAdrien Destugues				sparc)		targetMachine=sparc64-unknown-haiku;;
745d73993ffSAugustin Cavalier				*)
746d73993ffSAugustin Cavalier					echo "Unsupported target architecture: $2" >&2
747d73993ffSAugustin Cavalier					exit 1
748d73993ffSAugustin Cavalier					;;
749d73993ffSAugustin Cavalier			esac
75065706842SAugustin Cavalier			get_build_tool_path clang clang
75136f28382SAugustin Cavalier			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
75236f28382SAugustin Cavalier					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
75365706842SAugustin Cavalier				set_variable crossToolsPrefix_$targetArch llvm-
75465706842SAugustin Cavalier			fi
7555924b6e4SAugustin Cavalier			clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
7565924b6e4SAugustin Cavalier			if [ `echo $clangVersion | head -c 1` -lt 7 ]; then
7575924b6e4SAugustin Cavalier				echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
7585924b6e4SAugustin Cavalier				echo "Please install a newer version."
7595924b6e4SAugustin Cavalier				exit 1
7605924b6e4SAugustin Cavalier			fi
761d73993ffSAugustin Cavalier			targetArchs="$targetArchs $targetArch"
762d73993ffSAugustin Cavalier			shift 2
763d73993ffSAugustin Cavalier			;;
7647c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
765c0e8cc1aSIngo Weinhold		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
7667986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
767fc2c93fbSAugustin Cavalier		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
768fc2c93fbSAugustin Cavalier		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
7694da6cf84SFrançois Revol		--with-gdb)	gdbSources=$2; shift 2;;
770022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
771022fa244SIngo Weinhold	esac
772022fa244SIngo Weinholddone
773022fa244SIngo Weinhold
7740df3cc9cSIngo Weinhold# detect the build platform
775338b8dc3SIngo Weinholdcase "${platform}" in
7767c4641d0SOliver Tappe	Darwin)	HOST_PLATFORM=darwin ;;
7777c4641d0SOliver Tappe	FreeBSD)	HOST_PLATFORM=freebsd
7787986925fSIngo Weinhold				if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
7795abd9a46SIngo Weinhold					echo Unsupported platform: FreeBSD ${platformMachine}
780308c212cSIngo Weinhold					exit 1
781308c212cSIngo Weinhold				fi	;;
7827c4641d0SOliver Tappe	Haiku)	HOST_PLATFORM=haiku_host ;;
7837c4641d0SOliver Tappe	Linux)	HOST_PLATFORM=linux ;;
7847c4641d0SOliver Tappe	OpenBSD) HOST_PLATFORM=openbsd ;;
785807304b1SAugustin Cavalier	MINGW*) HOST_PLATFORM=mingw ;;
786338b8dc3SIngo Weinhold	*)		echo Unsupported platform: ${platform}
7874cbe4925SAxel Dörfler			exit 1 ;;
7884cbe4925SAxel Dörfleresac
78952a38012Sejakowatz
7900962132cSAlex Smith# check for case-sensitive filesystem
7910962132cSAlex Smithmkdir haikuCaseTest 2>/dev/null
7920962132cSAlex Smithmkdir haikucasetest 2>/dev/null
7930962132cSAlex SmithcaseInsensitive=$?
79497f5a0bdSAlex Smithrmdir haikuCaseTest haikucasetest 2>/dev/null
7950962132cSAlex Smithif [ $caseInsensitive != 0 ]; then
7963ecc5287SMichael Lotz	echo "You need a case-sensitive file-system to build Haiku."
7970962132cSAlex Smith	if [ $HOST_PLATFORM = "darwin" ]; then
7987a05e252SJohn Scipione		echo "You can create a case-sensitive disk image using Disk Utility."
7993ecc5287SMichael Lotz	fi
8000962132cSAlex Smith	exit 1
8013ecc5287SMichael Lotzfi
8023ecc5287SMichael Lotz
803a5c952dbSAugustin Cavalier# check xattr support
804503ef6d4SAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
805a5c952dbSAugustin Cavalier	check_native_xattrs
806a5c952dbSAugustin Cavalier	attrSupport=$?
807fc2c93fbSAugustin Cavalier	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
808fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR=1
809a5c952dbSAugustin Cavalier	elif [ $attrSupport = 1 ]; then
810fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR_REF=1
811a5c952dbSAugustin Cavalier	fi
812a5c952dbSAugustin Cavalierfi
813fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
814fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
815a5c952dbSAugustin Cavalier
816f04f7042SNiels Sascha Reedijk# determine how to invoke sed with extended regexp support for non-GNU sed
817f04f7042SNiels Sascha Reedijkif [ $HOST_PLATFORM = "darwin" ]; then
818f04f7042SNiels Sascha Reedijk	HOST_EXTENDED_REGEX_SED="sed -E"
819f04f7042SNiels Sascha Reedijkfi
820f04f7042SNiels Sascha Reedijk
8212b200496SAugustin Cavalier# locate python
8222b200496SAugustin Cavalierif python3 --version < /dev/null > /dev/null 2>&1; then
82317dc34acSAndrew Lindesay	HOST_PYTHON="python3"
8242b200496SAugustin Cavalierelif python --version < /dev/null > /dev/null 2>&1; then
82517dc34acSAndrew Lindesay	HOST_PYTHON="python"
82617dc34acSAndrew Lindesayelse
82717dc34acSAndrew Lindesay	echo "a python interpreter is required"
82817dc34acSAndrew Lindesay	exit 1
82917dc34acSAndrew Lindesayfi
83017dc34acSAndrew Lindesay
831cb721c59SFrançois Revol# check if nasm can actually output ELF files
832cb721c59SFrançois Revol# (the stock version in OSX can't)
833cb721c59SFrançois Revol# XXX: should probably only test for x86* arch
8343e6c09cdSAdrien Destuguesif [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
835cb721c59SFrançois Revol	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
836cb721c59SFrançois Revol	if [ $HOST_PLATFORM = "darwin" ]; then
837cb721c59SFrançois Revol		echo "You can install it from Mac Ports."
838cb721c59SFrançois Revol		echo "Mac Ports is available at: http://www.macports.org/"
839cb721c59SFrançois Revol	fi
840cb721c59SFrançois Revol	exit 1
841cb721c59SFrançois Revolfi
842cb721c59SFrançois Revol
843338b8dc3SIngo Weinhold# create output directory
8446e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
845338b8dc3SIngo Weinhold
8462ebcd86dSIngo Weinholdif [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
8472ebcd86dSIngo Weinhold	invalidCommand=$sourceDir/build/scripts/host_build_only
8482ebcd86dSIngo Weinhold	HAIKU_AR=$invalidCommand
8492ebcd86dSIngo Weinhold	HAIKU_CC=$invalidCommand
8502ebcd86dSIngo Weinhold	HAIKU_LD=$invalidCommand
8512ebcd86dSIngo Weinhold	HAIKU_OBJCOPY=$invalidCommand
8522ebcd86dSIngo Weinhold	HAIKU_RANLIB=$invalidCommand
8532ebcd86dSIngo Weinhold	HAIKU_ELFEDIT=$invalidCommand
854d6f80927SJonathan Schleifer	HAIKU_NASM=$invalidCommand
8552ebcd86dSIngo Weinhold	HAIKU_STRIP=$invalidCommand
8562ebcd86dSIngo Weinholdelse
857483b28e4SIngo Weinhold	# On Haiku determine target architectures and tools automatically.
858c0e8cc1aSIngo Weinhold	if [ -z "$targetArchs" ]; then
859483b28e4SIngo Weinhold		if [ $HOST_PLATFORM != haiku_host ]; then
860483b28e4SIngo Weinhold			echo "Please specify the build tools to use or build (via" \
861eaef83a9SJeroen Oortwijn				"--cross-tools-prefix or --build-cross-tools) or specify a" \
862483b28e4SIngo Weinhold				"host-only build (--host-only)." >&2
8637f9beaf1SOliver Tappe			echo "For more info, invoke $0 --help"
864483b28e4SIngo Weinhold			exit 1
865483b28e4SIngo Weinhold		fi
866483b28e4SIngo Weinhold
867483b28e4SIngo Weinhold		# determine primary architecture
868dda53eaeSIngo Weinhold		targetArch=`package list -i /system/packages/haiku-*.hpkg \
869483b28e4SIngo Weinhold			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
870483b28e4SIngo Weinhold		is_in_list "$targetArch" "$supportedTargetArchs" || (
871483b28e4SIngo Weinhold			echo "Unsupported target architecture: \"$targetArch\"" >&2
872483b28e4SIngo Weinhold			exit 1
873483b28e4SIngo Weinhold		)
874c0e8cc1aSIngo Weinhold		targetArchs=$targetArch
875483b28e4SIngo Weinhold
876c0e8cc1aSIngo Weinhold		set_default_value HAIKU_AR_$targetArch			ar
877c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CC_$targetArch			gcc
878c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LD_$targetArch			ld
879c0e8cc1aSIngo Weinhold		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
880c0e8cc1aSIngo Weinhold		set_default_value HAIKU_RANLIB_$targetArch		ranlib
881c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
882c0e8cc1aSIngo Weinhold		set_default_value HAIKU_STRIP_$targetArch		strip
883483b28e4SIngo Weinhold
884483b28e4SIngo Weinhold		# determine secondary architectures
885483b28e4SIngo Weinhold		for targetArch in $supportedTargetArchs; do
88680262a91SMatt Madia			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
887483b28e4SIngo Weinhold				targetArchs="$targetArchs $targetArch"
888483b28e4SIngo Weinhold				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
889483b28e4SIngo Weinhold				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
890483b28e4SIngo Weinhold				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
891483b28e4SIngo Weinhold				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
892483b28e4SIngo Weinhold				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
893483b28e4SIngo Weinhold				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
894483b28e4SIngo Weinhold				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
895483b28e4SIngo Weinhold			fi
896483b28e4SIngo Weinhold		done
897483b28e4SIngo Weinhold
898483b28e4SIngo Weinhold		# The target architectures might have been specified explicitly.
899483b28e4SIngo Weinhold		if [ -n "$haikuTargetArchs" ]; then
900483b28e4SIngo Weinhold			for targetArch in $haikuTargetArchs; do
901483b28e4SIngo Weinhold				is_in_list "$targetArch" "$targetArchs" || (
902483b28e4SIngo Weinhold					echo "Unsupported target architecture: \"$targetArch\"." \
903483b28e4SIngo Weinhold						"Only native architectures of the host platform can" \
904483b28e4SIngo Weinhold						"be specified." >&2
905483b28e4SIngo Weinhold					exit 1
906483b28e4SIngo Weinhold				)
907483b28e4SIngo Weinhold			done
908483b28e4SIngo Weinhold			targetArchs="$haikuTargetArchs"
909483b28e4SIngo Weinhold		fi
910c0e8cc1aSIngo Weinhold	fi
911c0e8cc1aSIngo Weinhold
91268ccc989SIngo Weinhold	isPrimaryArch=1
913c0e8cc1aSIngo Weinhold	for targetArch in $targetArchs; do
9146c5fcb4fSAugustin Cavalier		# Note: targetArch is "unknown<n>" at this point if a cross-tools
915c0e8cc1aSIngo Weinhold		# prefix was specified. The standard_gcc_settings call below will get
916c0e8cc1aSIngo Weinhold		# the actual architecture.
917c0e8cc1aSIngo Weinhold
91832b50a88SAugustin Cavalier		if test "${HAIKU_PACKAGING_ARCHS#*$targetArch\b}" != "$HAIKU_PACKAGING_ARCHS"; then
9196c5fcb4fSAugustin Cavalier			# somehow we wound up with a duplicate arch; skip this one
9206c5fcb4fSAugustin Cavalier			continue
9216c5fcb4fSAugustin Cavalier		fi
9226c5fcb4fSAugustin Cavalier
923c0e8cc1aSIngo Weinhold		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
924c0e8cc1aSIngo Weinhold
925338b8dc3SIngo Weinhold		# build cross tools from sources
926c0e8cc1aSIngo Weinhold		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
927c0e8cc1aSIngo Weinhold			crossToolsDir="$outputDir/cross-tools-$targetArch"
928c0e8cc1aSIngo Weinhold			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
929c0e8cc1aSIngo Weinhold			script="$buildCrossToolsScript"
9308304ec7cSIngo Weinhold			scriptArgs=
931c0e8cc1aSIngo Weinhold			if [ $targetArch != x86_gcc2 ]; then
9328304ec7cSIngo Weinhold				script="${script}_gcc4"
9338304ec7cSIngo Weinhold				scriptArgs="$targetMachine"
9341e93288eSJérôme Duval				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
9351e93288eSJérôme Duval					$useGccGraphiteDefault
936c0e8cc1aSIngo Weinhold			fi
93768ccc989SIngo Weinhold			secondaryArch=
93868ccc989SIngo Weinhold			if [ -z "$isPrimaryArch" ]; then
93968ccc989SIngo Weinhold				secondaryArch=$targetArch
94068ccc989SIngo Weinhold			fi
94186de8c37SIngo Weinhold
94286de8c37SIngo Weinhold			case $HOST_PLATFORM in
94386de8c37SIngo Weinhold				freebsd|openbsd)	MAKE=gmake;;
94486de8c37SIngo Weinhold				*)					MAKE=make;;
94586de8c37SIngo Weinhold			esac
94686de8c37SIngo Weinhold
9471f839e89Swaddlesplash			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
94886de8c37SIngo Weinhold				MAKE=$MAKE \
94968ccc989SIngo Weinhold				SECONDARY_ARCH=$secondaryArch \
950c0e8cc1aSIngo Weinhold				HAIKU_USE_GCC_GRAPHITE=`get_variable \
951c0e8cc1aSIngo Weinhold					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
952b3ece905SJérôme Duval				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
9534da6cf84SFrançois Revol				HAIKU_USE_GDB="$gdbSources" \
9548304ec7cSIngo Weinhold				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
9558304ec7cSIngo Weinhold					"$crossToolsDir" $buildCrossToolsJobs || exit 1
956825700d3SAugustin Cavalier			else
957825700d3SAugustin Cavalier				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
958825700d3SAugustin Cavalier			fi
959c0e8cc1aSIngo Weinhold			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
960338b8dc3SIngo Weinhold		fi
961338b8dc3SIngo Weinhold
962c0e8cc1aSIngo Weinhold		# prepare gcc settings and get the actual target architecture
963a7bddff1SJonathan Schleifer		if [ $useClang = 1 ]; then
964c44472c5SAugustin Cavalier			gcc="$HAIKU_clang -target ${targetMachine}"
965ddf7f643SAugustin Cavalier			if [ ! -z "${crossToolsPrefix}" ]; then
966ddf7f643SAugustin Cavalier				gcc="$gcc -B ${crossToolsPrefix}"
967ddf7f643SAugustin Cavalier			fi
9681f6fe055SAugustin Cavalier
9691f6fe055SAugustin Cavalier			# Clang's compiler intrinsics are not compatible with GCC's or even
9701f6fe055SAugustin Cavalier			# across versions of Clang, so we must collect them for use in the build.
9711f6fe055SAugustin Cavalier			mkdir -p "$outputDir/clang_headers" || exit 1
97220c61bb7SAugustin Cavalier			clangHeadersDir=`$gcc -print-resource-dir`/include/
97320c61bb7SAugustin Cavalier			case $targetArch in
97420c61bb7SAugustin Cavalier				x86*) cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1 ;;
97520c61bb7SAugustin Cavalier				ppc*) cp $clangHeadersDir/*altivec* "$outputDir/clang_headers" || exit 1 ;;
97620c61bb7SAugustin Cavalier				arm*) cp $clangHeadersDir/*arm* "$outputDir/clang_headers" || exit 1 ;;
97720c61bb7SAugustin Cavalier			esac
978d73993ffSAugustin Cavalier		elif [ -z "${crossToolsPrefix}" ]; then
979d73993ffSAugustin Cavalier			gcc=`get_variable HAIKU_CC_$targetArch`
980a7bddff1SJonathan Schleifer		else
981c0e8cc1aSIngo Weinhold			gcc="${crossToolsPrefix}gcc"
982a7bddff1SJonathan Schleifer		fi
983c0e8cc1aSIngo Weinhold		standard_gcc_settings "$gcc"
984c0e8cc1aSIngo Weinhold		targetArch=$standard_gcc_settings_targetArch
985338b8dc3SIngo Weinhold
986c0e8cc1aSIngo Weinhold		# set default values for flags
987c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CPPFLAGS_$targetArch	""
988c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CCFLAGS_$targetArch		""
989c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CXXFLAGS_$targetArch	""
990252e4f62SAugustin Cavalier		set_default_value HAIKU_LINKFLAGS_$targetArch	""
991c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LDFLAGS_$targetArch		""
992241b61a7SAugustin Cavalier		set_default_value HAIKU_ARFLAGS_$targetArch		cru
993c0e8cc1aSIngo Weinhold		set_default_value HAIKU_UNARFLAGS_$targetArch	x
994338b8dc3SIngo Weinhold
995c0e8cc1aSIngo Weinhold		# Override the cross tools variables, if the tools were built or a
996c0e8cc1aSIngo Weinhold		# prefix was specified.
9971c307243SAugustin Cavalier		if [ $useClang = 1 ]; then
9981c307243SAugustin Cavalier			get_build_tool_path LD_$targetArch ld.lld
9991c307243SAugustin Cavalier			get_build_tool_path ELFEDIT_$targetArch elfedit
10001c307243SAugustin Cavalier		elif [ -n "$crossToolsPrefix" ]; then
1001c0e8cc1aSIngo Weinhold			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
1002c0e8cc1aSIngo Weinhold			case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
1003133e4131SJérôme Duval				4.*|5.*|6.*|7.*|8.*)
1004c0e8cc1aSIngo Weinhold					get_build_tool_path ELFEDIT_$targetArch \
1005c0e8cc1aSIngo Weinhold						${crossToolsPrefix}elfedit
1006bd16f0ddSAlex Smith				;;
1007bd16f0ddSAlex Smith			esac
100852a38012Sejakowatz		fi
10091c307243SAugustin Cavalier		if [ -n "$crossToolsPrefix" ]; then
10101c307243SAugustin Cavalier			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
10111c307243SAugustin Cavalier			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
10121c307243SAugustin Cavalier			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
10131c307243SAugustin Cavalier			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
10141c307243SAugustin Cavalier		fi
101552a38012Sejakowatz
1016ef57df3dSIngo Weinhold		# check whether the Haiku compiler really targets Haiku
1017c0e8cc1aSIngo Weinhold		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
1018c0e8cc1aSIngo Weinhold		case "$targetMachine" in
1019eedc3d0bSIngo Weinhold			*-*-haiku)	;;
1020c0e8cc1aSIngo Weinhold			*)
1021c0e8cc1aSIngo Weinhold				echo The compiler specified as Haiku target compiler is not a \
1022c0e8cc1aSIngo Weinhold				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
1023eedc3d0bSIngo Weinhold				echo compiler: $HAIKU_CC
1024c0e8cc1aSIngo Weinhold				echo compiler is configured for target: $targetMachine
1025eedc3d0bSIngo Weinhold				exit 1 ;;
1026eedc3d0bSIngo Weinhold		esac
1027c0e8cc1aSIngo Weinhold
1028c0e8cc1aSIngo Weinhold		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
102968ccc989SIngo Weinhold		isPrimaryArch=
1030c0e8cc1aSIngo Weinhold	done
10312ebcd86dSIngo Weinholdfi
1032eedc3d0bSIngo Weinhold
103352a38012Sejakowatz# Generate BuildConfig
10347c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
1035825700d3SAugustin Cavalier# -- WARNING --
1036825700d3SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1037825700d3SAugustin Cavalier# overwritten the next time configure is run.
1038825700d3SAugustin Cavalier#
1039825700d3SAugustin Cavalier#d ${currentDir}
1040825700d3SAugustin Cavalier#c ${configurePath}
1041825700d3SAugustin Cavalier#e ${configureEnvirons}
1042825700d3SAugustin Cavalier#a ${configureArgs}
104352a38012Sejakowatz
10447c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
1045b57e7df9SAugustin CavalierTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
1046b57e7df9SAugustin CavalierHAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
1047338b8dc3SIngo Weinhold
1048b57e7df9SAugustin CavalierHAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
104976fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES		?= "${HAIKU_INCLUDE_SOURCES}" ;
10507c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY		?= "${HAIKU_INCLUDE_3RDPARTY}" ;
10517c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY	?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
1052b57e7df9SAugustin Cavalier
10537c4641d0SOliver TappeHAIKU_USE_GCC_PIPE			?= "${HAIKU_USE_GCC_PIPE}" ;
10547986925fSIngo WeinholdHAIKU_HOST_USE_32BIT		?= "${HAIKU_HOST_USE_32BIT}" ;
10557986925fSIngo WeinholdHAIKU_HOST_USE_XATTR		?= "${HAIKU_HOST_USE_XATTR}" ;
1056bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF	?= "${HAIKU_HOST_USE_XATTR_REF}" ;
10572ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY		?= "${HAIKU_HOST_BUILD_ONLY}" ;
1058eccc7665SIngo Weinhold
1059b57e7df9SAugustin CavalierHOST_CC						?= ${CC} ;
10607c4641d0SOliver TappeHOST_GCC_RAW_VERSION		?= ${HOST_GCC_RAW_VERSION} ;
10617c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
10627c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
10637c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
1064b57e7df9SAugustin CavalierHOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
10652a5d0aafSIngo WeinholdHOST_SHA256					?= ${HOST_SHA256} ;
106617dc34acSAndrew LindesayHOST_PYTHON					?= ${HOST_PYTHON} ;
1067b57e7df9SAugustin CavalierHAIKU_NASM					?= ${HAIKU_NASM} ;
1068b57e7df9SAugustin Cavalier
10691d91b371SAugustin CavalierHAIKU_BUILD_ATTRIBUTES_DIR	?= "${HAIKU_BUILD_ATTRIBUTES_DIR}" ;
10708b5934c9SIngo Weinhold
1071e173a1ecSIngo WeinholdHOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1072e173a1ecSIngo WeinholdHAIKU_PORTS					?= ${HAIKU_PORTS} ;
1073e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1074c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1075e173a1ecSIngo Weinhold
1076c4786ea6SlilloEOF
1077c4786ea6Slillo
1078c0e8cc1aSIngo Weinholdfor targetArch in $HAIKU_PACKAGING_ARCHS; do
1079c0e8cc1aSIngo Weinhold	variables="
1080c1249957SAugustin Cavalier		HAIKU_CC					HAIKU_CC
1081c1249957SAugustin Cavalier		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1082c1249957SAugustin Cavalier		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1083c0e8cc1aSIngo Weinhold		HAIKU_CPU					HAIKU_CPU
1084c1249957SAugustin Cavalier		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1085c1249957SAugustin Cavalier		HAIKU_GCC_RAW_VERSION		HAIKU_GCC_RAW_VERSION
1086c1249957SAugustin Cavalier		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1087c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1088c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
1089c0e8cc1aSIngo Weinhold		HAIKU_AR					HAIKU_AR
1090c0e8cc1aSIngo Weinhold		HAIKU_LD					HAIKU_LD
1091c0e8cc1aSIngo Weinhold		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1092c0e8cc1aSIngo Weinhold		HAIKU_RANLIB				HAIKU_RANLIB
1093c0e8cc1aSIngo Weinhold		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1094c0e8cc1aSIngo Weinhold		HAIKU_STRIP					HAIKU_STRIP
1095c0e8cc1aSIngo Weinhold		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1096c0e8cc1aSIngo Weinhold		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1097c0e8cc1aSIngo Weinhold		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1098252e4f62SAugustin Cavalier		HAIKU_LINKFLAGS				HAIKU_LINKFLAGS
1099c0e8cc1aSIngo Weinhold		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1100c0e8cc1aSIngo Weinhold		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1101c0e8cc1aSIngo Weinhold		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1102c0e8cc1aSIngo Weinhold		"
1103c0e8cc1aSIngo Weinhold	set -- $variables
1104c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1105c0e8cc1aSIngo Weinhold		value=`get_variable ${2}_$targetArch`
1106c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1107c0e8cc1aSIngo Weinhold		shift 2
1108c0e8cc1aSIngo Weinhold	done
1109b1e5b60cSAxel Dörfler
1110c0e8cc1aSIngo Weinhold	# For variables that may have long values, distribute them over multiple
1111c0e8cc1aSIngo Weinhold	# lines so that jam doesn't hit the maximum line length.
1112c0e8cc1aSIngo Weinhold	variables="
111366a7f29fSJérôme Duval		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
1114c0e8cc1aSIngo Weinhold		"
1115c0e8cc1aSIngo Weinhold	set -- $variables
1116c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1117c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1118c0e8cc1aSIngo Weinhold		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1119c0e8cc1aSIngo Weinhold			>> "$buildConfigFile"
1120c0e8cc1aSIngo Weinhold		echo "    ;" >> "$buildConfigFile"
1121c0e8cc1aSIngo Weinhold		shift 2
1122c0e8cc1aSIngo Weinhold	done
1123c0e8cc1aSIngo Weinholddone
1124b1e5b60cSAxel Dörfler
1125b1e5b60cSAxel Dörfler
11263facc270SAugustin Cavalier# Generate a Jamfile in the output directory.
1127338b8dc3SIngo Weinhold
1128338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
11293facc270SAugustin Cavalier# -- WARNING --
11303facc270SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
11313facc270SAugustin Cavalier# overwritten the next time configure is run.
1132338b8dc3SIngo Weinhold
11333facc270SAugustin CavalierHAIKU_TOP			= $(relative_to "${sourceDir}" "${outputDir}") ;
11343facc270SAugustin CavalierHAIKU_OUTPUT_DIR	= . ;
1135338b8dc3SIngo Weinhold
1136338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1137338b8dc3SIngo Weinhold
1138338b8dc3SIngo WeinholdEOF
1139d73993ffSAugustin Cavalier
1140d73993ffSAugustin Cavalierecho "Configured successfully!"
1141