xref: /haiku/configure (revision c0e8cc1a1368c6cc99ddf1c76f8826cd5a598fd2)
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:
15e173a1ecSIngo Weinhold  --bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo>
16e173a1ecSIngo Weinhold                              Prepare for a bootstrap build. No pre-built
17e173a1ecSIngo Weinhold                              packages will be used, instead they will be built
18e173a1ecSIngo Weinhold                              from the sources (in several phases).
19e173a1ecSIngo Weinhold                              <haikuporter> is the path to the haikuporter tool
20e173a1ecSIngo Weinhold                              suitable for the host platform.
21e173a1ecSIngo Weinhold                              <HaikuPorts cross repo> is the path to a checked
22e173a1ecSIngo Weinhold                              out HaikuPorts cross-compilation repository.
23e173a1ecSIngo Weinhold                              <HaikuPorts repo> is the path to a checked out
24e173a1ecSIngo Weinhold                              HaikuPorts repository.
25*c0e8cc1aSIngo Weinhold  --build-cross-tools <arch> [ <build tools dir> ]
26338b8dc3SIngo Weinhold                              Assume cross compilation. <build tools dir>
27338b8dc3SIngo Weinhold                              defines the location of the build tools sources.
28338b8dc3SIngo Weinhold                              They will be compiled and placed in the output
29a5b60fa8SOliver Tappe                              directory under "cross-tools". The HAIKU_* tools
30a5b60fa8SOliver Tappe                              variables will be set accordingly.
3120ab75e6SIngo Weinhold                              <arch> specifies the target architecture, either
32*c0e8cc1aSIngo Weinhold                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k", "arm",
33*c0e8cc1aSIngo Weinhold                              or "mipsel".
34*c0e8cc1aSIngo Weinhold                              This option and --cross-tools-prefix can be
35*c0e8cc1aSIngo Weinhold                              specified multiple times. The first cross tools
36*c0e8cc1aSIngo Weinhold                              specify the primary tools, the subsequent ones the
37*c0e8cc1aSIngo Weinhold                              secondary tools (for "hybrid" images).
38*c0e8cc1aSIngo Weinhold                              For the first --build-cross-tools the
39*c0e8cc1aSIngo Weinhold                              <build tools dir> argument must be specified and
40*c0e8cc1aSIngo Weinhold                              for the subsequent ones it must be omitted.
41eccc7665SIngo Weinhold  --cross-tools-prefix <prefix>
42eccc7665SIngo Weinhold                              Assume cross compilation. <prefix> should be a
43eccc7665SIngo Weinhold                              path to the directory where the cross
44eccc7665SIngo Weinhold                              compilation tools are located, plus the platform
450da9c208SIngo Weinhold                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
46eccc7665SIngo Weinhold                              This overrides the HAIKU_* tool variables.
47a66c32ddSIngo Weinhold  --distro-compatibility <level>
48a66c32ddSIngo Weinhold                              The distribution's level of compatibility with
49a66c32ddSIngo Weinhold                              the official Haiku distribution. The generated
50a66c32ddSIngo Weinhold                              files will contain the respective trademarks
51a66c32ddSIngo Weinhold                              accordingly.
52a66c32ddSIngo Weinhold                              official -- the official Haiku distribution.
53a66c32ddSIngo Weinhold                              compatible -- a Haiku Compatible (tm) distro.
54a66c32ddSIngo Weinhold                              default -- any other distro (default value).
5560d8d8fcSIngo Weinhold  --enable-multiuser          Enable experimental multiuser support.
56eccc7665SIngo Weinhold  --help                      Prints out this help.
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.
60eccc7665SIngo Weinhold  --include-gpl-addons        Include GPL licensed add-ons.
6167838392SAxel Dörfler  --include-patented-code     Enable code that is known to implemented patented
6267838392SAxel Dörfler                              ideas and techniques. If this option is not
6367838392SAxel Dörfler                              specified, the resulting distribution may still
6467838392SAxel Dörfler                              implement patented ideas and techniques. This
6567838392SAxel Dörfler                              option only disables code that is currently known
6667838392SAxel Dörfler                              to be problematic.
6776fa0be3SIngo Weinhold  --include-sources           Includes the source code of projects that require
6876fa0be3SIngo Weinhold                              either an offer of source code or a copy of the
6976fa0be3SIngo Weinhold                              patched sources. This is preferable when
7076fa0be3SIngo Weinhold                              distributing on physical mediums.
711974210fSFrançois Revol  --include-3rdparty          Include 3rdparty/ in the build system.
7260d8d8fcSIngo Weinhold  -j<n>                       Only relevant for --build-cross-tools and
7360d8d8fcSIngo Weinhold                              --build-cross-tools-gcc4. Is passed on to the
7460d8d8fcSIngo Weinhold                              make building the build tools.
757c4641d0SOliver Tappe  --target=TARGET             Select build target platform.
767c4641d0SOliver Tappe                              [default=${TARGET_PLATFORM}]
77a17b9c0cSshatty                              valid targets=r5,bone,dano,haiku
787c4641d0SOliver Tappe  --update                    re-runs last configure invocation [must be given
797c4641d0SOliver Tappe                              as first option!]
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
83ed38d2efSJerome Duval                              optimizations. Only for gcc 4.
840385b065SIngo Weinhold  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
85bc96e8f3SIngo Weinhold  --use-xattr                 Use Linux xattr respectively *BSD extattr support
86bc96e8f3SIngo Weinhold                              for BeOS attribute emulation. Warning: Make sure
87bc96e8f3SIngo Weinhold                              your file system supports sufficient attribute
88bc96e8f3SIngo Weinhold                              sizes (4 KB per file for all attributes won't
89bc96e8f3SIngo Weinhold                              suffice).
90bc96e8f3SIngo Weinhold  --use-xattr-ref             Use the generic BeOS attribute emulation, but use
91bc96e8f3SIngo Weinhold                              Linux xattr respectively *BSD extattr support to
92bc96e8f3SIngo Weinhold                              make it more robust (i.e. attribute mix-ups become
93bc96e8f3SIngo Weinhold                              less likely).
94338b8dc3SIngo Weinhold
95338b8dc3SIngo Weinholdenvironment variables:
96*c0e8cc1aSIngo Weinhold  HAIKU_AR_x86_gcc2           The static library archiver for x86_gcc2.
97*c0e8cc1aSIngo Weinhold                              Defaults to "ar".
98*c0e8cc1aSIngo Weinhold  HAIKU_CC_x86_gcc2           The x86_gcc2 compiler. Defaults to "gcc".
99*c0e8cc1aSIngo Weinhold  HAIKU_LD_x86_gcc2           The x86_gcc2 linker. Defaults to "ld".
100*c0e8cc1aSIngo Weinhold  HAIKU_OBJCOPY_x86_gcc2      The x86_gcc2 objcopy to be used. Defaults to
101*c0e8cc1aSIngo Weinhold                              "objcopy".
102*c0e8cc1aSIngo Weinhold  HAIKU_RANLIB_x86_gcc2       The static library indexer for x86_gcc2. Defaults
103*c0e8cc1aSIngo Weinhold                              to "ranlib".
104*c0e8cc1aSIngo Weinhold  HAIKU_STRIP_x86_gcc2        The x86_gcc2 strip command. Defaults to "strip".
10577e84f21SIngo Weinhold  HAIKU_YASM                  The yasm assembler (x86 only).
106*c0e8cc1aSIngo Weinhold  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
107*c0e8cc1aSIngo Weinhold                              <arch>. Defaults to "".
108*c0e8cc1aSIngo Weinhold  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
109*c0e8cc1aSIngo Weinhold                              Defaults to "".
110*c0e8cc1aSIngo Weinhold  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
111*c0e8cc1aSIngo Weinhold                              Defaults to "".
112*c0e8cc1aSIngo Weinhold  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
113*c0e8cc1aSIngo Weinhold                              Defaults to "".
114*c0e8cc1aSIngo Weinhold  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
115*c0e8cc1aSIngo Weinhold                              architecture <arch> for archiving. Defaults to
116*c0e8cc1aSIngo Weinhold                              "cru".
117*c0e8cc1aSIngo Weinhold  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
118*c0e8cc1aSIngo Weinhold                              architecture <arch> for unarchiving. Defaults to
119*c0e8cc1aSIngo Weinhold                              "x".
12064f6da31SIngo Weinhold
121*c0e8cc1aSIngo WeinholdNon-default output directories:
12264f6da31SIngo Weinhold  By default all objects, build configuration, and other related files are
12364f6da31SIngo Weinhold  stored in /path/to/haiku_source/generated.  To store objects in a non-default
12464f6da31SIngo Weinhold  location, run "../../relative/path/to/haiku_source/configure <options>" from
12564f6da31SIngo Weinhold  within your non-default location.  "jam [ options ] targets" can then be run
12664f6da31SIngo Weinhold  directly inside your non-default location.  Another option is to invoke "jam
12764f6da31SIngo Weinhold  [ options ] targets" from within haiku_source.  This can be accomplished by
12864f6da31SIngo Weinhold  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
12964f6da31SIngo Weinhold  jam or by creating a symlink of haiku_source/generated pointing to your
13064f6da31SIngo Weinhold  non-default location and running jam.
13164f6da31SIngo Weinhold
13264f6da31SIngo Weinhold
133022fa244SIngo WeinholdEOF
134022fa244SIngo Weinhold}
135022fa244SIngo Weinhold
136022fa244SIngo Weinhold# assertparam
137022fa244SIngo Weinhold#
138022fa244SIngo Weinhold# Checks whether at least one parameter is left.
139022fa244SIngo Weinhold#
140022fa244SIngo Weinholdassertparam()
141022fa244SIngo Weinhold{
14220ab75e6SIngo Weinhold	if [ $2 -lt 2 ]; then
143022fa244SIngo Weinhold		echo $0: \`$1\': Parameter expected.
144022fa244SIngo Weinhold		exit 1
145022fa244SIngo Weinhold	fi
146022fa244SIngo Weinhold}
147022fa244SIngo Weinhold
14820ab75e6SIngo Weinhold# assertparams
14920ab75e6SIngo Weinhold#
15020ab75e6SIngo Weinhold# Checks whether at least a certain number of parameters is left.
15120ab75e6SIngo Weinhold#
15220ab75e6SIngo Weinholdassertparams()
15320ab75e6SIngo Weinhold{
15420ab75e6SIngo Weinhold	if [ $3 -le $2 ]; then
15520ab75e6SIngo Weinhold		echo $0: \`$1\': Not enough parameters.
15620ab75e6SIngo Weinhold		exit 1
15720ab75e6SIngo Weinhold	fi
15820ab75e6SIngo Weinhold}
15920ab75e6SIngo Weinhold
160e173a1ecSIngo Weinhold# absolute_path
161e173a1ecSIngo Weinhold#
162e173a1ecSIngo Weinhold# returns the absolute path of a given path.
163e173a1ecSIngo Weinhold#
164e173a1ecSIngo Weinholdabsolute_path()
165e173a1ecSIngo Weinhold{
166e173a1ecSIngo Weinhold	if [[ "$1" == /* ]]; then
167e173a1ecSIngo Weinhold		echo "$1"
168e173a1ecSIngo Weinhold	else
169e173a1ecSIngo Weinhold		echo "`pwd`/$1"
170e173a1ecSIngo Weinhold	fi
171e173a1ecSIngo Weinhold}
172e173a1ecSIngo Weinhold
1739a001156SOliver Tappe# real_path
1749a001156SOliver Tappe#
1759a001156SOliver Tappe# returns the realpath of a symbolic link.
1769a001156SOliver Tappe#
1779a001156SOliver Tappereal_path()
1789a001156SOliver Tappe{
1799a001156SOliver Tappe	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
1809a001156SOliver Tappe}
1819a001156SOliver Tappe
18209c5682dSIngo Weinhold# standard_gcc_settings
18309c5682dSIngo Weinhold#
18409c5682dSIngo Weinhold# Sets the variables for a GCC platform.
18509c5682dSIngo Weinhold#
18609c5682dSIngo Weinholdstandard_gcc_settings()
18709c5682dSIngo Weinhold{
188*c0e8cc1aSIngo Weinhold	local gcc=$1
189*c0e8cc1aSIngo Weinhold
190138f5fb4SIngo Weinhold	if which greadlink > /dev/null 2>&1; then
191b29b48b1SMatt Madia		readlink="greadlink -e"
192138f5fb4SIngo Weinhold	elif which realpath > /dev/null 2>&1; then
193b29b48b1SMatt Madia		readlink=realpath
1949a001156SOliver Tappe	elif readlink -e / > /dev/null 2>&1; then
195b29b48b1SMatt Madia		readlink="readlink -e"
1969a001156SOliver Tappe	else
1979a001156SOliver Tappe		readlink=real_path
198b4b6d83cSMatt Madia	fi
199138f5fb4SIngo Weinhold
20009c5682dSIngo Weinhold	# PLATFORM_LINKLIBS
201*c0e8cc1aSIngo Weinhold	local gcclib=`$gcc -print-libgcc-file-name`
202*c0e8cc1aSIngo Weinhold	local gccdir=`dirname ${gcclib}`
2035b0f7b1bSOliver Tappe
204*c0e8cc1aSIngo Weinhold	local gccRawVersion=`$gcc -dumpversion`
205*c0e8cc1aSIngo Weinhold	local gccMachine=`$gcc -dumpmachine`
206338b8dc3SIngo Weinhold
207*c0e8cc1aSIngo Weinhold	local libgcc=${gccdir}/libgcc.a
2088b5934c9SIngo Weinhold
209fc8967f1SIngo Weinhold	# determine architecture from machine triple
210*c0e8cc1aSIngo Weinhold	case $gccMachine in
211*c0e8cc1aSIngo Weinhold		arm-*)		targetCpu=arm;;
212*c0e8cc1aSIngo Weinhold		i?86-*)		targetCpu=x86;;
213*c0e8cc1aSIngo Weinhold		m68k-*)		targetCpu=m68k;;
214*c0e8cc1aSIngo Weinhold		mipsel-*)	targetCpu=mipsel;;
215*c0e8cc1aSIngo Weinhold		powerpc-*)	targetCpu=ppc;;
216*c0e8cc1aSIngo Weinhold		x86_64-*)	targetCpu=x86_64;;
217fc8967f1SIngo Weinhold		*)
218*c0e8cc1aSIngo Weinhold			echo "Unsupported gcc target machine: $gccMachine" >&2
219fc8967f1SIngo Weinhold			exit 1
220fc8967f1SIngo Weinhold			;;
221fc8967f1SIngo Weinhold	esac
222fc8967f1SIngo Weinhold
223*c0e8cc1aSIngo Weinhold	local targetArch=$targetCpu
224*c0e8cc1aSIngo Weinhold	local staticLibStdCxx
225*c0e8cc1aSIngo Weinhold	local sharedLibStdCxx
226*c0e8cc1aSIngo Weinhold	local staticLibSupCxx
227*c0e8cc1aSIngo Weinhold	local sharedLibSupCxx
228*c0e8cc1aSIngo Weinhold	local kernelLibgcc
229*c0e8cc1aSIngo Weinhold	local cxxHeaders
230fc8967f1SIngo Weinhold
231*c0e8cc1aSIngo Weinhold	case $gccRawVersion in
2328b5934c9SIngo Weinhold		4.*)
2335b0f7b1bSOliver Tappe			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
2345b0f7b1bSOliver Tappe			# compiler
235*c0e8cc1aSIngo Weinhold			staticLibStdCxx=`$gcc -print-file-name=libstdc++.a`
236*c0e8cc1aSIngo Weinhold			sharedLibStdCxx=`$gcc -print-file-name=libstdc++.so`
237*c0e8cc1aSIngo Weinhold			staticLibSupCxx=`$gcc -print-file-name=libsupc++.a`
238*c0e8cc1aSIngo Weinhold			sharedLibSupCxx=`$gcc -print-file-name=libsupc++.so`
23914210488SMichael Lotz
240aaeadfcbSAlex Smith			# If the architecture has separate runtime libraries for the
241aaeadfcbSAlex Smith			# kernel, use them.
242*c0e8cc1aSIngo Weinhold			kernelLibgcc=`$gcc -print-file-name=libgcc-kernel.a`
243*c0e8cc1aSIngo Weinhold			if [ $kernelLibgcc = libgcc-kernel.a ]; then
244*c0e8cc1aSIngo Weinhold				kernelLibgcc=$libgcc
245aaeadfcbSAlex Smith			fi
246*c0e8cc1aSIngo Weinhold			kernelLibSupCxx=`$gcc -print-file-name=libsupc++-kernel.a`
247*c0e8cc1aSIngo Weinhold			if [ $kernelLibSupCxx = libsupc++-kernel.a ]; then
248*c0e8cc1aSIngo Weinhold				kernelLibSupCxx=$staticLibSupCxx
249aaeadfcbSAlex Smith			fi
250aaeadfcbSAlex Smith
251*c0e8cc1aSIngo Weinhold			local headersBase=$gccdir/../../../..
252*c0e8cc1aSIngo Weinhold			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
253*c0e8cc1aSIngo Weinhold			if [ ! -d $headers ]; then
254*c0e8cc1aSIngo Weinhold				headers=$headersBase/include/c++/$gccRawVersion
25514210488SMichael Lotz			fi
25614210488SMichael Lotz
257*c0e8cc1aSIngo Weinhold			cxxHeaders=$headers
258*c0e8cc1aSIngo Weinhold			for d in $gccMachine backward ext; do
25929ef597dSIngo Weinhold				# Note: We need the line break, otherwise the line might become
26029ef597dSIngo Weinhold				# too long for jam (512 bytes max).
261*c0e8cc1aSIngo Weinhold				cxxHeaders="$cxxHeaders $headers/$d"
2628b5934c9SIngo Weinhold			done
263274b450aSMarcus Overhagen
2643f9f9f9aSIngo Weinhold			# Unset the HAIKU_{SHARED,STATIC}_LIB{STD,SUP}CXX variables, if the
2653f9f9f9aSIngo Weinhold			# compiler didn't give us actual file names. Otherwise resolve
2663f9f9f9aSIngo Weinhold			# symlinks to avoid problems when copying the libraries to the
2673f9f9f9aSIngo Weinhold			# image.
2688b5934c9SIngo Weinhold
269*c0e8cc1aSIngo Weinhold			if [ $staticLibStdCxx = libstdc++.a ]; then
270*c0e8cc1aSIngo Weinhold				staticLibStdCxx=
2713f9f9f9aSIngo Weinhold			else
272*c0e8cc1aSIngo Weinhold				staticLibStdCxx=`$readlink $staticLibStdCxx`
2738b5934c9SIngo Weinhold			fi
2743f9f9f9aSIngo Weinhold
275*c0e8cc1aSIngo Weinhold			if [ $sharedLibStdCxx = libstdc++.so ]; then
276*c0e8cc1aSIngo Weinhold				sharedLibStdCxx=
2773f9f9f9aSIngo Weinhold			else
278*c0e8cc1aSIngo Weinhold				sharedLibStdCxx=`$readlink $sharedLibStdCxx`
279ffe8b20cSIngo Weinhold			fi
2803f9f9f9aSIngo Weinhold
281*c0e8cc1aSIngo Weinhold			if [ $staticLibSupCxx = libsupc++.a ]; then
282*c0e8cc1aSIngo Weinhold				staticLibSupCxx=
2833f9f9f9aSIngo Weinhold			else
284*c0e8cc1aSIngo Weinhold				staticLibSupCxx=`$readlink $staticLibSupCxx`
285c89fc875SIngo Weinhold			fi
2863f9f9f9aSIngo Weinhold
287*c0e8cc1aSIngo Weinhold			if [ $sharedLibSupCxx = libsupc++.so ]; then
288*c0e8cc1aSIngo Weinhold				sharedLibSupCxx=
2893f9f9f9aSIngo Weinhold			else
290*c0e8cc1aSIngo Weinhold				sharedLibSupCxx=`$readlink $sharedLibSupCxx`
291ffe8b20cSIngo Weinhold			fi
2928b5934c9SIngo Weinhold			;;
2936cc8eecfSOliver Tappe		2.9*)
2945b0f7b1bSOliver Tappe			# check for correct (most up-to-date) legacy compiler and complain
2955b0f7b1bSOliver Tappe			# if an older one is installed
296*c0e8cc1aSIngo Weinhold			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
2975b0f7b1bSOliver Tappe				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
2985b0f7b1bSOliver Tappe				echo "Please download it from www.haiku-os.org...";
2995b0f7b1bSOliver Tappe				exit 1;
3005b0f7b1bSOliver Tappe			fi
301aaeadfcbSAlex Smith
302*c0e8cc1aSIngo Weinhold			kernelLibgcc=$libgcc
303*c0e8cc1aSIngo Weinhold			kernelLibSupCxx=
304*c0e8cc1aSIngo Weinhold			targetArch=x86_gcc2
3055b0f7b1bSOliver Tappe			;;
3068b5934c9SIngo Weinhold	esac
30765ad1ba3SAlex Smith
308*c0e8cc1aSIngo Weinhold	local bootLibgcc
309*c0e8cc1aSIngo Weinhold	local bootLibSupCxx
310*c0e8cc1aSIngo Weinhold	case $gccMachine in
3114591ebc9SAlex Smith		x86_64-*)
312c864ba1aSAlex Smith			# Boot loader is 32-bit, need the 32-bit libs.
313*c0e8cc1aSIngo Weinhold			bootLibgcc=`$gcc -m32 -print-libgcc-file-name`
314*c0e8cc1aSIngo Weinhold			bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
3154591ebc9SAlex Smith			;;
3164591ebc9SAlex Smith		*)
317*c0e8cc1aSIngo Weinhold			bootLibgcc=$libgcc
318*c0e8cc1aSIngo Weinhold			bootLibSupCxx=$staticLibSupCxx
319338b8dc3SIngo Weinhold			;;
320338b8dc3SIngo Weinhold	esac
321*c0e8cc1aSIngo Weinhold
322*c0e8cc1aSIngo Weinhold	# determine whether graphite loop optimization should/can be used
323*c0e8cc1aSIngo Weinhold	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
324*c0e8cc1aSIngo Weinhold	if [ -z "$useGraphite" ]; then
325*c0e8cc1aSIngo Weinhold		useGraphite=$useGccGraphiteDefault
326*c0e8cc1aSIngo Weinhold	fi
327*c0e8cc1aSIngo Weinhold
328*c0e8cc1aSIngo Weinhold	if [ "$useGraphite" != 0 ]; then
329*c0e8cc1aSIngo Weinhold		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
330*c0e8cc1aSIngo Weinhold		if [ $? != 0 ]; then
331*c0e8cc1aSIngo Weinhold			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
332*c0e8cc1aSIngo Weinhold			useGraphite=0
333*c0e8cc1aSIngo Weinhold		fi
334*c0e8cc1aSIngo Weinhold	fi
335*c0e8cc1aSIngo Weinhold
336*c0e8cc1aSIngo Weinhold	set_variable HAIKU_CPU_$targetArch $targetCpu
337*c0e8cc1aSIngo Weinhold
338*c0e8cc1aSIngo Weinhold	get_build_tool_path CC_$targetArch "$gcc"
339*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
340*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
341*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
342*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_LIBGCC_$targetArch $libgcc
343*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_GLUE_CODE_$targetArch "crtbegin.o crtend.o"
344*c0e8cc1aSIngo Weinhold	set_variable HAIKU_GCC_HEADERS_DIR_$targetArch \
345*c0e8cc1aSIngo Weinhold		"${gccdir}/include ${gccdir}/include-fixed"
346*c0e8cc1aSIngo Weinhold	set_variable HAIKU_STATIC_LIBSTDCXX_$targetArch "$staticLibStdCxx"
347*c0e8cc1aSIngo Weinhold	set_variable HAIKU_SHARED_LIBSTDCXX_$targetArch "$sharedLibStdCxx"
348*c0e8cc1aSIngo Weinhold	set_variable HAIKU_STATIC_LIBSUPCXX_$targetArch "$staticLibSupCxx"
349*c0e8cc1aSIngo Weinhold	set_variable HAIKU_SHARED_LIBSUPCXX_$targetArch "$sharedLibSupCxx"
350*c0e8cc1aSIngo Weinhold	set_variable HAIKU_KERNEL_LIBSUPCXX_$targetArch "$kernelLibSupCxx"
351*c0e8cc1aSIngo Weinhold	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
352*c0e8cc1aSIngo Weinhold	set_variable HAIKU_KERNEL_LIBGCC_$targetArch $kernelLibgcc
353*c0e8cc1aSIngo Weinhold	set_variable HAIKU_CXX_HEADERS_DIR_$targetArch "$cxxHeaders"
354*c0e8cc1aSIngo Weinhold	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
355*c0e8cc1aSIngo Weinhold	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
356*c0e8cc1aSIngo Weinhold
357*c0e8cc1aSIngo Weinhold	standard_gcc_settings_targetArch=$targetArch
358*c0e8cc1aSIngo Weinhold}
359*c0e8cc1aSIngo Weinhold
360*c0e8cc1aSIngo Weinhold# set_variable
361*c0e8cc1aSIngo Weinhold#
362*c0e8cc1aSIngo Weinhold# Set the value of a variable.
363*c0e8cc1aSIngo Weinhold#
364*c0e8cc1aSIngo Weinholdset_variable()
365*c0e8cc1aSIngo Weinhold{
366*c0e8cc1aSIngo Weinhold	eval "$1=\"$2\""
367*c0e8cc1aSIngo Weinhold}
368*c0e8cc1aSIngo Weinhold
369*c0e8cc1aSIngo Weinhold# get_variable
370*c0e8cc1aSIngo Weinhold#
371*c0e8cc1aSIngo Weinhold# Echo the value of a variable.
372*c0e8cc1aSIngo Weinhold#
373*c0e8cc1aSIngo Weinholdget_variable()
374*c0e8cc1aSIngo Weinhold{
375*c0e8cc1aSIngo Weinhold	eval "echo \${$1}"
37609c5682dSIngo Weinhold}
37709c5682dSIngo Weinhold
378338b8dc3SIngo Weinhold# set_default_value
379338b8dc3SIngo Weinhold#
380338b8dc3SIngo Weinhold# Set the value for a variable, if no value is set yet.
381338b8dc3SIngo Weinhold#
382338b8dc3SIngo Weinholdset_default_value()
383338b8dc3SIngo Weinhold{
384338b8dc3SIngo Weinhold	eval "$1=\${$1-$2}"
385338b8dc3SIngo Weinhold}
386338b8dc3SIngo Weinhold
387338b8dc3SIngo Weinhold# get_build_tool_path
388338b8dc3SIngo Weinhold#
389338b8dc3SIngo Weinhold# Gets a usable absolute path of a build tool.
390338b8dc3SIngo Weinhold#
391338b8dc3SIngo Weinholdget_build_tool_path()
392338b8dc3SIngo Weinhold{
393338b8dc3SIngo Weinhold	local var="HAIKU_$1"
394*c0e8cc1aSIngo Weinhold	local path=$2
395338b8dc3SIngo Weinhold
396338b8dc3SIngo Weinhold	if [ -f "$path" ]; then
397338b8dc3SIngo Weinhold		# get absolute path
398a559f87aSFrançois Revol		local oldPwd="`pwd`"
399a559f87aSFrançois Revol		cd "`dirname "$path"`"
400a559f87aSFrançois Revol		path="`pwd`/`basename "$path"`"
401338b8dc3SIngo Weinhold		cd $oldPwd
402338b8dc3SIngo Weinhold	else
4037fe2e06cSMatt Madia		which "$path" > /dev/null 2>&1 || {
404338b8dc3SIngo Weinhold			echo "Build tool \"$path\" not found." >&2
405338b8dc3SIngo Weinhold			exit 1
406338b8dc3SIngo Weinhold		}
407338b8dc3SIngo Weinhold	fi
408338b8dc3SIngo Weinhold
409338b8dc3SIngo Weinhold	eval "$var=$path"
410338b8dc3SIngo Weinhold}
411338b8dc3SIngo Weinhold
412338b8dc3SIngo Weinhold# get cwd and the source directory
413338b8dc3SIngo WeinholdcurrentDir=`pwd`
4146e7c6fe5SIngo Weinholdcd `dirname "$0"`
415338b8dc3SIngo WeinholdsourceDir=`pwd`
4166e7c6fe5SIngo Weinholdcd "$currentDir"
417338b8dc3SIngo Weinhold
41855d267a4SFrançois Revol# backup the passed arguments
41955d267a4SFrançois RevolconfigureArgs="$@"
42055d267a4SFrançois Revol
4217c4641d0SOliver Tappe# internal default parameter values
422022fa244SIngo Weinhold#
42352a38012Sejakowatzplatform=`uname`
4245abd9a46SIngo WeinholdplatformMachine=`uname  -m`
425*c0e8cc1aSIngo WeinholdtargetArchs=
426338b8dc3SIngo WeinholdbuildCrossTools=
42729ef597dSIngo WeinholdbuildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
42860d8d8fcSIngo WeinholdbuildCrossToolsJobs=
429*c0e8cc1aSIngo WeinholduseGccGraphiteDefault=0
430*c0e8cc1aSIngo WeinholdunknownArchIndex=1
4317c4641d0SOliver Tappe
4327c4641d0SOliver Tappe# exported (BuildSetup) default parameter values
4337c4641d0SOliver Tappe#
4347c4641d0SOliver TappeHOST_GCC_RAW_VERSION=`gcc -dumpversion`
4357c4641d0SOliver TappeHOST_GCC_MACHINE=`gcc -dumpmachine`
4367c4641d0SOliver TappeHAIKU_INCLUDE_GPL_ADDONS=0
4377c4641d0SOliver TappeHAIKU_INCLUDE_PATENTED_CODE=0
43876fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES=0
4397c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY=0
4407c4641d0SOliver TappeHAIKU_ENABLE_MULTIUSER=0
4417c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY=default
4427c4641d0SOliver TappeTARGET_PLATFORM=haiku
4437c4641d0SOliver TappeHAIKU_USE_GCC_PIPE=0
4447986925fSIngo WeinholdHAIKU_HOST_USE_32BIT=0
4457986925fSIngo WeinholdHAIKU_HOST_USE_XATTR=0
446bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF=0
4472ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY=0
4487c4641d0SOliver TappeHOST_GCC_LD=`gcc -print-prog-name=ld`
4497c4641d0SOliver TappeHOST_GCC_OBJCOPY=`gcc -print-prog-name=objcopy`
450c505b276SFrançois RevolSFDISK_BINARY=sfdisk
451c505b276SFrançois RevolHOST_SFDISK=$SFDISK_BINARY
4522a5d0aafSIngo WeinholdHOST_SHA256=
453e173a1ecSIngo WeinholdHOST_HAIKU_PORTER=
454e173a1ecSIngo WeinholdHAIKU_PORTS=
455e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS=
4562a5d0aafSIngo Weinhold
457*c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS=
458*c0e8cc1aSIngo Weinhold
459*c0e8cc1aSIngo Weinholdset_default_value HAIKU_YASM		yasm
460*c0e8cc1aSIngo Weinhold
4613942ca0dSIngo Weinholdif sha256sum < /dev/null > /dev/null 2>&1; then
4622a5d0aafSIngo Weinhold	HOST_SHA256=sha256sum
4633942ca0dSIngo Weinholdelif sha256 < /dev/null > /dev/null 2>&1; then
4642a5d0aafSIngo Weinhold	HOST_SHA256="sha256 -q"
4652a5d0aafSIngo Weinholdelse
4662a5d0aafSIngo Weinhold	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
4672a5d0aafSIngo Weinhold	exit 1
4682a5d0aafSIngo Weinholdfi
469338b8dc3SIngo Weinhold
470983aba29SOliver TappehaikuRequiredLegacyGCCVersion="2.95.3-haiku-2013_07_15"
471a559f87aSFrançois Revolexport haikuRequiredLegacyGCCVersion
472af4bf973SOliver Tappe	# version of legacy gcc required to build haiku
473af4bf973SOliver Tappe
4747c4641d0SOliver Tappe# determine output directory
4757c4641d0SOliver Tappeif [ "$currentDir" = "$sourceDir" ]; then
4767c4641d0SOliver Tappe	outputDir=$currentDir/generated
4777c4641d0SOliver Tappeelse
4787c4641d0SOliver Tappe	outputDir=$currentDir
4797c4641d0SOliver Tappefi
4807c4641d0SOliver TappebuildOutputDir="$outputDir/build"
4817c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
4827c4641d0SOliver TappebuildConfigFile="$buildOutputDir/BuildConfig"
4837c4641d0SOliver Tappe
4847c4641d0SOliver Tappe# check for update request
4857c4641d0SOliver Tappeif [ "$1" = "--update" ]; then
4867c4641d0SOliver Tappe	if ! [ -e "$buildConfigFile" ]; then
4877c4641d0SOliver Tappe		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
4887c4641d0SOliver Tappe		exit 1
4897c4641d0SOliver Tappe	fi
4907c4641d0SOliver Tappe	if ! type perl >/dev/null 2>&1; then
4917c4641d0SOliver Tappe		echo $0 --update: \'perl\' not found - updating not possible.
4927c4641d0SOliver Tappe		exit 1
4937c4641d0SOliver Tappe	fi
4947c4641d0SOliver Tappe	# convert BuildConfig from jam format to shell format and evaluate it
4957c4641d0SOliver Tappe	shellConfigFile="${buildConfigFile}.shell"
4967c4641d0SOliver Tappe	perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \
4977c4641d0SOliver Tappe		<"$buildConfigFile" >"$shellConfigFile"
4987c4641d0SOliver Tappe	. "$shellConfigFile"
4997c4641d0SOliver Tappe	rm "$shellConfigFile"
5007c4641d0SOliver Tappe	shift
5017c4641d0SOliver Tappefi
5027c4641d0SOliver Tappe
503022fa244SIngo Weinhold# parse parameters
504022fa244SIngo Weinhold#
50520ab75e6SIngo Weinholdwhile [ $# -gt 0 ] ; do
506022fa244SIngo Weinhold	case "$1" in
507e173a1ecSIngo Weinhold		--bootstrap)
508e173a1ecSIngo Weinhold			assertparams "$1" 3 $#
509e173a1ecSIngo Weinhold			HOST_HAIKU_PORTER="`absolute_path $2`"
510e173a1ecSIngo Weinhold			HAIKU_PORTS_CROSS="`absolute_path $3`"
511e173a1ecSIngo Weinhold			HAIKU_PORTS="`absolute_path $4`"
512e173a1ecSIngo Weinhold			shift 4
513e173a1ecSIngo Weinhold			;;
514*c0e8cc1aSIngo Weinhold		--build-cross-tools)
515*c0e8cc1aSIngo Weinhold			if [ -z "$buildCrossTools" ]; then
5169b0dd528SIngo Weinhold				assertparams "$1" 2 $#
517*c0e8cc1aSIngo Weinhold				targetArch=$2
5189b0dd528SIngo Weinhold				buildCrossTools=$3
5199b0dd528SIngo Weinhold				shift 3
520*c0e8cc1aSIngo Weinhold			else
521*c0e8cc1aSIngo Weinhold				assertparam "$1" $#
522*c0e8cc1aSIngo Weinhold				targetArch=$2
523*c0e8cc1aSIngo Weinhold				shift 2
524*c0e8cc1aSIngo Weinhold			fi
525*c0e8cc1aSIngo Weinhold			case "$targetArch" in
526*c0e8cc1aSIngo Weinhold				x86_gcc2)	targetMachine=i586-pc-haiku;;
527*c0e8cc1aSIngo Weinhold				x86)		targetMachine=i586-pc-haiku;;
528*c0e8cc1aSIngo Weinhold				x86_64)		targetMachine=x86_64-unknown-haiku;;
529*c0e8cc1aSIngo Weinhold				ppc)		targetMachine=powerpc-apple-haiku;;
530*c0e8cc1aSIngo Weinhold				m68k)		targetMachine=m68k-unknown-haiku;;
531*c0e8cc1aSIngo Weinhold				arm)		targetMachine=arm-unknown-haiku;;
532*c0e8cc1aSIngo Weinhold				mipsel)		targetMachine=mipsel-unknown-haiku;;
533*c0e8cc1aSIngo Weinhold				*)
534*c0e8cc1aSIngo Weinhold					echo "Unsupported target architecture: $2" >&2
535*c0e8cc1aSIngo Weinhold					exit 1
536*c0e8cc1aSIngo Weinhold					;;
537*c0e8cc1aSIngo Weinhold			esac
538*c0e8cc1aSIngo Weinhold			set_variable buildCrossToolsMachine_$targetArch $targetMachine
539*c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
540*c0e8cc1aSIngo Weinhold			HAIKU_PACKAGING_ARCHS=
5419b0dd528SIngo Weinhold			;;
5429b0dd528SIngo Weinhold		--cross-tools-prefix)
5439b0dd528SIngo Weinhold			assertparam "$1" $#
544*c0e8cc1aSIngo Weinhold			targetArch=unknown${unknownArchIndex}
545*c0e8cc1aSIngo Weinhold			set_variable crossToolsPrefix_$targetArch "$2"
546*c0e8cc1aSIngo Weinhold			targetArchs="$targetArchs $targetArch"
547*c0e8cc1aSIngo Weinhold			HAIKU_PACKAGING_ARCHS=
548*c0e8cc1aSIngo Weinhold			unknownArchIndex=$[$unknownArchIndex + 1]
5499b0dd528SIngo Weinhold			shift 2
5509b0dd528SIngo Weinhold			;;
551a66c32ddSIngo Weinhold		--distro-compatibility)
5529b0dd528SIngo Weinhold			assertparam "$1" $#
5537c4641d0SOliver Tappe			HAIKU_DISTRO_COMPATIBILITY=$2
5547c4641d0SOliver Tappe			case "$HAIKU_DISTRO_COMPATIBILITY" in
555a66c32ddSIngo Weinhold				official)	;;
556a66c32ddSIngo Weinhold				compatible)	;;
557a66c32ddSIngo Weinhold				default)	;;
558a66c32ddSIngo Weinhold				*)			echo "Invalid distro compatibility" \
5597c4641d0SOliver Tappe								"level: $HAIKU_DISTRO_COMPATIBILITY"
560a66c32ddSIngo Weinhold							exit 1;;
561a66c32ddSIngo Weinhold			esac
5629b0dd528SIngo Weinhold			shift 2
5639b0dd528SIngo Weinhold			;;
5647c4641d0SOliver Tappe		--enable-multiuser)	HAIKU_ENABLE_MULTIUSER=1; shift 1;;
56560d8d8fcSIngo Weinhold		--help | -h)	usage; exit 0;;
5662ebcd86dSIngo Weinhold		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
5677c4641d0SOliver Tappe		--include-gpl-addons)	HAIKU_INCLUDE_GPL_ADDONS=1; shift 1;;
5687c4641d0SOliver Tappe		--include-patented-code)	HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
56976fa0be3SIngo Weinhold		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
5707c4641d0SOliver Tappe		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
57160d8d8fcSIngo Weinhold        -j*)				buildCrossToolsJobs="$1"; shift 1;;
5727c4641d0SOliver Tappe		--target=*)     TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
5737c4641d0SOliver Tappe		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
574*c0e8cc1aSIngo Weinhold		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
5757986925fSIngo Weinhold		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
5767986925fSIngo Weinhold		--use-xattr)	HAIKU_HOST_USE_XATTR=1; shift 1;;
577bc96e8f3SIngo Weinhold		--use-xattr-ref)	HAIKU_HOST_USE_XATTR_REF=1; shift 1;;
578022fa244SIngo Weinhold		*)				echo Invalid argument: \`$1\'; exit 1;;
579022fa244SIngo Weinhold	esac
580022fa244SIngo Weinholddone
581022fa244SIngo Weinhold
5820df3cc9cSIngo Weinhold# detect the build platform
583338b8dc3SIngo Weinholdcase "${platform}" in
5847c4641d0SOliver Tappe	Darwin)	HOST_PLATFORM=darwin ;;
5857c4641d0SOliver Tappe	FreeBSD)	HOST_PLATFORM=freebsd
586c505b276SFrançois Revol				SFDISK_BINARY=sfdisk-linux
5877986925fSIngo Weinhold				if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
5885abd9a46SIngo Weinhold					echo Unsupported platform: FreeBSD ${platformMachine}
589308c212cSIngo Weinhold					exit 1
590308c212cSIngo Weinhold				fi	;;
5917c4641d0SOliver Tappe	Haiku)	HOST_PLATFORM=haiku_host ;;
5927c4641d0SOliver Tappe	Linux)	HOST_PLATFORM=linux ;;
5937c4641d0SOliver Tappe	OpenBSD) HOST_PLATFORM=openbsd ;;
5947c4641d0SOliver Tappe	SunOS)	HOST_PLATFORM=sunos ;;
5957c4641d0SOliver Tappe	CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
596338b8dc3SIngo Weinhold	*)		echo Unsupported platform: ${platform}
5974cbe4925SAxel Dörfler			exit 1 ;;
5984cbe4925SAxel Dörfleresac
59952a38012Sejakowatz
600c505b276SFrançois Revol# check common locations for sfdisk
601c505b276SFrançois Revolfor sfdiskDir in /sbin /usr/sbin /usr/local/sbin ; do
602c505b276SFrançois Revol	if [ -e ${sfdiskDir}/${SFDISK_BINARY} ]; then
603c505b276SFrançois Revol		HOST_SFDISK=${sfdiskDir}/${SFDISK_BINARY}
604c505b276SFrançois Revol	fi
605c505b276SFrançois Revoldone
606c505b276SFrançois Revol
6070962132cSAlex Smith# check for case-sensitive filesystem
6080962132cSAlex Smithmkdir haikuCaseTest 2>/dev/null
6090962132cSAlex Smithmkdir haikucasetest 2>/dev/null
6100962132cSAlex SmithcaseInsensitive=$?
61197f5a0bdSAlex Smithrmdir haikuCaseTest haikucasetest 2>/dev/null
6120962132cSAlex Smithif [ $caseInsensitive != 0 ]; then
6133ecc5287SMichael Lotz	echo "You need a case-sensitive file-system to build Haiku."
6140962132cSAlex Smith	if [ $HOST_PLATFORM = "darwin" ]; then
6150962132cSAlex Smith		echo "You can create a case-sensitive disk image using Disk Utility and use"
6160962132cSAlex Smith		echo "it to store the Haiku sources on."
6173ecc5287SMichael Lotz	fi
6180962132cSAlex Smith	exit 1
6193ecc5287SMichael Lotzfi
6203ecc5287SMichael Lotz
621338b8dc3SIngo Weinhold# create output directory
6226e7c6fe5SIngo Weinholdmkdir -p "$buildOutputDir" || exit 1
623338b8dc3SIngo Weinhold
6242ebcd86dSIngo Weinholdif [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
6252ebcd86dSIngo Weinhold	invalidCommand=$sourceDir/build/scripts/host_build_only
6262ebcd86dSIngo Weinhold	HAIKU_AR=$invalidCommand
6272ebcd86dSIngo Weinhold	HAIKU_CC=$invalidCommand
6282ebcd86dSIngo Weinhold	HAIKU_LD=$invalidCommand
6292ebcd86dSIngo Weinhold	HAIKU_OBJCOPY=$invalidCommand
6302ebcd86dSIngo Weinhold	HAIKU_RANLIB=$invalidCommand
6312ebcd86dSIngo Weinhold	HAIKU_ELFEDIT=$invalidCommand
6322ebcd86dSIngo Weinhold	HAIKU_YASM=$invalidCommand
6332ebcd86dSIngo Weinhold	HAIKU_STRIP=$invalidCommand
6342ebcd86dSIngo Weinholdelse
635*c0e8cc1aSIngo Weinhold	if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
636*c0e8cc1aSIngo Weinhold		targetArchs="$HAIKU_PACKAGING_ARCHS"
637*c0e8cc1aSIngo Weinhold	fi
638*c0e8cc1aSIngo Weinhold	HAIKU_PACKAGING_ARCHS=
639*c0e8cc1aSIngo Weinhold
640*c0e8cc1aSIngo Weinhold	if [ -z "$targetArchs" ]; then
641*c0e8cc1aSIngo Weinhold		targetArch=x86_gcc2
642*c0e8cc1aSIngo Weinhold		targetArchs=$targetArch
643*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_AR_$targetArch			ar
644*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CC_$targetArch			gcc
645*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LD_$targetArch			ld
646*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
647*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_RANLIB_$targetArch		ranlib
648*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
649*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_STRIP_$targetArch		strip
650*c0e8cc1aSIngo Weinhold	fi
651*c0e8cc1aSIngo Weinhold
652*c0e8cc1aSIngo Weinhold	for targetArch in $targetArchs; do
653*c0e8cc1aSIngo Weinhold		# Note: targetArch is "unknown<n>" at this point, if a cross-tools
654*c0e8cc1aSIngo Weinhold		# prefix was specified. The standard_gcc_settings call below will get
655*c0e8cc1aSIngo Weinhold		# the actual architecture.
656*c0e8cc1aSIngo Weinhold
657*c0e8cc1aSIngo Weinhold		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
658*c0e8cc1aSIngo Weinhold
659338b8dc3SIngo Weinhold		# build cross tools from sources
660*c0e8cc1aSIngo Weinhold		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
661*c0e8cc1aSIngo Weinhold			crossToolsDir="$outputDir/cross-tools-$targetArch"
662*c0e8cc1aSIngo Weinhold			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
663*c0e8cc1aSIngo Weinhold			script="$buildCrossToolsScript"
664*c0e8cc1aSIngo Weinhold			if [ $targetArch != x86_gcc2 ]; then
665*c0e8cc1aSIngo Weinhold				script="${script}_gcc4 $targetMachine"
666*c0e8cc1aSIngo Weinhold			fi
667*c0e8cc1aSIngo Weinhold			HAIKU_USE_GCC_GRAPHITE=`get_variable \
668*c0e8cc1aSIngo Weinhold				HAIKU_USE_GCC_GRAPHITE_$targetArch` \
669*c0e8cc1aSIngo Weinhold			$script "$sourceDir" "$buildCrossTools" "$crossToolsDir" \
670*c0e8cc1aSIngo Weinhold				$buildCrossToolsJobs || exit 1
671*c0e8cc1aSIngo Weinhold			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
672338b8dc3SIngo Weinhold		fi
673338b8dc3SIngo Weinhold
674*c0e8cc1aSIngo Weinhold		# prepare gcc settings and get the actual target architecture
675*c0e8cc1aSIngo Weinhold		gcc="${crossToolsPrefix}gcc"
676*c0e8cc1aSIngo Weinhold		if [ -z "${crossToolsPrefix}" ]; then
677*c0e8cc1aSIngo Weinhold			gcc=`get_variable HAIKU_CC_$targetArch`
678338b8dc3SIngo Weinhold		fi
679*c0e8cc1aSIngo Weinhold		standard_gcc_settings "$gcc"
680*c0e8cc1aSIngo Weinhold		targetArch=$standard_gcc_settings_targetArch
681338b8dc3SIngo Weinhold
682*c0e8cc1aSIngo Weinhold		# set default values for flags
683*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CPPFLAGS_$targetArch	""
684*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CCFLAGS_$targetArch		""
685*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_CXXFLAGS_$targetArch	""
686*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_LDFLAGS_$targetArch		""
687*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_ARFLAGS_$targetArch		cru
688*c0e8cc1aSIngo Weinhold		set_default_value HAIKU_UNARFLAGS_$targetArch	x
689338b8dc3SIngo Weinhold
690*c0e8cc1aSIngo Weinhold		# Override the cross tools variables, if the tools were built or a
691*c0e8cc1aSIngo Weinhold		# prefix was specified.
692b7777272SAlex Smith		if [ -n "$crossToolsPrefix" ]; then
693*c0e8cc1aSIngo Weinhold			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
694*c0e8cc1aSIngo Weinhold			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
695*c0e8cc1aSIngo Weinhold			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
696*c0e8cc1aSIngo Weinhold			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
697*c0e8cc1aSIngo Weinhold			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
698*c0e8cc1aSIngo Weinhold
699*c0e8cc1aSIngo Weinhold			case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
700bd16f0ddSAlex Smith				4.*)
701*c0e8cc1aSIngo Weinhold					get_build_tool_path ELFEDIT_$targetArch \
702*c0e8cc1aSIngo Weinhold						${crossToolsPrefix}elfedit
703bd16f0ddSAlex Smith				;;
704bd16f0ddSAlex Smith			esac
70552a38012Sejakowatz		fi
70652a38012Sejakowatz
707*c0e8cc1aSIngo Weinhold		# Get the libgcc objects. We couldn't do that in standard_gcc_settings,
708*c0e8cc1aSIngo Weinhold		# since we need "ar", which may be set later.
709*c0e8cc1aSIngo Weinhold		ar=`get_variable HAIKU_AR_$targetArch`
710*c0e8cc1aSIngo Weinhold		libgcc=`get_variable HAIKU_GCC_LIBGCC_$targetArch`
711*c0e8cc1aSIngo Weinhold		set_variable HAIKU_GCC_LIBGCC_OBJECTS_$targetArch \
712*c0e8cc1aSIngo Weinhold			"`$ar t $libgcc | grep -v eabi.o`"
713*c0e8cc1aSIngo Weinhold			# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC
714*c0e8cc1aSIngo Weinhold			# and neither needed nor wanted.
715*c0e8cc1aSIngo Weinhold
716ef57df3dSIngo Weinhold		# check whether the Haiku compiler really targets Haiku
717*c0e8cc1aSIngo Weinhold		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
718*c0e8cc1aSIngo Weinhold		case "$targetMachine" in
719eedc3d0bSIngo Weinhold			*-*-haiku)	;;
720*c0e8cc1aSIngo Weinhold			*)
721*c0e8cc1aSIngo Weinhold				echo The compiler specified as Haiku target compiler is not a \
722*c0e8cc1aSIngo Weinhold				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
723eedc3d0bSIngo Weinhold				echo compiler: $HAIKU_CC
724*c0e8cc1aSIngo Weinhold				echo compiler is configured for target: $targetMachine
725eedc3d0bSIngo Weinhold				exit 1 ;;
726eedc3d0bSIngo Weinhold		esac
727*c0e8cc1aSIngo Weinhold
728*c0e8cc1aSIngo Weinhold		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
729*c0e8cc1aSIngo Weinhold	done
7302ebcd86dSIngo Weinholdfi
731eedc3d0bSIngo Weinhold
73252a38012Sejakowatz# Generate BuildConfig
7337c4641d0SOliver Tappecat << EOF > "$buildConfigFile"
73452a38012Sejakowatz# BuildConfig
735ab2540c4SIngo Weinhold# Note: This file has been automatically generated by configure with the
736ab2540c4SIngo Weinhold# following arguments:
73755d267a4SFrançois Revol# ${configureArgs}
73852a38012Sejakowatz
7397c4641d0SOliver TappeTARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
7407c4641d0SOliver TappeHOST_PLATFORM				?= "${HOST_PLATFORM}" ;
741338b8dc3SIngo Weinhold
7427c4641d0SOliver TappeHAIKU_INCLUDE_GPL_ADDONS			?= "${HAIKU_INCLUDE_GPL_ADDONS}" ;
7437c4641d0SOliver TappeHAIKU_INCLUDE_PATENTED_CODE			?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
74476fa0be3SIngo WeinholdHAIKU_INCLUDE_SOURCES				?= "${HAIKU_INCLUDE_SOURCES}" ;
7457c4641d0SOliver TappeHAIKU_INCLUDE_3RDPARTY				?= "${HAIKU_INCLUDE_3RDPARTY}" ;
7467c4641d0SOliver TappeHAIKU_ENABLE_MULTIUSER				?= "${HAIKU_ENABLE_MULTIUSER}" ;
7477c4641d0SOliver TappeHAIKU_DISTRO_COMPATIBILITY			?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
7487c4641d0SOliver TappeHAIKU_USE_GCC_PIPE					?= "${HAIKU_USE_GCC_PIPE}" ;
7497986925fSIngo WeinholdHAIKU_HOST_USE_32BIT				?= "${HAIKU_HOST_USE_32BIT}" ;
7507986925fSIngo WeinholdHAIKU_HOST_USE_XATTR				?= "${HAIKU_HOST_USE_XATTR}" ;
751bc96e8f3SIngo WeinholdHAIKU_HOST_USE_XATTR_REF			?= "${HAIKU_HOST_USE_XATTR_REF}" ;
7522ebcd86dSIngo WeinholdHAIKU_HOST_BUILD_ONLY				?= "${HAIKU_HOST_BUILD_ONLY}" ;
753eccc7665SIngo Weinhold
754*c0e8cc1aSIngo WeinholdHAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
75565ad1ba3SAlex Smith
7567c4641d0SOliver TappeHAIKU_BUILD_ATTRIBUTES_DIR	?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
757338b8dc3SIngo Weinhold
75877e84f21SIngo WeinholdHAIKU_YASM					?= ${HAIKU_YASM} ;
759338b8dc3SIngo Weinhold
7607c4641d0SOliver TappeHOST_GCC_RAW_VERSION		?= ${HOST_GCC_RAW_VERSION} ;
7617c4641d0SOliver TappeHOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
7627c4641d0SOliver TappeHOST_LD						?= ${HOST_GCC_LD} ;
7637c4641d0SOliver TappeHOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
764c505b276SFrançois RevolHOST_SFDISK					?= ${HOST_SFDISK} ;
7652a5d0aafSIngo WeinholdHOST_SHA256					?= ${HOST_SHA256} ;
7668b5934c9SIngo Weinhold
767e173a1ecSIngo WeinholdHOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
768e173a1ecSIngo WeinholdHAIKU_PORTS					?= ${HAIKU_PORTS} ;
769e173a1ecSIngo WeinholdHAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
770e173a1ecSIngo Weinhold
771c4786ea6SlilloEOF
772c4786ea6Slillo
773*c0e8cc1aSIngo Weinholdfor targetArch in $HAIKU_PACKAGING_ARCHS; do
774*c0e8cc1aSIngo Weinhold	variables="
775*c0e8cc1aSIngo Weinhold		HAIKU_GCC_RAW_VERSION		HAIKU_GCC_RAW_VERSION
776*c0e8cc1aSIngo Weinhold		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
777*c0e8cc1aSIngo Weinhold		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
778*c0e8cc1aSIngo Weinhold		HAIKU_GCC_LIBGCC			HAIKU_GCC_LIBGCC
779*c0e8cc1aSIngo Weinhold		HAIKU_CPU					HAIKU_CPU
780*c0e8cc1aSIngo Weinhold		HAIKU_STATIC_LIBSTDC++		HAIKU_STATIC_LIBSTDCXX
781*c0e8cc1aSIngo Weinhold		HAIKU_SHARED_LIBSTDC++		HAIKU_SHARED_LIBSTDCXX
782*c0e8cc1aSIngo Weinhold		HAIKU_STATIC_LIBSUPC++		HAIKU_STATIC_LIBSUPCXX
783*c0e8cc1aSIngo Weinhold		HAIKU_SHARED_LIBSUPC++		HAIKU_SHARED_LIBSUPCXX
784*c0e8cc1aSIngo Weinhold		HAIKU_KERNEL_LIBGCC			HAIKU_KERNEL_LIBGCC
785*c0e8cc1aSIngo Weinhold		HAIKU_KERNEL_LIBSUPC++		HAIKU_KERNEL_LIBSUPCXX
786*c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
787*c0e8cc1aSIngo Weinhold		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
788*c0e8cc1aSIngo Weinhold		HAIKU_AR					HAIKU_AR
789*c0e8cc1aSIngo Weinhold		HAIKU_CC					HAIKU_CC
790*c0e8cc1aSIngo Weinhold		HAIKU_LD					HAIKU_LD
791*c0e8cc1aSIngo Weinhold		HAIKU_OBJCOPY				HAIKU_OBJCOPY
792*c0e8cc1aSIngo Weinhold		HAIKU_RANLIB				HAIKU_RANLIB
793*c0e8cc1aSIngo Weinhold		HAIKU_ELFEDIT				HAIKU_ELFEDIT
794*c0e8cc1aSIngo Weinhold		HAIKU_STRIP					HAIKU_STRIP
795*c0e8cc1aSIngo Weinhold		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
796*c0e8cc1aSIngo Weinhold		HAIKU_CCFLAGS				HAIKU_CCFLAGS
797*c0e8cc1aSIngo Weinhold		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
798*c0e8cc1aSIngo Weinhold		HAIKU_LDFLAGS				HAIKU_LDFLAGS
799*c0e8cc1aSIngo Weinhold		HAIKU_ARFLAGS				HAIKU_ARFLAGS
800*c0e8cc1aSIngo Weinhold		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
801*c0e8cc1aSIngo Weinhold		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
802*c0e8cc1aSIngo Weinhold		"
803*c0e8cc1aSIngo Weinhold	set -- $variables
804*c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
805*c0e8cc1aSIngo Weinhold		value=`get_variable ${2}_$targetArch`
806*c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
807*c0e8cc1aSIngo Weinhold		shift 2
808*c0e8cc1aSIngo Weinhold	done
809b1e5b60cSAxel Dörfler
810*c0e8cc1aSIngo Weinhold	# For variables that may have long values, distribute them over multiple
811*c0e8cc1aSIngo Weinhold	# lines so that jam doesn't hit the maximum line length.
812*c0e8cc1aSIngo Weinhold	variables="
813*c0e8cc1aSIngo Weinhold		HAIKU_GCC_HEADERS_DIR		HAIKU_GCC_HEADERS_DIR
814*c0e8cc1aSIngo Weinhold		HAIKU_C++_HEADERS_DIR		HAIKU_CXX_HEADERS_DIR
815*c0e8cc1aSIngo Weinhold		HAIKU_GCC_LIBGCC_OBJECTS	HAIKU_GCC_LIBGCC_OBJECTS
816*c0e8cc1aSIngo Weinhold		"
817*c0e8cc1aSIngo Weinhold	set -- $variables
818*c0e8cc1aSIngo Weinhold	while [ $# -ge 2 ]; do
819*c0e8cc1aSIngo Weinhold		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
820*c0e8cc1aSIngo Weinhold		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
821*c0e8cc1aSIngo Weinhold			>> "$buildConfigFile"
822*c0e8cc1aSIngo Weinhold		echo "    ;" >> "$buildConfigFile"
823*c0e8cc1aSIngo Weinhold		shift 2
824*c0e8cc1aSIngo Weinhold	done
825*c0e8cc1aSIngo Weinholddone
826b1e5b60cSAxel Dörfler
827b1e5b60cSAxel Dörfler
8289b0dd528SIngo Weinhold# Generate a boot strap Jamfile in the output directory.
829338b8dc3SIngo Weinhold
830338b8dc3SIngo Weinholdcat << EOF > $outputDir/Jamfile
831338b8dc3SIngo Weinhold# automatically generated Jamfile
832338b8dc3SIngo Weinhold
833338b8dc3SIngo WeinholdHAIKU_TOP			= ${sourceDir} ;
834338b8dc3SIngo WeinholdHAIKU_OUTPUT_DIR	= ${outputDir} ;
835338b8dc3SIngo Weinhold
836338b8dc3SIngo Weinholdinclude [ FDirName \$(HAIKU_TOP) Jamfile ] ;
837338b8dc3SIngo Weinhold
838338b8dc3SIngo WeinholdEOF
839