xref: /haiku/configure (revision ddf7f6436591e141c219bf8d10ed54624ca89cd0)
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
351b38c341SAlexander von Gluck IV                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k", "arm"
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).
40c0e8cc1aSIngo Weinhold                              For the first --build-cross-tools the
41c0e8cc1aSIngo Weinhold                              <build tools dir> argument must be specified and
42c0e8cc1aSIngo Weinhold                              for the subsequent ones it must be omitted.
43eccc7665SIngo Weinhold  --cross-tools-prefix <prefix>
44eccc7665SIngo Weinhold                              Assume cross compilation. <prefix> should be a
45eccc7665SIngo Weinhold                              path to the directory where the cross
46eccc7665SIngo Weinhold                              compilation tools are located, plus the platform
470da9c208SIngo Weinhold                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
48eccc7665SIngo Weinhold                              This overrides the HAIKU_* tool variables.
49a66c32ddSIngo Weinhold  --distro-compatibility <level>
50a66c32ddSIngo Weinhold                              The distribution's level of compatibility with
51a66c32ddSIngo Weinhold                              the official Haiku distribution. The generated
52a66c32ddSIngo Weinhold                              files will contain the respective trademarks
53a66c32ddSIngo Weinhold                              accordingly.
54a66c32ddSIngo Weinhold                              official -- the official Haiku distribution.
55a66c32ddSIngo Weinhold                              compatible -- a Haiku Compatible (tm) distro.
56a66c32ddSIngo Weinhold                              default -- any other distro (default value).
572ebcd86dSIngo Weinhold  --host-only                 Configure for building tools for the build host
582ebcd86dSIngo Weinhold                              only. Haiku cannot be built when configured like
592ebcd86dSIngo Weinhold                              this.
6076fa0be3SIngo Weinhold  --include-sources           Includes the source code of projects that require
6176fa0be3SIngo Weinhold                              either an offer of source code or a copy of the
6276fa0be3SIngo Weinhold                              patched sources. This is preferable when
6376fa0be3SIngo Weinhold                              distributing on physical mediums.
641974210fSFrançois Revol  --include-3rdparty          Include 3rdparty/ in the build system.
654880ae01SJessica Hamilton  -j<n>                       Only relevant for --build-cross-tools. Is passed
664880ae01SJessica Hamilton                              on to the make building the build tools.
67aa2e5ecaSOliver Tappe  --no-downloads              Do not download anything. Useful when trying to
68aa2e5ecaSOliver Tappe                              bootstrap and build Haiku from source only.
69483b28e4SIngo Weinhold  --target-arch <arch>        Haiku only: Specify the target architecture to
70483b28e4SIngo Weinhold                              build for. Must be one of the architectures of the
71483b28e4SIngo Weinhold                              host system. The installed build tools for that
72483b28e4SIngo Weinhold                              architecture will be used.
73483b28e4SIngo Weinhold                              This option can be specified multiple times. The
74483b28e4SIngo Weinhold                              first occurrence specifies the primary
75483b28e4SIngo Weinhold                              architecture of the Haiku to build, subsequent
76483b28e4SIngo Weinhold                              ones the secondary architectures.
77d73993ffSAugustin Cavalier  --use-clang <arch>          Build with host Clang instead of GCC cross
78d73993ffSAugustin Cavalier                              compiler, targeting <arch>
79eccc7665SIngo Weinhold  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
805a34a443SFrançois Revol                              process, but uses more memory.
81ed38d2efSJerome Duval  --use-gcc-graphite          Build with GCC Graphite engine for loop
82a5c952dbSAugustin Cavalier                              optimizations. (Only for GCC 4+.)
830385b065SIngo Weinhold  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
84fc2c93fbSAugustin Cavalier  --no-full-xattr             Do not use Linux/*BSD/Darwin's native extended file
85fc2c93fbSAugustin Cavalier                              attributes as Haiku attributes. If they are still
86fc2c93fbSAugustin Cavalier                              available, they will be used to store hashes for
87fc2c93fbSAugustin Cavalier                              the attribute emulation layer.
88fc2c93fbSAugustin Cavalier  --no-xattr                  Do not use Linux/*BSD/Darwin's native extended file
89fc2c93fbSAugustin Cavalier                              attributes for Haiku extended attributes at all,
90fc2c93fbSAugustin Cavalier                              even if they are available.
914da6cf84SFrançois Revol  --with-gdb <gdb sources dir>
924da6cf84SFrançois Revol                              specify the path to a GDB source dir, to build
934da6cf84SFrançois Revol                              GDB for each arch we build the cross-tools for.
94338b8dc3SIngo Weinhold
95338b8dc3SIngo Weinholdenvironment variables:
9663701e7dSOliver Tappe  CC                          The host compiler. Defaults to "gcc".
9765706842SAugustin Cavalier  HAIKU_AR_<arch>             The static library archiver for <arch>.
98c0e8cc1aSIngo Weinhold                              Defaults to "ar".
9965706842SAugustin Cavalier  HAIKU_CC_<arch>             The compiler for <arch>. Defaults to "gcc".
10065706842SAugustin Cavalier  HAIKU_LD_<arch>             The <arch> linker. Defaults to "ld".
10165706842SAugustin Cavalier  HAIKU_OBJCOPY_<arch>        The <arch> objcopy to be used. Defaults to
102c0e8cc1aSIngo Weinhold                              "objcopy".
10365706842SAugustin Cavalier  HAIKU_RANLIB_<arch>         The static library indexer for <arch>. Defaults
104c0e8cc1aSIngo Weinhold                              to "ranlib".
10565706842SAugustin Cavalier  HAIKU_STRIP_<arch>          The <arch> strip command. Defaults to "strip".
106a04a520bSJonathan Schleifer  HAIKU_NASM                  The nasm assembler (x86 and x86_64 only).
107c0e8cc1aSIngo Weinhold  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
108c0e8cc1aSIngo Weinhold                              <arch>. Defaults to "".
109c0e8cc1aSIngo Weinhold  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
110c0e8cc1aSIngo Weinhold                              Defaults to "".
111c0e8cc1aSIngo Weinhold  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
112c0e8cc1aSIngo Weinhold                              Defaults to "".
113c0e8cc1aSIngo Weinhold  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
114c0e8cc1aSIngo Weinhold                              Defaults to "".
115c0e8cc1aSIngo Weinhold  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
116c0e8cc1aSIngo Weinhold                              architecture <arch> for archiving. Defaults to
117c0e8cc1aSIngo Weinhold                              "cru".
118c0e8cc1aSIngo Weinhold  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
119c0e8cc1aSIngo Weinhold                              architecture <arch> for unarchiving. Defaults to
120c0e8cc1aSIngo Weinhold                              "x".
12164f6da31SIngo Weinhold
122c0e8cc1aSIngo WeinholdNon-default output directories:
12364f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
12464f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
12564f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
12664f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
12764f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
12864f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
12964f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
13064f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
13164f6da31SIngo Weinhold  non-default location and running jam.
13264f6da31SIngo Weinhold
13364f6da31SIngo Weinhold
134022fa244SIngo WeinholdEOF
135022fa244SIngo Weinhold}
136022fa244SIngo Weinhold
137022fa244SIngo Weinhold# assertparam
138022fa244SIngo Weinhold#
139022fa244SIngo Weinhold# Checks whether at least one parameter is left.
140022fa244SIngo Weinhold#
141022fa244SIngo Weinholdassertparam()
142022fa244SIngo Weinhold{
14320ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
144022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
145022fa244SIngo Weinhold		exit 1
146022fa244SIngo Weinhold	fi
147022fa244SIngo Weinhold}
148022fa244SIngo Weinhold
14920ab75e6SIngo Weinhold# assertparams
15020ab75e6SIngo Weinhold#
15120ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
15220ab75e6SIngo Weinhold#
15320ab75e6SIngo Weinholdassertparams()
15420ab75e6SIngo Weinhold{
15520ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
15620ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
15720ab75e6SIngo Weinhold		exit 1
15820ab75e6SIngo Weinhold	fi
15920ab75e6SIngo Weinhold}
16020ab75e6SIngo Weinhold
161e173a1ecSIngo Weinhold# absolute_path
162e173a1ecSIngo Weinhold#
163e173a1ecSIngo Weinhold# returns the absolute path of a given path.
164e173a1ecSIngo Weinhold#
165e173a1ecSIngo Weinholdabsolute_path()
166e173a1ecSIngo Weinhold{
1676a4f3954SFrançois Revol	if [ "x$1" != "x${1#/}" ]; then
168e173a1ecSIngo Weinhold		echo "$1"
169e173a1ecSIngo Weinhold	else
170e173a1ecSIngo Weinhold		echo "`pwd`/$1"
171e173a1ecSIngo Weinhold	fi
172e173a1ecSIngo Weinhold}
173e173a1ecSIngo Weinhold
17439d444a3SArvind S Raj# check_dir_exists
17539d444a3SArvind S Raj#
17639d444a3SArvind S Raj# check if a directory exists or not
17739d444a3SArvind S Raj#
17839d444a3SArvind S Rajcheck_dir_exists()
17939d444a3SArvind S Raj{
18039d444a3SArvind S Raj	if [ -d "$1" ]; then
18139d444a3SArvind S Raj		return 0
18239d444a3SArvind S Raj	else
18339d444a3SArvind S Raj		return 1
18439d444a3SArvind S Raj	fi
18539d444a3SArvind S Raj}
18639d444a3SArvind S Raj
187502882dbSJessica Hamilton# check_file_exists
188502882dbSJessica Hamilton#
189502882dbSJessica Hamilton# check if a file exists or not
190502882dbSJessica Hamilton#
191502882dbSJessica Hamiltoncheck_file_exists()
192502882dbSJessica Hamilton{
193502882dbSJessica Hamilton	if [ -f "$1" ]; then
194502882dbSJessica Hamilton		return 0
195502882dbSJessica Hamilton	else
196502882dbSJessica Hamilton		return 1
197502882dbSJessica Hamilton	fi
198502882dbSJessica Hamilton}
199502882dbSJessica Hamilton
2009a001156SOliver Tappe# real_path
2019a001156SOliver Tappe#
2029a001156SOliver Tappe# returns the realpath of a symbolic link.
2039a001156SOliver Tappe#
2049a001156SOliver Tappereal_path()
2059a001156SOliver Tappe{
2069a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
2079a001156SOliver Tappe}
2089a001156SOliver Tappe
209e5d446fcSAlexander von Gluck IV# valid_toolchain
210e5d446fcSAlexander von Gluck IV#
2111f839e89Swaddlesplash# check if a toolchain is valid
212e5d446fcSAlexander von Gluck IV#
213e5d446fcSAlexander von Gluck IVvalid_toolchain()
214e5d446fcSAlexander von Gluck IV{
215e5d446fcSAlexander von Gluck IV	TRIPLET="$1"
216e5d446fcSAlexander von Gluck IV	BASE="$2"
2171f839e89Swaddlesplash	SOURCE="$3"
218e5d446fcSAlexander von Gluck IV	if [ ! -d "$BASE" ]; then
2191f839e89Swaddlesplash		return 1
220e5d446fcSAlexander von Gluck IV	fi
221e5d446fcSAlexander von Gluck IV	if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
2221f839e89Swaddlesplash		[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
2231f839e89Swaddlesplash			[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
2241f839e89Swaddlesplash		return $?
225e5d446fcSAlexander von Gluck IV	fi
2261f839e89Swaddlesplash	return 1
227e5d446fcSAlexander von Gluck IV}
228e5d446fcSAlexander von Gluck IV
22909c5682dSIngo Weinhold# standard_gcc_settings
23009c5682dSIngo Weinhold#
23109c5682dSIngo Weinhold# Sets the variables for a GCC platform.
23209c5682dSIngo Weinhold#
23309c5682dSIngo Weinholdstandard_gcc_settings()
23409c5682dSIngo Weinhold{
23565706842SAugustin Cavalier	local gcc="$1"
236c0e8cc1aSIngo Weinhold
237138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
238b29b48b1SMatt Madia		readlink="greadlink -e"
239138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
240b29b48b1SMatt Madia		readlink=realpath
2419a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
242b29b48b1SMatt Madia		readlink="readlink -e"
2439a001156SOliver Tappe	else
2449a001156SOliver Tappe		readlink=real_path
245b4b6d83cSMatt Madia	fi
246138f5fb4SIngo Weinhold
24709c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
248c0e8cc1aSIngo Weinhold	local gcclib=`$gcc -print-libgcc-file-name`
249c0e8cc1aSIngo Weinhold	local gccdir=`dirname ${gcclib}`
2505b0f7b1bSOliver Tappe
251c0e8cc1aSIngo Weinhold	local gccRawVersion=`$gcc -dumpversion`
252c0e8cc1aSIngo Weinhold	local gccMachine=`$gcc -dumpmachine`
253338b8dc3SIngo Weinhold
254fc8967f1SIngo Weinhold	# determine architecture from machine triple
255c0e8cc1aSIngo Weinhold	case $gccMachine in
256c0e8cc1aSIngo Weinhold		arm-*)		targetCpu=arm;;
257c0e8cc1aSIngo Weinhold		i?86-*)		targetCpu=x86;;
258c0e8cc1aSIngo Weinhold		m68k-*)		targetCpu=m68k;;
259c0e8cc1aSIngo Weinhold		powerpc-*)	targetCpu=ppc;;
260c0e8cc1aSIngo Weinhold		x86_64-*)	targetCpu=x86_64;;
261fc8967f1SIngo Weinhold		*)
262c0e8cc1aSIngo Weinhold			echo "Unsupported gcc target machine: $gccMachine" >&2
263fc8967f1SIngo Weinhold			exit 1
264fc8967f1SIngo Weinhold			;;
265fc8967f1SIngo Weinhold	esac
266fc8967f1SIngo Weinhold
267c0e8cc1aSIngo Weinhold	local targetArch=$targetCpu
268fc8967f1SIngo Weinhold
269c0e8cc1aSIngo Weinhold	case $gccRawVersion in
2706cc8eecfSOliver Tappe		2.9*)
2715b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
2725b0f7b1bSOliver Tappe			# if an older one is installed
273c0e8cc1aSIngo Weinhold			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
2745b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
2755b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
2765b0f7b1bSOliver Tappe				exit 1;
2775b0f7b1bSOliver Tappe			fi
278aaeadfcbSAlex Smith
279c0e8cc1aSIngo Weinhold			targetArch=x86_gcc2
2805b0f7b1bSOliver Tappe			;;
2818b5934c9SIngo Weinhold	esac
28265ad1ba3SAlex Smith
283c0e8cc1aSIngo Weinhold	local bootLibgcc
284c0e8cc1aSIngo Weinhold	local bootLibSupCxx
28566a7f29fSJérôme Duval	local bootCxxHeaders
286c0e8cc1aSIngo Weinhold	case $gccMachine in
2874591ebc9SAlex Smith		x86_64-*)
28866a7f29fSJérôme Duval			# Boot loader is 32-bit, need the 32-bit libs and c++ config
28911ae3c5fSOliver Tappe			bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a`
290c0e8cc1aSIngo Weinhold			bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
29166a7f29fSJérôme Duval
29266a7f29fSJérôme Duval			local headersBase=$gccdir/../../../..
29366a7f29fSJérôme Duval			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
29466a7f29fSJérôme Duval			if [ ! -d $headers ]; then
29566a7f29fSJérôme Duval				headers=$headersBase/include/c++/$gccRawVersion
29666a7f29fSJérôme Duval			fi
29766a7f29fSJérôme Duval			bootCxxHeaders="$headers/$gccMachine/32"
2984591ebc9SAlex Smith			;;
299338b8dc3SIngo Weinhold	esac
300c0e8cc1aSIngo Weinhold
301c0e8cc1aSIngo Weinhold	# determine whether graphite loop optimization should/can be used
302c0e8cc1aSIngo Weinhold	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
303c0e8cc1aSIngo Weinhold	if [ -z "$useGraphite" ]; then
304c0e8cc1aSIngo Weinhold		useGraphite=$useGccGraphiteDefault
305c0e8cc1aSIngo Weinhold	fi
306c0e8cc1aSIngo Weinhold
307c0e8cc1aSIngo Weinhold	if [ "$useGraphite" != 0 ]; then
308c0e8cc1aSIngo Weinhold		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
309c0e8cc1aSIngo Weinhold		if [ $? != 0 ]; then
310c0e8cc1aSIngo Weinhold			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
311c0e8cc1aSIngo Weinhold			useGraphite=0
312c0e8cc1aSIngo Weinhold		fi
313c0e8cc1aSIngo Weinhold	fi
314c0e8cc1aSIngo Weinhold
315c0e8cc1aSIngo Weinhold	set_variable HAIKU_CPU_$targetArch $targetCpu
316c0e8cc1aSIngo Weinhold
317c0e8cc1aSIngo Weinhold	get_build_tool_path CC_$targetArch "$gcc"
318a7bddff1SJonathan Schleifer	set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
319c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
320c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
321c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
32266a7f29fSJérôme Duval	set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
32311ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
32411ae3c5fSOliver Tappe	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
325c0e8cc1aSIngo Weinhold	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
326c0e8cc1aSIngo Weinhold
327c0e8cc1aSIngo Weinhold	standard_gcc_settings_targetArch=$targetArch
328c0e8cc1aSIngo Weinhold}
329c0e8cc1aSIngo Weinhold
330c0e8cc1aSIngo Weinhold# set_variable
331c0e8cc1aSIngo Weinhold#
332c0e8cc1aSIngo Weinhold# Set the value of a variable.
333c0e8cc1aSIngo Weinhold#
334c0e8cc1aSIngo Weinholdset_variable()
335c0e8cc1aSIngo Weinhold{
336c0e8cc1aSIngo Weinhold	eval "$1=\"$2\""
337c0e8cc1aSIngo Weinhold}
338c0e8cc1aSIngo Weinhold
339c0e8cc1aSIngo Weinhold# get_variable
340c0e8cc1aSIngo Weinhold#
341c0e8cc1aSIngo Weinhold# Echo the value of a variable.
342c0e8cc1aSIngo Weinhold#
343c0e8cc1aSIngo Weinholdget_variable()
344c0e8cc1aSIngo Weinhold{
345c0e8cc1aSIngo Weinhold	eval "echo \${$1}"
34609c5682dSIngo Weinhold}
34709c5682dSIngo Weinhold
348338b8dc3SIngo Weinhold# set_default_value
349338b8dc3SIngo Weinhold#
350338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
351338b8dc3SIngo Weinhold#
352338b8dc3SIngo Weinholdset_default_value()
353338b8dc3SIngo Weinhold{
3540838a930SJérôme Duval	eval "$1=\${$1-$2}"
355338b8dc3SIngo Weinhold}
356338b8dc3SIngo Weinhold
357338b8dc3SIngo Weinhold# get_build_tool_path
358338b8dc3SIngo Weinhold#
359338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
360338b8dc3SIngo Weinhold#
361338b8dc3SIngo Weinholdget_build_tool_path()
362338b8dc3SIngo Weinhold{
363338b8dc3SIngo Weinhold	local var="HAIKU_$1"
36465706842SAugustin Cavalier	local varval="`get_variable $var`"
36565706842SAugustin Cavalier	local cmd="$2"
366d73993ffSAugustin Cavalier
367e042a53bSAugustin Cavalier	if [ ! -z "$varval" ]; then
368d73993ffSAugustin Cavalier		# this variable is already set (probably by user) so grab its contents
369e042a53bSAugustin Cavalier		cmd=$varval
370d73993ffSAugustin Cavalier	fi
371d73993ffSAugustin Cavalier
372d73993ffSAugustin Cavalier	local path=${cmd%% *}
373338b8dc3SIngo Weinhold
374338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
37565706842SAugustin Cavalier		# get absolute path from relative path
376a559f87aSFrançois Revol		local oldPwd="`pwd`"
377a559f87aSFrançois Revol		cd "`dirname "$path"`"
378a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
379338b8dc3SIngo Weinhold		cd $oldPwd
380338b8dc3SIngo Weinhold	else
3817fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
382d73993ffSAugustin Cavalier			echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
383338b8dc3SIngo Weinhold			exit 1
384338b8dc3SIngo Weinhold		}
385338b8dc3SIngo Weinhold	fi
386338b8dc3SIngo Weinhold
38765706842SAugustin Cavalier	if test "${cmd#* }" != "$cmd"; then
38865706842SAugustin Cavalier		# $cmd contains arguments, so preserve them (and only them)
38965706842SAugustin Cavalier		cmd=${cmd#* }
39065706842SAugustin Cavalier	else
39165706842SAugustin Cavalier		# $cmd does not contain arguments, so unset it
39265706842SAugustin Cavalier		cmd=
39365706842SAugustin Cavalier	fi
39465706842SAugustin Cavalier	eval "$var=\"$path $cmd\""
395338b8dc3SIngo Weinhold}
396338b8dc3SIngo Weinhold
397a5c952dbSAugustin Cavalier# check_native_xattrs
398a5c952dbSAugustin Cavalier#
399a5c952dbSAugustin Cavalier# Checks the host platform's support for extended attributes.
400a5c952dbSAugustin Cavalier# 0: no support, 1: only enough for xattr-ref, 2: full support
401a5c952dbSAugustin Cavalier#
402a5c952dbSAugustin Cavaliercheck_native_xattrs()
403a5c952dbSAugustin Cavalier{
404a5c952dbSAugustin Cavalier	local xattr_set=
405a5c952dbSAugustin Cavalier	local xattr_set_args=
406a5c952dbSAugustin Cavalier	local xattr_get=
407a5c952dbSAugustin Cavalier	local xattr_get_args=
408a5c952dbSAugustin Cavalier	case $HOST_PLATFORM in
409503ef6d4SAugustin Cavalier		haiku_host)
410503ef6d4SAugustin Cavalier			xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
411503ef6d4SAugustin Cavalier			xattr_get="catattr"; xattr_get_args="\$NAME"
412503ef6d4SAugustin Cavalier			;;
413a5c952dbSAugustin Cavalier		darwin)
414a5c952dbSAugustin Cavalier			xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
415a5c952dbSAugustin Cavalier			xattr_get="xattr"; xattr_get_args="-p \$NAME"
416a5c952dbSAugustin Cavalier			;;
417a5c952dbSAugustin Cavalier		freebsd)
418a5c952dbSAugustin Cavalier			xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
419a5c952dbSAugustin Cavalier			xattr_get="getextattr"; xattr_get_args="user \$NAME"
420a5c952dbSAugustin Cavalier			;;
421a5c952dbSAugustin Cavalier		linux)
422a5c952dbSAugustin Cavalier			xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
423a5c952dbSAugustin Cavalier			xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
424a5c952dbSAugustin Cavalier			;;
425a5c952dbSAugustin Cavalier		*)
426a5c952dbSAugustin Cavalier			return 0
427a5c952dbSAugustin Cavalier			;;
428a5c952dbSAugustin Cavalier	esac
429a5c952dbSAugustin Cavalier	if ! type $xattr_set >/dev/null 2>&1; then
430a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_set, assuming host has no extended attributes"
431a5c952dbSAugustin Cavalier		return 0
432a5c952dbSAugustin Cavalier	elif ! type $xattr_get >/dev/null 2>&1; then
433a5c952dbSAugustin Cavalier		echo "$0: could not find $xattr_get, assuming host has no extended attributes"
434a5c952dbSAugustin Cavalier		return 0
435a5c952dbSAugustin Cavalier	fi
436a5c952dbSAugustin Cavalier
43743f5f35aSAugustin Cavalier	mkdir -p "$outputDir"
438a5c952dbSAugustin Cavalier	echo "xattr test file" >"$outputDir/xattrtest"
439a5c952dbSAugustin Cavalier	local i=0
440a5c952dbSAugustin Cavalier	# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
441a5c952dbSAugustin Cavalier	# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
442a5c952dbSAugustin Cavalier	while [ $i -lt 2 ]; do
443a5c952dbSAugustin Cavalier		local j=0
444a5c952dbSAugustin Cavalier		while [ $j -lt 3 ]; do
445a5c952dbSAugustin Cavalier			NAME=attr$j
446a5c952dbSAugustin Cavalier			VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
447a5c952dbSAugustin Cavalier			if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
448a5c952dbSAugustin Cavalier				echo "$0: warning: could not generate test data for extended attributes"
449a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
450a5c952dbSAugustin Cavalier				return $i
451a5c952dbSAugustin Cavalier			elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
452a5c952dbSAugustin Cavalier					"$outputDir/xattrtest" >/dev/null 2>&1 ; then
453a5c952dbSAugustin Cavalier				rm "$outputDir/xattrtest"
454a5c952dbSAugustin Cavalier				return $i
455a5c952dbSAugustin Cavalier			fi
456a5c952dbSAugustin Cavalier			j=$((j+1))
457a5c952dbSAugustin Cavalier		done
458a5c952dbSAugustin Cavalier		i=$((i+1))
459a5c952dbSAugustin Cavalier	done
460a5c952dbSAugustin Cavalier	rm "$outputDir/xattrtest"
461a5c952dbSAugustin Cavalier	return 2
462a5c952dbSAugustin Cavalier}
463a5c952dbSAugustin Cavalier
464483b28e4SIngo Weinholdis_in_list()
465483b28e4SIngo Weinhold{
466483b28e4SIngo Weinhold	local element
467483b28e4SIngo Weinhold	for element in $2; do
468483b28e4SIngo Weinhold		if [ "$1" = "$element" ]; then
469483b28e4SIngo Weinhold			return 0
470483b28e4SIngo Weinhold		fi
471483b28e4SIngo Weinhold	done
472483b28e4SIngo Weinhold	return 1
473483b28e4SIngo Weinhold}
474483b28e4SIngo Weinhold
4757f9beaf1SOliver Tappe# check for --help or -h and show usage immediately
4767f9beaf1SOliver Tappeif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
4778b420c2fSOliver Tappe	usage; exit 0;
4788b420c2fSOliver Tappefi
4798b420c2fSOliver Tappe
480c6c03d56SAugustin Cavalier# ensure umask is not too restrictive
481c6c03d56SAugustin Cavalierif [ $(umask) -gt 22 ]; then
482c6c03d56SAugustin Cavalier	echo "Your umask is too restrictive (should be: <= 0022; is actually:" $(umask)")"
483c6c03d56SAugustin Cavalier	exit 1
484c6c03d56SAugustin Cavalierfi
4858b420c2fSOliver Tappe
486338b8dc3SIngo Weinhold# get cwd and the source directory
487338b8dc3SIngo WeinholdcurrentDir=`pwd`
4886e7c6fe5SIngo Weinholdcd `dirname "$0"`
489338b8dc3SIngo WeinholdsourceDir=`pwd`
4906e7c6fe5SIngo Weinholdcd "$currentDir"
491338b8dc3SIngo Weinhold
49255d267a4SFrançois Revol# backup the passed arguments
49355d267a4SFrançois RevolconfigureArgs="$@"
494825700d3SAugustin CavalierconfigurePath=$0
495825700d3SAugustin Cavalier
496825700d3SAugustin Cavalier# backup relevant environs
497825700d3SAugustin CavalierconfigureEnvirons=
498825700d3SAugustin Cavalierfor var in `env`; do
499825700d3SAugustin Cavalier	case "$var" in
500825700d3SAugustin Cavalier		CC\=*|HAIKU*\=*)
501825700d3SAugustin Cavalier			configureEnvirons="$configureEnvirons $var"
502825700d3SAugustin Cavalier			;;
503825700d3SAugustin Cavalier	esac
504825700d3SAugustin Cavalierdone
50555d267a4SFrançois Revol
5067c4641d0SOliver Tappe# internal default parameter values
507022fa244SIngo Weinhold#
50852a38012Sejakowatzplatform=`uname`
5095abd9a46SIngo WeinholdplatformMachine=`uname  -m`
510c0e8cc1aSIngo WeinholdtargetArchs=
511338b8dc3SIngo WeinholdbuildCrossTools=
51229ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
51360d8d8fcSIngo WeinholdbuildCrossToolsJobs=
514c2b76f7fSJonathan SchleiferuseClang=0
515c0e8cc1aSIngo WeinholduseGccGraphiteDefault=0
516c0e8cc1aSIngo WeinholdunknownArchIndex=1
517483b28e4SIngo WeinholdhaikuTargetArchs=
5184da6cf84SFrançois RevolgdbSources=
5197c4641d0SOliver Tappe
52063701e7dSOliver Tappeif [ -z "$CC" ]; then
52163701e7dSOliver Tappe	CC=gcc
52263701e7dSOliver Tappefi
52363701e7dSOliver Tappe
5247c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
5257c4641d0SOliver Tappe#
52663701e7dSOliver TappeHOST_GCC_RAW_VERSION=`$CC -dumpversion`
52763701e7dSOliver TappeHOST_GCC_MACHINE=`$CC -dumpmachine`
52876fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
5297c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
5307c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
5317c4641d0SOliver TappeTARGET_PLATFORM=haiku
5327c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
5337986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
534fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR=
535fc2c93fbSAugustin CavalierHAIKU_HOST_USE_XATTR_REF=
5362ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY=0
537f04f7042SNiels Sascha ReedijkHOST_EXTENDED_REGEX_SED="sed -r"
53863701e7dSOliver TappeHOST_GCC_LD=`$CC -print-prog-name=ld`
53963701e7dSOliver TappeHOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
5402a5d0aafSIngo WeinholdHOST_SHA256=
541e173a1ecSIngo WeinholdHOST_HAIKU_PORTER=
542e173a1ecSIngo WeinholdHAIKU_PORTS=
543e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS=
544c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP=0
545e70c4c64SPulkoMandyHAIKU_BOOT_BOARD=
546aa2e5ecaSOliver TappeHAIKU_NO_DOWNLOADS=0
5472a5d0aafSIngo Weinhold
548c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS=
549c0e8cc1aSIngo Weinhold
550a04a520bSJonathan Schleiferset_default_value HAIKU_NASM		nasm
551c0e8cc1aSIngo Weinhold
5523942ca0dSIngo Weinholdif sha256sum < /dev/null > /dev/null 2>&1; then
5532a5d0aafSIngo Weinhold	HOST_SHA256=sha256sum
5543942ca0dSIngo Weinholdelif sha256 < /dev/null > /dev/null 2>&1; then
5552a5d0aafSIngo Weinhold	HOST_SHA256="sha256 -q"
556b5a871b1SNiels Sascha Reedijkelif shasum < /dev/null > /dev/null 2>&1; then
557b5a871b1SNiels Sascha Reedijk	HOST_SHA256="shasum -a 256"
5582a5d0aafSIngo Weinholdelse
5592a5d0aafSIngo Weinhold	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
5602a5d0aafSIngo Weinhold	exit 1
5612a5d0aafSIngo Weinholdfi
562338b8dc3SIngo Weinhold
56384edb1a1SAxel DörflerhaikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
564a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
565af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
566483b28e4SIngo WeinholdsupportedTargetArchs="
567483b28e4SIngo Weinhold	arm
568483b28e4SIngo Weinhold	m68k
569483b28e4SIngo Weinhold	ppc
570483b28e4SIngo Weinhold	x86
571483b28e4SIngo Weinhold	x86_64
572483b28e4SIngo Weinhold	x86_gcc2
573483b28e4SIngo Weinhold	"
574af4bf973SOliver Tappe
5757c4641d0SOliver Tappe# determine output directory
5767c4641d0SOliver Tappeif [ "$currentDir" = "$sourceDir" ]; then
5777c4641d0SOliver Tappe	outputDir=$currentDir/generated
5787c4641d0SOliver Tappeelse
5797c4641d0SOliver Tappe	outputDir=$currentDir
5807c4641d0SOliver Tappefi
5817c4641d0SOliver TappebuildOutputDir="$outputDir/build"
5827c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
5837c4641d0SOliver TappebuildConfigFile="$buildOutputDir/BuildConfig"
5847c4641d0SOliver Tappe
5857c4641d0SOliver Tappe# check for update request
5867c4641d0SOliver Tappeif [ "$1" = "--update" ]; then
5877c4641d0SOliver Tappe	if ! [ -e "$buildConfigFile" ]; then
5887c4641d0SOliver Tappe		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
5897c4641d0SOliver Tappe		exit 1
5907c4641d0SOliver Tappe	fi
591825700d3SAugustin Cavalier	# get last configure invocation and flags from BuildConfig and call ourselves with it
592825700d3SAugustin Cavalier	lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
593825700d3SAugustin Cavalier	lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
594825700d3SAugustin Cavalier	lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
595825700d3SAugustin Cavalier	lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
596825700d3SAugustin Cavalier	if [ -z "$lastConfig" ]; then
597825700d3SAugustin Cavalier		echo "$0 --update: The previous configure invocation was not properly" \
598825700d3SAugustin Cavalier			"encoded into '$buildConfigFile' - updating not possible."
5997c4641d0SOliver Tappe		exit 1
6007c4641d0SOliver Tappe	fi
601825700d3SAugustin Cavalier	cd $lastPwd
602fc2c93fbSAugustin Cavalier	if [ -n "$lastEnv" ]; then
603825700d3SAugustin Cavalier		export $lastEnv
604fc2c93fbSAugustin Cavalier	fi
605825700d3SAugustin Cavalier	$lastConfig $lastArgs
606825700d3SAugustin Cavalier	exit $?
6077c4641d0SOliver Tappefi
6087c4641d0SOliver Tappe
609022fa244SIngo Weinhold# parse parameters
610022fa244SIngo Weinhold#
61120ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
612022fa244SIngo Weinhold	case "$1" in
613e173a1ecSIngo Weinhold		--bootstrap)
614e173a1ecSIngo Weinhold			assertparams "$1" 3 $#
615e173a1ecSIngo Weinhold			HOST_HAIKU_PORTER="`absolute_path $2`"
616e173a1ecSIngo Weinhold			HAIKU_PORTS_CROSS="`absolute_path $3`"
617e173a1ecSIngo Weinhold			HAIKU_PORTS="`absolute_path $4`"
618c9dd05ffSJonathan Schleifer			HAIKU_IS_BOOTSTRAP=1
619c9dd05ffSJonathan Schleifer			HAIKU_NO_DOWNLOADS=1
620502882dbSJessica Hamilton			check_file_exists "$HOST_HAIKU_PORTER" || (
621502882dbSJessica Hamilton				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
62239d444a3SArvind S Raj				exit 1
62339d444a3SArvind S Raj			)
62439d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS" || (
62539d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS" >&2
62639d444a3SArvind S Raj				exit 1
62739d444a3SArvind S Raj			)
62839d444a3SArvind S Raj			check_dir_exists "$HAIKU_PORTS_CROSS" || (
62939d444a3SArvind S Raj				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
63039d444a3SArvind S Raj				exit 1
63139d444a3SArvind S Raj			)
632e173a1ecSIngo Weinhold			shift 4
633e173a1ecSIngo Weinhold			;;
634c0e8cc1aSIngo Weinhold		--build-cross-tools)
635c0e8cc1aSIngo Weinhold			if [ -z "$buildCrossTools" ]; then
6369b0dd528SIngo Weinhold				assertparams "$1" 2 $#
637c0e8cc1aSIngo Weinhold				targetArch=$2
6389b0dd528SIngo Weinhold				buildCrossTools=$3
6399b0dd528SIngo Weinhold				shift 3
640c0e8cc1aSIngo Weinhold			else
641c0e8cc1aSIngo Weinhold				assertparam "$1" $#
642c0e8cc1aSIngo Weinhold				targetArch=$2
643c0e8cc1aSIngo Weinhold				shift 2
644c0e8cc1aSIngo Weinhold			fi
645c0e8cc1aSIngo Weinhold			case "$targetArch" in
646c0e8cc1aSIngo Weinhold				x86_gcc2)	targetMachine=i586-pc-haiku;;
647c0e8cc1aSIngo Weinhold				x86)		targetMachine=i586-pc-haiku;;
648c0e8cc1aSIngo Weinhold				x86_64)		targetMachine=x86_64-unknown-haiku;;
649c0e8cc1aSIngo Weinhold				ppc)		targetMachine=powerpc-apple-haiku;;
650c0e8cc1aSIngo Weinhold				m68k)		targetMachine=m68k-unknown-haiku;;
651c0e8cc1aSIngo Weinhold				arm)		targetMachine=arm-unknown-haiku;;
652c0e8cc1aSIngo Weinhold				*)
653c0e8cc1aSIngo Weinhold					echo "Unsupported target architecture: $2" >&2
654c0e8cc1aSIngo Weinhold					exit 1
655c0e8cc1aSIngo Weinhold					;;
656c0e8cc1aSIngo Weinhold			esac
657c0e8cc1aSIngo Weinhold			set_variable buildCrossToolsMachine_$targetArch $targetMachine
658c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
659c0e8cc1aSIngo Weinhold			HAIKU_PACKAGING_ARCHS=
6609b0dd528SIngo Weinhold			;;
6619b0dd528SIngo Weinhold		--cross-tools-prefix)
6629b0dd528SIngo Weinhold			assertparam "$1" $#
663c0e8cc1aSIngo Weinhold			targetArch=unknown${unknownArchIndex}
664c0e8cc1aSIngo Weinhold			set_variable crossToolsPrefix_$targetArch "$2"
665c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
666c0e8cc1aSIngo Weinhold			HAIKU_PACKAGING_ARCHS=
667d68208faSMatt Madia			unknownArchIndex=$(($unknownArchIndex + 1))
6689b0dd528SIngo Weinhold			shift 2
6699b0dd528SIngo Weinhold			;;
670a66c32ddSIngo Weinhold		--distro-compatibility)
6719b0dd528SIngo Weinhold			assertparam "$1" $#
6727c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
6737c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
674a66c32ddSIngo Weinhold				official)	;;
675a66c32ddSIngo Weinhold				compatible)	;;
676a66c32ddSIngo Weinhold				default)	;;
677a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
6787c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
679a66c32ddSIngo Weinhold							exit 1;;
680a66c32ddSIngo Weinhold			esac
6819b0dd528SIngo Weinhold			shift 2
6829b0dd528SIngo Weinhold			;;
6832ebcd86dSIngo Weinhold		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
68476fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
6857c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
68660d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
687aa2e5ecaSOliver Tappe		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
688483b28e4SIngo Weinhold		--target-arch)
689483b28e4SIngo Weinhold			assertparam "$1" $#
690483b28e4SIngo Weinhold			targetArch=$2
691483b28e4SIngo Weinhold			shift 2
692483b28e4SIngo Weinhold			if [ ! "$platform" = Haiku ]; then
693483b28e4SIngo Weinhold				echo "--target-arch can only be specified on Haiku." >&2
694483b28e4SIngo Weinhold				exit 1
695483b28e4SIngo Weinhold			fi
696483b28e4SIngo Weinhold			is_in_list "$targetArch" "$supportedTargetArchs" || (
697483b28e4SIngo Weinhold				echo "Unsupported target architecture: \"$targetArch\"" >&2
698483b28e4SIngo Weinhold				exit 1
699483b28e4SIngo Weinhold			)
700483b28e4SIngo Weinhold			haikuTargetArchs="$haikuTargetArchs $targetArch"
701483b28e4SIngo Weinhold			;;
702d73993ffSAugustin Cavalier		--use-clang)
703d73993ffSAugustin Cavalier			assertparam "$1" $#
704d73993ffSAugustin Cavalier			targetArch=$2
705d73993ffSAugustin Cavalier			useClang=1
706d73993ffSAugustin Cavalier			case "$targetArch" in
707d73993ffSAugustin Cavalier				x86)		targetMachine=i586-pc-haiku;;
708d73993ffSAugustin Cavalier				x86_64)		targetMachine=x86_64-unknown-haiku;;
709d73993ffSAugustin Cavalier				*)
710d73993ffSAugustin Cavalier					echo "Unsupported target architecture: $2" >&2
711d73993ffSAugustin Cavalier					exit 1
712d73993ffSAugustin Cavalier					;;
713d73993ffSAugustin Cavalier			esac
71465706842SAugustin Cavalier			get_build_tool_path clang clang
71536f28382SAugustin Cavalier			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
71636f28382SAugustin Cavalier					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
71765706842SAugustin Cavalier				set_variable crossToolsPrefix_$targetArch llvm-
71865706842SAugustin Cavalier			fi
71936f28382SAugustin Cavalier			if ! test "${targetArchs#*$targetArch}" != "$targetArchs"; then
72036f28382SAugustin Cavalier				# we have not already added this arch to targetArchs, so add it now
721d73993ffSAugustin Cavalier				targetArchs="$targetArchs $targetArch"
72236f28382SAugustin Cavalier			fi
723d73993ffSAugustin Cavalier			HAIKU_PACKAGING_ARCHS=
724d73993ffSAugustin Cavalier			shift 2
725d73993ffSAugustin Cavalier			;;
7267c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
727c0e8cc1aSIngo Weinhold		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
7287986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
729fc2c93fbSAugustin Cavalier		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
730fc2c93fbSAugustin Cavalier		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
7314da6cf84SFrançois Revol		--with-gdb)	gdbSources=$2; shift 2;;
732022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
733022fa244SIngo Weinhold	esac
734022fa244SIngo Weinholddone
735022fa244SIngo Weinhold
7360df3cc9cSIngo Weinhold# detect the build platform
737338b8dc3SIngo Weinholdcase "${platform}" in
7387c4641d0SOliver Tappe	Darwin)	HOST_PLATFORM=darwin ;;
7397c4641d0SOliver Tappe	FreeBSD)	HOST_PLATFORM=freebsd
7407986925fSIngo Weinhold				if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
7415abd9a46SIngo Weinhold					echo Unsupported platform: FreeBSD ${platformMachine}
742308c212cSIngo Weinhold					exit 1
743308c212cSIngo Weinhold				fi	;;
7447c4641d0SOliver Tappe	Haiku)	HOST_PLATFORM=haiku_host ;;
7457c4641d0SOliver Tappe	Linux)	HOST_PLATFORM=linux ;;
7467c4641d0SOliver Tappe	OpenBSD) HOST_PLATFORM=openbsd ;;
7477c4641d0SOliver Tappe	SunOS)	HOST_PLATFORM=sunos ;;
7487c4641d0SOliver Tappe	CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
749338b8dc3SIngo Weinhold	*)		echo Unsupported platform: ${platform}
7504cbe4925SAxel Dörfler			exit 1 ;;
7514cbe4925SAxel Dörfleresac
75252a38012Sejakowatz
7530962132cSAlex Smith# check for case-sensitive filesystem
7540962132cSAlex Smithmkdir haikuCaseTest 2>/dev/null
7550962132cSAlex Smithmkdir haikucasetest 2>/dev/null
7560962132cSAlex SmithcaseInsensitive=$?
75797f5a0bdSAlex Smithrmdir haikuCaseTest haikucasetest 2>/dev/null
7580962132cSAlex Smithif [ $caseInsensitive != 0 ]; then
7593ecc5287SMichael Lotz	echo "You need a case-sensitive file-system to build Haiku."
7600962132cSAlex Smith	if [ $HOST_PLATFORM = "darwin" ]; then
7617a05e252SJohn Scipione		echo "You can create a case-sensitive disk image using Disk Utility."
7623ecc5287SMichael Lotz	fi
7630962132cSAlex Smith	exit 1
7643ecc5287SMichael Lotzfi
7653ecc5287SMichael Lotz
766a5c952dbSAugustin Cavalier# check xattr support
767503ef6d4SAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
768a5c952dbSAugustin Cavalier	check_native_xattrs
769a5c952dbSAugustin Cavalier	attrSupport=$?
770fc2c93fbSAugustin Cavalier	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
771fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR=1
772a5c952dbSAugustin Cavalier	elif [ $attrSupport = 1 ]; then
773fc2c93fbSAugustin Cavalier		HAIKU_HOST_USE_XATTR_REF=1
774a5c952dbSAugustin Cavalier	fi
775a5c952dbSAugustin Cavalierfi
776fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
777fc2c93fbSAugustin Cavalierif [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
778a5c952dbSAugustin Cavalier
779f04f7042SNiels Sascha Reedijk# determine how to invoke sed with extended regexp support for non-GNU sed
780f04f7042SNiels Sascha Reedijkif [ $HOST_PLATFORM = "darwin" ]; then
781f04f7042SNiels Sascha Reedijk	HOST_EXTENDED_REGEX_SED="sed -E"
782f04f7042SNiels Sascha Reedijkfi
783f04f7042SNiels Sascha Reedijk
784cb721c59SFrançois Revol# check if nasm can actually output ELF files
785cb721c59SFrançois Revol# (the stock version in OSX can't)
786cb721c59SFrançois Revol# XXX: should probably only test for x86* arch
7873e6c09cdSAdrien Destuguesif [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
788cb721c59SFrançois Revol	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
789cb721c59SFrançois Revol	if [ $HOST_PLATFORM = "darwin" ]; then
790cb721c59SFrançois Revol		echo "You can install it from Mac Ports."
791cb721c59SFrançois Revol		echo "Mac Ports is available at: http://www.macports.org/"
792cb721c59SFrançois Revol	fi
793cb721c59SFrançois Revol	exit 1
794cb721c59SFrançois Revolfi
795cb721c59SFrançois Revol
796338b8dc3SIngo Weinhold# create output directory
7976e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
798338b8dc3SIngo Weinhold
7992ebcd86dSIngo Weinholdif [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
8002ebcd86dSIngo Weinhold	invalidCommand=$sourceDir/build/scripts/host_build_only
8012ebcd86dSIngo Weinhold	HAIKU_AR=$invalidCommand
8022ebcd86dSIngo Weinhold	HAIKU_CC=$invalidCommand
8032ebcd86dSIngo Weinhold	HAIKU_LD=$invalidCommand
8042ebcd86dSIngo Weinhold	HAIKU_OBJCOPY=$invalidCommand
8052ebcd86dSIngo Weinhold	HAIKU_RANLIB=$invalidCommand
8062ebcd86dSIngo Weinhold	HAIKU_ELFEDIT=$invalidCommand
807d6f80927SJonathan Schleifer	HAIKU_NASM=$invalidCommand
8082ebcd86dSIngo Weinhold	HAIKU_STRIP=$invalidCommand
8092ebcd86dSIngo Weinholdelse
810c0e8cc1aSIngo Weinhold	if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
811c0e8cc1aSIngo Weinhold		targetArchs="$HAIKU_PACKAGING_ARCHS"
812c0e8cc1aSIngo Weinhold	fi
813c0e8cc1aSIngo Weinhold	HAIKU_PACKAGING_ARCHS=
814c0e8cc1aSIngo Weinhold
815483b28e4SIngo Weinhold	# On Haiku determine target architectures and tools automatically.
816c0e8cc1aSIngo Weinhold	if [ -z "$targetArchs" ]; then
817483b28e4SIngo Weinhold		if [ $HOST_PLATFORM != haiku_host ]; then
818483b28e4SIngo Weinhold			echo "Please specify the build tools to use or build (via" \
819eaef83a9SJeroen Oortwijn				"--cross-tools-prefix or --build-cross-tools) or specify a" \
820483b28e4SIngo Weinhold				"host-only build (--host-only)." >&2
8217f9beaf1SOliver Tappe			echo "For more info, invoke $0 --help"
822483b28e4SIngo Weinhold			exit 1
823483b28e4SIngo Weinhold		fi
824483b28e4SIngo Weinhold
825483b28e4SIngo Weinhold		# determine primary architecture
826dda53eaeSIngo Weinhold		targetArch=`package list -i /system/packages/haiku-*.hpkg \
827483b28e4SIngo Weinhold			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
828483b28e4SIngo Weinhold		is_in_list "$targetArch" "$supportedTargetArchs" || (
829483b28e4SIngo Weinhold			echo "Unsupported target architecture: \"$targetArch\"" >&2
830483b28e4SIngo Weinhold			exit 1
831483b28e4SIngo Weinhold		)
832c0e8cc1aSIngo Weinhold		targetArchs=$targetArch
833483b28e4SIngo Weinhold
834c0e8cc1aSIngo Weinhold		set_default_value HAIKU_AR_$targetArch			ar
835c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CC_$targetArch			gcc
836c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LD_$targetArch			ld
837c0e8cc1aSIngo Weinhold		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
838c0e8cc1aSIngo Weinhold		set_default_value HAIKU_RANLIB_$targetArch		ranlib
839c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
840c0e8cc1aSIngo Weinhold		set_default_value HAIKU_STRIP_$targetArch		strip
841483b28e4SIngo Weinhold
842483b28e4SIngo Weinhold		# determine secondary architectures
843483b28e4SIngo Weinhold		for targetArch in $supportedTargetArchs; do
84480262a91SMatt Madia			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
845483b28e4SIngo Weinhold				targetArchs="$targetArchs $targetArch"
846483b28e4SIngo Weinhold				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
847483b28e4SIngo Weinhold				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
848483b28e4SIngo Weinhold				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
849483b28e4SIngo Weinhold				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
850483b28e4SIngo Weinhold				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
851483b28e4SIngo Weinhold				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
852483b28e4SIngo Weinhold				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
853483b28e4SIngo Weinhold			fi
854483b28e4SIngo Weinhold		done
855483b28e4SIngo Weinhold
856483b28e4SIngo Weinhold		# The target architectures might have been specified explicitly.
857483b28e4SIngo Weinhold		if [ -n "$haikuTargetArchs" ]; then
858483b28e4SIngo Weinhold			for targetArch in $haikuTargetArchs; do
859483b28e4SIngo Weinhold				is_in_list "$targetArch" "$targetArchs" || (
860483b28e4SIngo Weinhold					echo "Unsupported target architecture: \"$targetArch\"." \
861483b28e4SIngo Weinhold						"Only native architectures of the host platform can" \
862483b28e4SIngo Weinhold						"be specified." >&2
863483b28e4SIngo Weinhold					exit 1
864483b28e4SIngo Weinhold				)
865483b28e4SIngo Weinhold			done
866483b28e4SIngo Weinhold			targetArchs="$haikuTargetArchs"
867483b28e4SIngo Weinhold		fi
868c0e8cc1aSIngo Weinhold	fi
869c0e8cc1aSIngo Weinhold
87068ccc989SIngo Weinhold	isPrimaryArch=1
871c0e8cc1aSIngo Weinhold	for targetArch in $targetArchs; do
872c0e8cc1aSIngo Weinhold		# Note: targetArch is "unknown<n>" at this point, if a cross-tools
873c0e8cc1aSIngo Weinhold		# prefix was specified. The standard_gcc_settings call below will get
874c0e8cc1aSIngo Weinhold		# the actual architecture.
875c0e8cc1aSIngo Weinhold
876c0e8cc1aSIngo Weinhold		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
877c0e8cc1aSIngo Weinhold
878338b8dc3SIngo Weinhold		# build cross tools from sources
879c0e8cc1aSIngo Weinhold		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
880c0e8cc1aSIngo Weinhold			crossToolsDir="$outputDir/cross-tools-$targetArch"
881c0e8cc1aSIngo Weinhold			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
882c0e8cc1aSIngo Weinhold			script="$buildCrossToolsScript"
8838304ec7cSIngo Weinhold			scriptArgs=
884c0e8cc1aSIngo Weinhold			if [ $targetArch != x86_gcc2 ]; then
8858304ec7cSIngo Weinhold				script="${script}_gcc4"
8868304ec7cSIngo Weinhold				scriptArgs="$targetMachine"
8871e93288eSJérôme Duval				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
8881e93288eSJérôme Duval					$useGccGraphiteDefault
889c0e8cc1aSIngo Weinhold			fi
89068ccc989SIngo Weinhold			secondaryArch=
89168ccc989SIngo Weinhold			if [ -z "$isPrimaryArch" ]; then
89268ccc989SIngo Weinhold				secondaryArch=$targetArch
89368ccc989SIngo Weinhold			fi
89486de8c37SIngo Weinhold
89586de8c37SIngo Weinhold			case $HOST_PLATFORM in
89686de8c37SIngo Weinhold				freebsd|openbsd)	MAKE=gmake;;
89786de8c37SIngo Weinhold				*)					MAKE=make;;
89886de8c37SIngo Weinhold			esac
89986de8c37SIngo Weinhold
9001f839e89Swaddlesplash			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
90186de8c37SIngo Weinhold				MAKE=$MAKE \
90268ccc989SIngo Weinhold				SECONDARY_ARCH=$secondaryArch \
903c0e8cc1aSIngo Weinhold				HAIKU_USE_GCC_GRAPHITE=`get_variable \
904c0e8cc1aSIngo Weinhold					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
905b3ece905SJérôme Duval				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
9064da6cf84SFrançois Revol				HAIKU_USE_GDB="$gdbSources" \
9078304ec7cSIngo Weinhold				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
9088304ec7cSIngo Weinhold					"$crossToolsDir" $buildCrossToolsJobs || exit 1
909825700d3SAugustin Cavalier			else
910825700d3SAugustin Cavalier				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
911825700d3SAugustin Cavalier			fi
912c0e8cc1aSIngo Weinhold			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
913338b8dc3SIngo Weinhold		fi
914338b8dc3SIngo Weinhold
915c0e8cc1aSIngo Weinhold		# prepare gcc settings and get the actual target architecture
916a7bddff1SJonathan Schleifer		if [ $useClang = 1 ]; then
91765706842SAugustin Cavalier			gcc="$HAIKU_clang -target ${targetMachine} -no-integrated-as"
918*ddf7f643SAugustin Cavalier			if [ ! -z "${crossToolsPrefix}" ]; then
919*ddf7f643SAugustin Cavalier				gcc="$gcc -B ${crossToolsPrefix}"
920*ddf7f643SAugustin Cavalier			fi
9211f6fe055SAugustin Cavalier
9221f6fe055SAugustin Cavalier			# Clang's compiler intrinsics are not compatible with GCC's or even
9231f6fe055SAugustin Cavalier			# across versions of Clang, so we must collect them for use in the build.
9241f6fe055SAugustin Cavalier			mkdir -p "$outputDir/clang_headers" || exit 1
9251f6fe055SAugustin Cavalier			clangHeadersDir=`$gcc -print-resource-dir`/include/
9261f6fe055SAugustin Cavalier			cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1
927d73993ffSAugustin Cavalier		elif [ -z "${crossToolsPrefix}" ]; then
928d73993ffSAugustin Cavalier			gcc=`get_variable HAIKU_CC_$targetArch`
929a7bddff1SJonathan Schleifer		else
930c0e8cc1aSIngo Weinhold			gcc="${crossToolsPrefix}gcc"
931a7bddff1SJonathan Schleifer		fi
932c0e8cc1aSIngo Weinhold		standard_gcc_settings "$gcc"
933c0e8cc1aSIngo Weinhold		targetArch=$standard_gcc_settings_targetArch
934338b8dc3SIngo Weinhold
935c0e8cc1aSIngo Weinhold		# set default values for flags
936c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CPPFLAGS_$targetArch	""
937c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CCFLAGS_$targetArch		""
938c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CXXFLAGS_$targetArch	""
939c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LDFLAGS_$targetArch		""
940c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ARFLAGS_$targetArch		cru
941c0e8cc1aSIngo Weinhold		set_default_value HAIKU_UNARFLAGS_$targetArch	x
942338b8dc3SIngo Weinhold
943c0e8cc1aSIngo Weinhold		# Override the cross tools variables, if the tools were built or a
944c0e8cc1aSIngo Weinhold		# prefix was specified.
945b7777272SAlex Smith		if [ -n "$crossToolsPrefix" ]; then
946c0e8cc1aSIngo Weinhold			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
947c0e8cc1aSIngo Weinhold			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
948c0e8cc1aSIngo Weinhold			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
949c0e8cc1aSIngo Weinhold			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
950c0e8cc1aSIngo Weinhold			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
951c0e8cc1aSIngo Weinhold
952c0e8cc1aSIngo Weinhold			case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
953133e4131SJérôme Duval				4.*|5.*|6.*|7.*|8.*)
954c0e8cc1aSIngo Weinhold					get_build_tool_path ELFEDIT_$targetArch \
955c0e8cc1aSIngo Weinhold						${crossToolsPrefix}elfedit
956bd16f0ddSAlex Smith				;;
957bd16f0ddSAlex Smith			esac
95852a38012Sejakowatz		fi
95952a38012Sejakowatz
960ef57df3dSIngo Weinhold		# check whether the Haiku compiler really targets Haiku
961c0e8cc1aSIngo Weinhold		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
962c0e8cc1aSIngo Weinhold		case "$targetMachine" in
963eedc3d0bSIngo Weinhold			*-*-haiku)	;;
964c0e8cc1aSIngo Weinhold			*)
965c0e8cc1aSIngo Weinhold				echo The compiler specified as Haiku target compiler is not a \
966c0e8cc1aSIngo Weinhold				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
967eedc3d0bSIngo Weinhold				echo compiler: $HAIKU_CC
968c0e8cc1aSIngo Weinhold				echo compiler is configured for target: $targetMachine
969eedc3d0bSIngo Weinhold				exit 1 ;;
970eedc3d0bSIngo Weinhold		esac
971c0e8cc1aSIngo Weinhold
972c0e8cc1aSIngo Weinhold		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
97368ccc989SIngo Weinhold		isPrimaryArch=
974c0e8cc1aSIngo Weinhold	done
9752ebcd86dSIngo Weinholdfi
976eedc3d0bSIngo Weinhold
97752a38012Sejakowatz# Generate BuildConfig
9787c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
979825700d3SAugustin Cavalier# -- WARNING --
980825700d3SAugustin Cavalier# This file was AUTOMATICALLY GENERATED by configure, and will be completely
981825700d3SAugustin Cavalier# overwritten the next time configure is run.
982825700d3SAugustin Cavalier#
983825700d3SAugustin Cavalier#d ${currentDir}
984825700d3SAugustin Cavalier#c ${configurePath}
985825700d3SAugustin Cavalier#e ${configureEnvirons}
986825700d3SAugustin Cavalier#a ${configureArgs}
98752a38012Sejakowatz
9887c4641d0SOliver TappeTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
9897c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
990338b8dc3SIngo Weinhold
99176fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES				?= "${HAIKU_INCLUDE_SOURCES}" ;
9927c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY				?= "${HAIKU_INCLUDE_3RDPARTY}" ;
9937c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY			?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
9947c4641d0SOliver TappeHAIKU_USE_GCC_PIPE					?= "${HAIKU_USE_GCC_PIPE}" ;
9957986925fSIngo WeinholdHAIKU_HOST_USE_32BIT				?= "${HAIKU_HOST_USE_32BIT}" ;
9967986925fSIngo WeinholdHAIKU_HOST_USE_XATTR				?= "${HAIKU_HOST_USE_XATTR}" ;
997bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF			?= "${HAIKU_HOST_USE_XATTR_REF}" ;
9982ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY				?= "${HAIKU_HOST_BUILD_ONLY}" ;
999eccc7665SIngo Weinhold
1000c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
100165ad1ba3SAlex Smith
1002aa2e5ecaSOliver TappeHAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
1003aa2e5ecaSOliver Tappe
10047c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR	?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
1005338b8dc3SIngo Weinhold
1006d6f80927SJonathan SchleiferHAIKU_NASM					?= ${HAIKU_NASM} ;
1007e70c4c64SPulkoMandyHAIKU_BOOT_BOARD			?= ${HAIKU_BOOT_BOARD} ;
1008338b8dc3SIngo Weinhold
1009f04f7042SNiels Sascha ReedijkHOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
10107c4641d0SOliver TappeHOST_GCC_RAW_VERSION		?= ${HOST_GCC_RAW_VERSION} ;
10117c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
10127c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
10137c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
10142a5d0aafSIngo WeinholdHOST_SHA256					?= ${HOST_SHA256} ;
10158b5934c9SIngo Weinhold
1016e173a1ecSIngo WeinholdHOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1017e173a1ecSIngo WeinholdHAIKU_PORTS					?= ${HAIKU_PORTS} ;
1018e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1019c9dd05ffSJonathan SchleiferHAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1020e173a1ecSIngo Weinhold
1021c4786ea6SlilloEOF
1022c4786ea6Slillo
1023c0e8cc1aSIngo Weinholdfor targetArch in $HAIKU_PACKAGING_ARCHS; do
1024c0e8cc1aSIngo Weinhold	variables="
1025c0e8cc1aSIngo Weinhold		HAIKU_GCC_RAW_VERSION		HAIKU_GCC_RAW_VERSION
1026c0e8cc1aSIngo Weinhold		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1027c0e8cc1aSIngo Weinhold		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1028c0e8cc1aSIngo Weinhold		HAIKU_CPU					HAIKU_CPU
1029c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1030c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
1031c0e8cc1aSIngo Weinhold		HAIKU_AR					HAIKU_AR
1032c0e8cc1aSIngo Weinhold		HAIKU_CC					HAIKU_CC
1033c2b76f7fSJonathan Schleifer		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1034c0e8cc1aSIngo Weinhold		HAIKU_LD					HAIKU_LD
1035c0e8cc1aSIngo Weinhold		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1036c0e8cc1aSIngo Weinhold		HAIKU_RANLIB				HAIKU_RANLIB
1037c0e8cc1aSIngo Weinhold		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1038c0e8cc1aSIngo Weinhold		HAIKU_STRIP					HAIKU_STRIP
1039c0e8cc1aSIngo Weinhold		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1040c0e8cc1aSIngo Weinhold		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1041c0e8cc1aSIngo Weinhold		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1042c0e8cc1aSIngo Weinhold		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1043c0e8cc1aSIngo Weinhold		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1044c0e8cc1aSIngo Weinhold		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1045c0e8cc1aSIngo Weinhold		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1046c0e8cc1aSIngo Weinhold		"
1047c0e8cc1aSIngo Weinhold	set -- $variables
1048c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1049c0e8cc1aSIngo Weinhold		value=`get_variable ${2}_$targetArch`
1050c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1051c0e8cc1aSIngo Weinhold		shift 2
1052c0e8cc1aSIngo Weinhold	done
1053b1e5b60cSAxel Dörfler
1054c0e8cc1aSIngo Weinhold	# For variables that may have long values, distribute them over multiple
1055c0e8cc1aSIngo Weinhold	# lines so that jam doesn't hit the maximum line length.
1056c0e8cc1aSIngo Weinhold	variables="
105766a7f29fSJérôme Duval		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
1058c0e8cc1aSIngo Weinhold		"
1059c0e8cc1aSIngo Weinhold	set -- $variables
1060c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
1061c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1062c0e8cc1aSIngo Weinhold		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1063c0e8cc1aSIngo Weinhold			>> "$buildConfigFile"
1064c0e8cc1aSIngo Weinhold		echo "    ;" >> "$buildConfigFile"
1065c0e8cc1aSIngo Weinhold		shift 2
1066c0e8cc1aSIngo Weinhold	done
1067c0e8cc1aSIngo Weinholddone
1068b1e5b60cSAxel Dörfler
1069b1e5b60cSAxel Dörfler
10709b0dd528SIngo Weinhold# Generate a boot strap Jamfile in the output directory.
1071338b8dc3SIngo Weinhold
1072338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
1073338b8dc3SIngo Weinhold# automatically generated Jamfile
1074338b8dc3SIngo Weinhold
1075338b8dc3SIngo WeinholdHAIKU_TOP			= ${sourceDir} ;
1076338b8dc3SIngo WeinholdHAIKU_OUTPUT_DIR	= ${outputDir} ;
1077338b8dc3SIngo Weinhold
1078338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1079338b8dc3SIngo Weinhold
1080338b8dc3SIngo WeinholdEOF
1081d73993ffSAugustin Cavalier
1082d73993ffSAugustin Cavalierecho "Configured successfully!"
1083