xref: /haiku/configure (revision 8ece85d22005339e63ae5b7c0153cfdb0dfc1243)
1#!/bin/sh
2#
3# configure [ <options> ]
4
5# usage
6#
7# Prints usage.
8#
9usage()
10{
11	cat << EOF
12
13Usage: $0 <options>
14options:
15  --help                      Prints out this help.
16  --update                    Re-runs last configure invocation [must be given
17                              as first option!]
18  --bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo>
19                              Prepare for a bootstrap build. No pre-built
20                              packages will be used, instead they will be built
21                              from the sources (in several phases).
22                              <haikuporter> is the path to the haikuporter tool
23                              suitable for the host platform.
24                              <HaikuPorts cross repo> is the path to a checked
25                              out HaikuPorts cross-compilation repository.
26                              <HaikuPorts repo> is the path to a checked out
27                              HaikuPorts repository.
28  --build-cross-tools <arch>
29                              Assume cross compilation.
30                              Toolchain will be compiled and placed in the
31                              output directory under "cross-tools". The
32                              HAIKU_* tools variables will be set accordingly.
33                              <arch> specifies the target architecture, either
34                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k",
35                              "arm", "arm64", "riscv64", "sparc"
36                              This option and --cross-tools-prefix can be
37                              specified multiple times. The first cross tools
38                              specify the primary tools, the subsequent ones the
39                              secondary tools (for "hybrid" images).
40  --cross-tools-prefix <prefix>
41                              Assume cross compilation. <prefix> should be a
42                              path to the directory where the cross
43                              compilation tools are located, plus the platform
44                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
45                              This overrides the HAIKU_* tool variables.
46  --cross-tools-source <buildtools dir>
47                              Toolchain sources for cross compilation.
48                              <buildtools dir> defines the location of the
49                              buildtools sources.
50  --distro-compatibility <level>
51                              The distribution's level of compatibility with
52                              the official Haiku distribution. The generated
53                              files will contain the respective trademarks
54                              accordingly.
55                              official -- the official Haiku distribution.
56                              compatible -- a Haiku Compatible (tm) distro.
57                              default -- any other distro (default value).
58  --host-only                 Configure for building tools for the build host
59                              only. Haiku cannot be built when configured like
60                              this.
61  --include-sources           Includes the source code of projects that require
62                              either an offer of source code or a copy of the
63                              patched sources. This is preferable when
64                              distributing on physical mediums.
65  --include-3rdparty          Include 3rdparty/ in the build system.
66  -j<n>                       Only relevant for --build-cross-tools. Is passed
67                              on to the make building the build tools.
68  --no-downloads              Do not download anything. Useful when trying to
69                              bootstrap and build Haiku from source only.
70  --sysroot                   The location of the cross-compiler sysroot,
71                              primarily for CI environments or cross-compilers
72                              used outside of the Haiku build system.
73  --target-arch <arch>        Haiku only: Specify the target architecture to
74                              build for. Must be one of the architectures of the
75                              host system. The installed build tools for that
76                              architecture will be used.
77                              This option can be specified multiple times. The
78                              first occurrence specifies the primary
79                              architecture of the Haiku to build, subsequent
80                              ones the secondary architectures.
81  --use-clang <arch>          Build with host Clang instead of GCC cross
82                              compiler, targeting <arch>
83  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
84                              process, but uses more memory.
85  --use-gcc-graphite          Build with GCC Graphite engine for loop
86                              optimizations. (Only for GCC 4+.)
87  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
88  --no-full-xattr             Do not use Linux/*BSD/Darwin's native extended file
89                              attributes as Haiku attributes. If they are still
90                              available, they will be used to store hashes for
91                              the attribute emulation layer.
92  --no-xattr                  Do not use Linux/*BSD/Darwin's native extended file
93                              attributes for Haiku extended attributes at all,
94                              even if they are available.
95  --with-gdb <gdb sources dir>
96                              specify the path to a GDB source dir, to build
97                              GDB for each arch we build the cross-tools for.
98  --use-stack-protector       Build with stack protection enabled
99  --efi-signing-key           Private keyfile to sign any EFI bootloaders
100
101environment variables:
102  CC                          The host compiler. Defaults to "gcc".
103  HAIKU_AR_<arch>             The static library archiver for <arch>.
104                              Defaults to "ar".
105  HAIKU_CC_<arch>             The compiler for <arch>. Defaults to "gcc".
106  HAIKU_LD_<arch>             The <arch> linker. Defaults to "ld".
107  HAIKU_OBJCOPY_<arch>        The <arch> objcopy to be used. Defaults to
108                              "objcopy".
109  HAIKU_RANLIB_<arch>         The static library indexer for <arch>. Defaults
110                              to "ranlib".
111  HAIKU_STRIP_<arch>          The <arch> strip command. Defaults to "strip".
112  HAIKU_NASM                  The nasm assembler (x86 and x86_64 only).
113  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
114                              <arch>. Defaults to "".
115  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
116                              Defaults to "".
117  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
118                              Defaults to "".
119  HAIKU_LINKFLAGS_<arch>      The flags passed to the compiler when linking for
120                              target architecture <arch>. Defaults to "".
121  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
122                              Defaults to "".
123  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
124                              architecture <arch> for archiving. Defaults to
125                              "cru".
126  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
127                              architecture <arch> for unarchiving. Defaults to
128                              "x".
129
130Non-default output directories:
131  By default all objects, build configuration, and other related files are
132  stored in /path/to/haiku_source/generated.  To store objects in a non-default
133  location, run "../../relative/path/to/haiku_source/configure <options>" from
134  within your non-default location.  "jam [ options ] targets" can then be run
135  directly inside your non-default location.  Another option is to invoke "jam
136  [ options ] targets" from within haiku_source.  This can be accomplished by
137  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
138  jam or by creating a symlink of haiku_source/generated pointing to your
139  non-default location and running jam.
140
141
142EOF
143}
144
145# assertparam
146#
147# Checks whether at least one parameter is left.
148#
149assertparam()
150{
151	if [ $2 -lt 2 ]; then
152		echo $0: \`$1\': Parameter expected.
153		exit 1
154	fi
155}
156
157# assertparams
158#
159# Checks whether at least a certain number of parameters is left.
160#
161assertparams()
162{
163	if [ $3 -le $2 ]; then
164		echo $0: \`$1\': Not enough parameters.
165		exit 1
166	fi
167}
168
169# absolute_path
170#
171# returns the absolute path of a given path.
172#
173absolute_path()
174{
175	if [ "x$1" != "x${1#/}" ]; then
176		echo "$1"
177	else
178		echo "`pwd`/$1"
179	fi
180}
181
182# check_dir_exists
183#
184# check if a directory exists or not
185#
186check_dir_exists()
187{
188	if [ -d "$1" ]; then
189		return 0
190	else
191		return 1
192	fi
193}
194
195# check_file_exists
196#
197# check if a file exists or not
198#
199check_file_exists()
200{
201	if [ -f "$1" ]; then
202		return 0
203	else
204		return 1
205	fi
206}
207
208# real_path
209#
210# returns the realpath of a symbolic link.
211#
212real_path()
213{
214	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
215}
216
217# relative_to
218#
219# returns $1 relative to $2
220#
221relative_to()
222{
223	perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' \
224		"$1" "$2"
225}
226
227# valid_toolchain
228#
229# check if a toolchain is valid
230#
231valid_toolchain()
232{
233	TRIPLET="$1"
234	BASE="$2"
235	SOURCE="$3"
236	if [ ! -d "$BASE" ]; then
237		return 1
238	fi
239	if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
240		[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
241			[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
242		return $?
243	fi
244	return 1
245}
246
247# is_legacy_gcc
248#
249# Determines if the specified GCC version is a "legacy" (i.e. GCC < 4) one.
250#
251is_legacy_gcc()
252{
253	if [ `echo $1 | cut -d'.' -f1` -lt 4 ]; then
254		echo 1
255	else
256		echo 0
257	fi
258}
259
260# standard_gcc_settings
261#
262# Sets the variables for a GCC platform.
263#
264standard_gcc_settings()
265{
266	local gcc="$1"
267
268	if which greadlink > /dev/null 2>&1; then
269		readlink="greadlink -e"
270	elif which realpath > /dev/null 2>&1; then
271		readlink=realpath
272	elif readlink -e / > /dev/null 2>&1; then
273		readlink="readlink -e"
274	else
275		readlink=real_path
276	fi
277
278	# PLATFORM_LINKLIBS
279	local gcclib=`$gcc -print-libgcc-file-name`
280	local gccdir=`dirname ${gcclib}`
281
282	local gccRawVersion=`$gcc -dumpversion`
283	local gccMachine=`$gcc -dumpmachine`
284
285	# determine architecture from machine triple
286	case $gccMachine in
287		arm-*)		targetCpu=arm;;
288		aarch64-*)	targetCpu=arm64;;
289		i?86-*)		targetCpu=x86;;
290		m68k-*)		targetCpu=m68k;;
291		powerpc-*)	targetCpu=ppc;;
292		riscv64-*)	targetCpu=riscv64;;
293		sparc64-*)	targetCpu=sparc;;
294		x86_64-*)	targetCpu=x86_64;;
295		*)
296			echo "Unsupported gcc target machine: $gccMachine" >&2
297			exit 1
298			;;
299	esac
300
301	local targetArch=$targetCpu
302
303	case $gccRawVersion in
304		2.9*)
305			# check for correct (most up-to-date) legacy compiler and complain
306			# if an older one is installed
307			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
308				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
309				echo "Please download it from www.haiku-os.org...";
310				exit 1;
311			fi
312
313			targetArch=x86_gcc2
314			;;
315	esac
316
317	local bootLibgcc
318	local bootLibSupCxx
319	local bootCxxHeaders
320	local boot32Libgcc
321	local boot32LibSupCxx
322	local boot32CxxHeaders
323	case $gccMachine in
324		x86_64-*)
325			# Boot loader is 32-bit, need the 32-bit libs and c++ config
326			boot32Libgcc=`$gcc -m32 -print-file-name=libgcc.a`
327			boot32LibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
328			bootLibgcc=`$gcc -print-file-name=libgcc.a`
329			bootLibSupCxx=`$gcc -print-file-name=libsupc++.a`
330
331			local headersBase=$gccdir/../../../..
332			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
333			if [ ! -d $headers ]; then
334				headers=$headersBase/include/c++/$gccRawVersion
335			fi
336			boot32CxxHeaders="$headers/$gccMachine/32"
337			bootCxxHeaders="$headers/$gccMachine"
338			;;
339	esac
340
341	# determine whether graphite loop optimization should/can be used
342	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
343	if [ -z "$useGraphite" ]; then
344		useGraphite=$useGccGraphiteDefault
345	fi
346
347	if [ "$useGraphite" != 0 ]; then
348		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
349		if [ $? != 0 ]; then
350			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
351			useGraphite=0
352		fi
353	fi
354
355	set_variable HAIKU_CPU_$targetArch $targetCpu
356
357	get_build_tool_path CC_$targetArch "$gcc"
358	set_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch \
359		`is_legacy_gcc $gccRawVersion`
360	set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
361	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
362	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
363	set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
364	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
365	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
366	set_variable HAIKU_BOOT_32_CXX_HEADERS_DIR_$targetArch "$boot32CxxHeaders"
367	set_variable HAIKU_BOOT_32_LIBSUPCXX_$targetArch "$boot32LibSupCxx"
368	set_variable HAIKU_BOOT_32_LIBGCC_$targetArch $boot32Libgcc
369	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
370
371	standard_gcc_settings_targetArch=$targetArch
372}
373
374# set_variable
375#
376# Set the value of a variable.
377#
378set_variable()
379{
380	eval "$1=\"$2\""
381}
382
383# get_variable
384#
385# Echo the value of a variable.
386#
387get_variable()
388{
389	eval "echo \${$1}"
390}
391
392# set_default_value
393#
394# Set the value for a variable, if no value is set yet.
395#
396set_default_value()
397{
398	eval "$1=\${$1-$2}"
399}
400
401# get_build_tool_path
402#
403# Gets a usable absolute path of a build tool.
404#
405get_build_tool_path()
406{
407	local var="HAIKU_$1"
408	local varval="`get_variable $var`"
409	local cmd="$2"
410
411	if [ ! -z "$varval" ]; then
412		# this variable is already set (probably by user) so grab its contents
413		cmd=$varval
414	fi
415
416	local path=${cmd%% *}
417
418	if [ -f "$path" ]; then
419		# get absolute path from relative path
420		local oldPwd="`pwd`"
421		cd "`dirname "$path"`"
422		path="`pwd`/`basename "$path"`"
423		cd $oldPwd
424	else
425		which "$path" > /dev/null 2>&1 || {
426			echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
427			exit 1
428		}
429	fi
430
431	if test "${cmd#* }" != "$cmd"; then
432		# $cmd contains arguments, so preserve them (and only them)
433		cmd=${cmd#* }
434	else
435		# $cmd does not contain arguments, so unset it
436		cmd=
437	fi
438	eval "$var=\"$path $cmd\""
439}
440
441# check_native_xattrs
442#
443# Checks the host platform's support for extended attributes.
444# 0: no support, 1: only enough for xattr-ref, 2: full support
445#
446check_native_xattrs()
447{
448	local xattr_set=
449	local xattr_set_args=
450	local xattr_get=
451	local xattr_get_args=
452	case $HOST_PLATFORM in
453		haiku_host)
454			xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
455			xattr_get="catattr"; xattr_get_args="\$NAME"
456			;;
457		darwin)
458			xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
459			xattr_get="xattr"; xattr_get_args="-p \$NAME"
460			;;
461		freebsd)
462			xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
463			xattr_get="getextattr"; xattr_get_args="user \$NAME"
464			;;
465		linux)
466			xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
467			xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
468			;;
469		*)
470			return 0
471			;;
472	esac
473	if ! type $xattr_set >/dev/null 2>&1; then
474		echo "$0: could not find $xattr_set, assuming host has no extended attributes"
475		return 0
476	elif ! type $xattr_get >/dev/null 2>&1; then
477		echo "$0: could not find $xattr_get, assuming host has no extended attributes"
478		return 0
479	fi
480
481	mkdir -p "$outputDir"
482	echo "xattr test file" >"$outputDir/xattrtest"
483	local i=0
484	# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
485	# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
486	while [ $i -lt 2 ]; do
487		local j=0
488		while [ $j -lt 3 ]; do
489			NAME=attr$j
490			VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
491			if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
492				echo "$0: warning: could not generate test data for extended attributes"
493				rm "$outputDir/xattrtest"
494				return $i
495			elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
496					"$outputDir/xattrtest" >/dev/null 2>&1 ; then
497				rm "$outputDir/xattrtest"
498				return $i
499			fi
500			j=$((j+1))
501		done
502		i=$((i+1))
503	done
504	rm "$outputDir/xattrtest"
505	return 2
506}
507
508is_in_list()
509{
510	local element
511	for element in $2; do
512		if [ "$1" = "$element" ]; then
513			return 0
514		fi
515	done
516	return 1
517}
518
519# check for --help or -h and show usage immediately
520if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
521	usage; exit 0;
522fi
523
524# get cwd and the source directory
525currentDir=`pwd`
526cd `dirname "$0"`
527sourceDir=`pwd`
528cd "$currentDir"
529
530# determine output directory
531if [ "$currentDir" = "$sourceDir" ]; then
532	outputDir=$currentDir/generated
533else
534	outputDir=$currentDir
535fi
536buildOutputDir="$outputDir/build"
537HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
538buildConfigFile="$buildOutputDir/BuildConfig"
539
540# check for update request
541if [ "$1" = "--update" ]; then
542	if ! [ -e "$buildConfigFile" ]; then
543		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
544		exit 1
545	fi
546	# get last configure invocation and flags from BuildConfig and call ourselves with it
547	lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
548	lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
549	lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
550	lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
551	if [ -z "$lastConfig" ]; then
552		echo "$0 --update: The previous configure invocation was not properly" \
553			"encoded into '$buildConfigFile' - updating not possible."
554		exit 1
555	fi
556	cd "$lastPwd"
557	if [ -n "$lastEnv" ]; then
558		export $lastEnv
559	fi
560	$lastConfig $lastArgs
561	exit $?
562fi
563
564# backup the passed arguments
565configureArgs="$@"
566configurePath=$0
567configureDir=`dirname $configurePath`
568
569# backup relevant environs
570configureEnvirons=
571for var in `env`; do
572	case "$var" in
573		CC\=*|HAIKU*\=*|JAMSHELL\=*|HOST_PYTHON\=*)
574			configureEnvirons="$configureEnvirons $var"
575			;;
576	esac
577done
578
579# ensure umask is not too restrictive
580if [ `umask` -gt 22 ]; then
581	echo Your umask is too restrictive "(should be <= 0022;" is actually `umask`")"
582	echo
583	echo Additionally, if the source tree was cloned with a too-restrictive umask,
584	echo you will need to run \"git checkout\" again to fix this.
585	exit 1
586fi
587
588# internal default parameter values
589#
590platform=`uname`
591platformMachine=`uname  -m`
592targetArchs=
593buildCrossTools=
594buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
595buildCrossToolsJobs=
596useClang=0
597useGccGraphiteDefault=0
598unknownArchIndex=1
599haikuTargetArchs=
600gdbSources=
601
602if [ -z "$CC" ]; then
603	CC=gcc
604fi
605if [ $(is_legacy_gcc $($CC -dumpversion)) -ne 0 ]; then
606	if [ $platform == "Haiku" ] && [ $platformMachine == "BePC" ]; then
607		CC=gcc-x86
608	else
609		echo The host tools cannot be built with a legacy version of GCC.
610		echo Please specify a more modern compiler in the "CC" environ.
611		exit 1
612	fi
613fi
614
615# detect the build platform
616case "${platform}" in
617	Darwin)  HOST_PLATFORM=darwin ;;
618	FreeBSD) HOST_PLATFORM=freebsd
619	         if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
620	         	echo Unsupported platform: FreeBSD ${platformMachine}
621	         	exit 1
622	         fi ;;
623	Haiku)   HOST_PLATFORM=haiku_host ;;
624	Linux)   HOST_PLATFORM=linux ;;
625	OpenBSD) HOST_PLATFORM=openbsd ;;
626	*)       echo Unsupported platform: ${platform}
627	         exit 1 ;;
628esac
629
630case $HOST_PLATFORM in
631	darwin|freebsd|openbsd) statCmd='stat -f' ;;
632	*)                      statCmd='stat -c' ;;
633esac
634
635# ensure git checkout was not done with a restrictive umask
636if [ `$statCmd '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
637	echo "The source tree was cloned with a umask > 0022. It seems you"
638	echo have already corrected your umask, but not re-checked-out the
639	echo source tree. Try running:
640	echo "	git checkout --force"
641	echo to fix this problem.
642	exit 1
643fi
644
645# exported (BuildSetup) default parameter values
646#
647GIT_DIR=`git -C "$configureDir" rev-parse --git-dir | sed 's/^gitdir: //'`
648HOST_GCC_MACHINE=`$CC -dumpmachine`
649HAIKU_INCLUDE_SOURCES=0
650HAIKU_INCLUDE_3RDPARTY=0
651HAIKU_DISTRO_COMPATIBILITY=default
652TARGET_PLATFORM=haiku
653HAIKU_USE_GCC_PIPE=0
654HAIKU_HOST_USE_32BIT=0
655HAIKU_HOST_USE_XATTR=
656HAIKU_HOST_USE_XATTR_REF=
657HAIKU_HOST_BUILD_ONLY=0
658HOST_EXTENDED_REGEX_SED="sed -r"
659HOST_GCC_LD=`$CC -print-prog-name=ld`
660HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
661HOST_SHA256=
662HOST_HAIKU_PORTER=
663HAIKU_PORTS=
664HAIKU_PORTS_CROSS=
665HAIKU_IS_BOOTSTRAP=0
666HAIKU_NO_DOWNLOADS=0
667
668HAIKU_PACKAGING_ARCHS=
669
670set_default_value HAIKU_NASM		nasm
671
672if sha256sum < /dev/null > /dev/null 2>&1; then
673	HOST_SHA256=sha256sum
674elif sha256 < /dev/null > /dev/null 2>&1; then
675	HOST_SHA256="sha256 -q"
676elif shasum < /dev/null > /dev/null 2>&1; then
677	HOST_SHA256="shasum -a 256"
678else
679	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
680	exit 1
681fi
682
683haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
684export haikuRequiredLegacyGCCVersion
685	# version of legacy gcc required to build haiku
686supportedTargetArchs="
687	arm
688	arm64
689	m68k
690	ppc
691	riscv64
692	sparc
693	x86
694	x86_64
695	x86_gcc2
696	"
697
698# parse parameters
699#
700while [ $# -gt 0 ] ; do
701	case "$1" in
702		--sysroot)
703			assertparam "$1" $#
704			crossToolsSysroot=$2
705			shift 2
706			;;
707		--bootstrap)
708			assertparams "$1" 3 $#
709			HOST_HAIKU_PORTER="`absolute_path $2`"
710			HAIKU_PORTS_CROSS="`absolute_path $3`"
711			HAIKU_PORTS="`absolute_path $4`"
712			HAIKU_IS_BOOTSTRAP=1
713			HAIKU_NO_DOWNLOADS=1
714			if ! check_file_exists "$HOST_HAIKU_PORTER"; then
715				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
716				exit 1
717			fi
718			if ! check_dir_exists "$HAIKU_PORTS"; then
719				echo "Non-existent directory $HAIKU_PORTS" >&2
720				exit 1
721			fi
722			if ! check_dir_exists "$HAIKU_PORTS_CROSS"; then
723				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
724				exit 1
725			fi
726			shift 4
727			;;
728		--cross-tools-source)
729			assertparam "$1" $#
730			buildCrossTools=$2
731			shift 2
732			;;
733		--build-cross-tools)
734			assertparam "$1" $#
735			targetArch=$2
736			shift 2
737			case "$targetArch" in
738				x86_gcc2)	targetMachine=i586-pc-haiku;;
739				x86)		targetMachine=i586-pc-haiku;;
740				x86_64)		targetMachine=x86_64-unknown-haiku;;
741				ppc)		targetMachine=powerpc-apple-haiku;;
742				m68k)		targetMachine=m68k-unknown-haiku;;
743				arm)		targetMachine=arm-unknown-haiku;;
744				arm64)		targetMachine=aarch64-unknown-haiku;;
745				riscv64)	targetMachine=riscv64-unknown-haiku;;
746				sparc)		targetMachine=sparc64-unknown-haiku;;
747				*)
748					echo "Unsupported target architecture: $targetArch" >&2
749					exit 1
750					;;
751			esac
752			set_variable buildCrossToolsMachine_$targetArch $targetMachine
753			targetArchs="$targetArchs $targetArch"
754			;;
755		--cross-tools-prefix)
756			assertparam "$1" $#
757			targetArch=unknown${unknownArchIndex}
758			set_variable crossToolsPrefix_$targetArch "$2"
759			targetArchs="$targetArchs $targetArch"
760			unknownArchIndex=$(($unknownArchIndex + 1))
761			shift 2
762			;;
763		--distro-compatibility)
764			assertparam "$1" $#
765			HAIKU_DISTRO_COMPATIBILITY=$2
766			case "$HAIKU_DISTRO_COMPATIBILITY" in
767				official)	;;
768				compatible)	;;
769				default)	;;
770				*)			echo "Invalid distro compatibility" \
771								"level: $HAIKU_DISTRO_COMPATIBILITY"
772							exit 1;;
773			esac
774			shift 2
775			;;
776		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
777		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
778		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
779        -j*)				buildCrossToolsJobs="$1"; shift 1;;
780		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
781		--target-arch)
782			assertparam "$1" $#
783			targetArch=$2
784			shift 2
785			if [ ! "$platform" = Haiku ]; then
786				echo "--target-arch can only be specified on Haiku." >&2
787				exit 1
788			fi
789			is_in_list "$targetArch" "$supportedTargetArchs" || (
790				echo "Unsupported target architecture: \"$targetArch\"" >&2
791				exit 1
792			)
793			haikuTargetArchs="$haikuTargetArchs $targetArch"
794			;;
795		--use-clang)
796			assertparam "$1" $#
797			targetArch=$2
798			useClang=1
799			case "$targetArch" in
800				x86)		targetMachine=i586-pc-haiku;;
801				x86_64)		targetMachine=x86_64-unknown-haiku;;
802				ppc)		targetMachine=powerpc-apple-haiku;;
803				arm)		targetMachine=arm-unknown-haiku;;
804				arm64)		targetMachine=aarch64-unknown-haiku;;
805				riscv64)	targetMachine=riscv64-unknown-haiku;;
806				sparc)		targetMachine=sparc64-unknown-haiku;;
807				*)
808					echo "Unsupported target architecture: $2" >&2
809					exit 1
810					;;
811			esac
812			get_build_tool_path clang clang
813			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
814					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
815				set_variable crossToolsPrefix_$targetArch llvm-
816			fi
817			clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
818			if [ `echo $clangVersion | cut -d'.' -f1` -lt 7 ]; then
819				echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
820				echo "Please install a newer version."
821				exit 1
822			fi
823			targetArchs="$targetArchs $targetArch"
824			shift 2
825			;;
826		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
827		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
828		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
829		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
830		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
831		--with-gdb)	gdbSources=$2; shift 2;;
832		--use-stack-protector)	HAIKU_USE_STACK_PROTECTOR=1; shift 1;;
833		--efi-signing-key)
834			assertparam "$1" $#
835			HAIKU_EFI_SIGNING_KEY="$2"
836			shift 2
837			;;
838		*)				echo Invalid argument: \`$1\'; exit 1;;
839	esac
840done
841
842# check for case-sensitive filesystem
843mkdir haikuCaseTest 2>/dev/null
844mkdir haikucasetest 2>/dev/null
845caseInsensitive=$?
846rmdir haikuCaseTest haikucasetest 2>/dev/null
847if [ $caseInsensitive != 0 ]; then
848	echo "You need a case-sensitive file-system to build Haiku."
849	if [ $HOST_PLATFORM = "darwin" ]; then
850		echo "You can create a case-sensitive disk image using Disk Utility."
851	fi
852	exit 1
853fi
854
855# check xattr support
856if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
857	check_native_xattrs
858	attrSupport=$?
859	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
860		HAIKU_HOST_USE_XATTR=1
861	elif [ $attrSupport = 1 ]; then
862		HAIKU_HOST_USE_XATTR_REF=1
863	fi
864fi
865if [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
866if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
867
868# determine how to invoke sed with extended regexp support for non-GNU sed
869if [ $HOST_PLATFORM = "darwin" ]; then
870	HOST_EXTENDED_REGEX_SED="sed -E"
871fi
872
873# pick a JAMSHELL
874if [ "$JAMSHELL" = "" ]; then
875	if check_file_exists /bin/dash; then
876		JAMSHELL=/bin/dash
877	else
878		JAMSHELL=/bin/sh
879	fi
880fi
881if ! $JAMSHELL -c true; then
882	echo "$JAMSHELL does not work! Please specify a working JAMSHELL."
883	exit 1
884fi
885
886# locate python
887if [ -z "$HOST_PYTHON" ]; then
888	if python3 --version < /dev/null > /dev/null 2>&1; then
889		HOST_PYTHON="python3"
890	elif python --version < /dev/null > /dev/null 2>&1; then
891		HOST_PYTHON="python"
892	else
893		echo "a python interpreter is required"
894		exit 1
895	fi
896fi
897
898# check is python is new enough
899# usage of python by HDS requires at least 3.9
900PYTHON_VERSION=$("$HOST_PYTHON" --version 2>&1 | sed -e 's/Python //')
901
902case $PYTHON_VERSION in
903	2.* | 3.[1-8].*)
904		echo "Python $PYTHON_VERSION is too old; need at least Python 3.9."
905		echo "(maybe specify a Python interpreter to use in HOST_PYTHON?)"
906		exit 1
907		;;
908	*)
909		;;
910esac
911
912# check if wget supports --retry-on-host-error
913if wget --retry-on-host-error --version > /dev/null 2>&1; then
914	HOST_WGET_RETRY_ON_HOST_ERROR=1
915fi
916
917# check if nasm can actually output ELF files
918# (the stock version in OSX can't)
919# XXX: should probably only test for x86* arch
920if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
921	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
922	if [ $HOST_PLATFORM = "darwin" ]; then
923		echo "You can install it from Mac Ports."
924		echo "Mac Ports is available at: http://www.macports.org/"
925	fi
926	exit 1
927fi
928
929# create output directory
930mkdir -p "$buildOutputDir" || exit 1
931
932if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
933	invalidCommand=$sourceDir/build/scripts/host_build_only
934	HAIKU_AR=$invalidCommand
935	HAIKU_CC=$invalidCommand
936	HAIKU_LD=$invalidCommand
937	HAIKU_OBJCOPY=$invalidCommand
938	HAIKU_RANLIB=$invalidCommand
939	HAIKU_ELFEDIT=$invalidCommand
940	HAIKU_NASM=$invalidCommand
941	HAIKU_STRIP=$invalidCommand
942else
943	# On Haiku determine target architectures and tools automatically.
944	if [ -z "$targetArchs" ]; then
945		if [ $HOST_PLATFORM != haiku_host ]; then
946			echo "Please specify the build tools to use or build (via" \
947				"--cross-tools-prefix or --build-cross-tools) or specify a" \
948				"host-only build (--host-only)." >&2
949			echo "For more info, invoke $0 --help"
950			exit 1
951		fi
952
953		# determine primary architecture
954		targetArch=`package list -i /system/packages/haiku-*.hpkg \
955			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
956		is_in_list "$targetArch" "$supportedTargetArchs" || (
957			echo "Unsupported target architecture: \"$targetArch\"" >&2
958			exit 1
959		)
960		targetArchs=$targetArch
961
962		set_default_value HAIKU_AR_$targetArch			ar
963		set_default_value HAIKU_CC_$targetArch			gcc
964		set_default_value HAIKU_LD_$targetArch			ld
965		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
966		set_default_value HAIKU_RANLIB_$targetArch		ranlib
967		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
968		set_default_value HAIKU_STRIP_$targetArch		strip
969
970		# determine secondary architectures
971		for targetArch in $supportedTargetArchs; do
972			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
973				targetArchs="$targetArchs $targetArch"
974				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
975				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
976				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
977				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
978				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
979				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
980				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
981			fi
982		done
983
984		# The target architectures might have been specified explicitly.
985		if [ -n "$haikuTargetArchs" ]; then
986			for targetArch in $haikuTargetArchs; do
987				is_in_list "$targetArch" "$targetArchs" || (
988					echo "Unsupported target architecture: \"$targetArch\"." \
989						"Only native architectures of the host platform can" \
990						"be specified." >&2
991					exit 1
992				)
993			done
994			targetArchs="$haikuTargetArchs"
995		fi
996	fi
997
998	if [ "$targetArchs" = " x86_gcc2" ]; then
999		echo "Building a GCC2-only Haiku is no longer supported."
1000		echo "Please configure the secondary architecture."
1001		exit 1
1002	fi
1003
1004	isPrimaryArch=1
1005	for targetArch in $targetArchs; do
1006		# Note: targetArch is "unknown<n>" at this point if a cross-tools
1007		# prefix was specified. The standard_gcc_settings call below will get
1008		# the actual architecture.
1009
1010		for existingArch in $HAIKU_PACKAGING_ARCHS; do
1011			if [ $existingArch = $targetArch ]; then
1012				# somehow we wound up with a duplicate arch; skip this one
1013				targetArch=
1014				break
1015			fi
1016		done
1017		if [ -z "$targetArch" ]; then
1018			continue
1019		fi
1020
1021		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
1022
1023		# build cross tools from sources
1024		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
1025			crossToolsDir="$outputDir/cross-tools-$targetArch"
1026			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
1027			script="$buildCrossToolsScript"
1028			scriptArgs=
1029			if [ $targetArch != x86_gcc2 ]; then
1030				script="${script}_gcc4"
1031				scriptArgs="$targetMachine"
1032				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
1033					$useGccGraphiteDefault
1034			fi
1035			secondaryArch=
1036			if [ -z "$isPrimaryArch" ]; then
1037				secondaryArch=$targetArch
1038			fi
1039
1040			case $HOST_PLATFORM in
1041				freebsd|openbsd)	MAKE=gmake;;
1042				*)					MAKE=make;;
1043			esac
1044
1045			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
1046				MAKE=$MAKE \
1047				SECONDARY_ARCH=$secondaryArch \
1048				HAIKU_USE_GCC_GRAPHITE=`get_variable \
1049					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
1050				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
1051				HAIKU_USE_GDB="$gdbSources" \
1052				HAIKU_USE_SYSROOT="$crossToolsSysroot" \
1053				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
1054					"$crossToolsDir" $buildCrossToolsJobs || exit 1
1055			else
1056				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
1057			fi
1058			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
1059		fi
1060
1061		# prepare gcc settings and get the actual target architecture
1062		if [ $useClang = 1 ]; then
1063			gcc="$HAIKU_clang -target ${targetMachine}"
1064			if [ ! -z "${crossToolsPrefix}" ]; then
1065				gcc="$gcc -B ${crossToolsPrefix}"
1066			fi
1067
1068			# Clang's compiler intrinsics are not compatible with GCC's or even
1069			# across versions of Clang, so we must collect them for use in the build.
1070			mkdir -p "$outputDir/clang_headers" || exit 1
1071			clangHeadersDir=`$gcc -print-resource-dir`/include/
1072			case $targetArch in
1073				x86*) cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1 ;;
1074				ppc*) cp $clangHeadersDir/*altivec* "$outputDir/clang_headers" || exit 1 ;;
1075				arm*) cp $clangHeadersDir/*arm* "$outputDir/clang_headers" || exit 1 ;;
1076			esac
1077		elif [ -z "${crossToolsPrefix}" ]; then
1078			gcc=`get_variable HAIKU_CC_$targetArch`
1079		else
1080			gcc="${crossToolsPrefix}gcc"
1081		fi
1082
1083		if [ -z "$gcc" ]; then
1084			echo "Please specify the build tools to use or build (via" \
1085				"--cross-tools-prefix or --build-cross-tools)." >&2
1086			echo "For more info, invoke $0 --help"
1087			exit 1
1088		fi
1089		standard_gcc_settings "$gcc"
1090		targetArch=$standard_gcc_settings_targetArch
1091
1092		# set default values for flags
1093		set_default_value HAIKU_CPPFLAGS_$targetArch	""
1094		set_default_value HAIKU_CCFLAGS_$targetArch		""
1095		set_default_value HAIKU_CXXFLAGS_$targetArch	""
1096		set_default_value HAIKU_LINKFLAGS_$targetArch	""
1097		set_default_value HAIKU_LDFLAGS_$targetArch		""
1098		set_default_value HAIKU_ARFLAGS_$targetArch		cru
1099		set_default_value HAIKU_UNARFLAGS_$targetArch	x
1100
1101		# Override the cross tools variables, if the tools were built or a
1102		# prefix was specified.
1103		if [ -n "$crossToolsPrefix" ]; then
1104			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
1105			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
1106			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
1107			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
1108
1109			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
1110			if [ `get_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch` -eq 0 ]; then
1111				get_build_tool_path ELFEDIT_$targetArch ${crossToolsPrefix}elfedit
1112			fi
1113		fi
1114
1115		# check whether the Haiku compiler really targets Haiku
1116		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
1117		case "$targetMachine" in
1118			*-*-haiku)	;;
1119			*)
1120				echo The compiler specified as Haiku target compiler is not a \
1121				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
1122				echo compiler: $HAIKU_CC
1123				echo compiler is configured for target: $targetMachine
1124				exit 1 ;;
1125		esac
1126
1127		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
1128		isPrimaryArch=
1129	done
1130fi
1131
1132# Generate BuildConfig
1133cat << EOF > "$buildConfigFile"
1134# -- WARNING --
1135# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1136# overwritten the next time configure is run.
1137#
1138#d ${currentDir}
1139#c ${configurePath}
1140#e ${configureEnvirons}
1141#a ${configureArgs}
1142
1143GIT_DIR						?= "${GIT_DIR}" ;
1144
1145HOST_PLATFORM				?= "${HOST_PLATFORM}" ;
1146TARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
1147HAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
1148
1149HAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
1150HAIKU_INCLUDE_SOURCES		?= "${HAIKU_INCLUDE_SOURCES}" ;
1151HAIKU_INCLUDE_3RDPARTY		?= "${HAIKU_INCLUDE_3RDPARTY}" ;
1152HAIKU_DISTRO_COMPATIBILITY	?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
1153
1154HAIKU_USE_GCC_PIPE			?= "${HAIKU_USE_GCC_PIPE}" ;
1155HAIKU_HOST_USE_32BIT		?= "${HAIKU_HOST_USE_32BIT}" ;
1156HAIKU_HOST_USE_XATTR		?= "${HAIKU_HOST_USE_XATTR}" ;
1157HAIKU_HOST_USE_XATTR_REF	?= "${HAIKU_HOST_USE_XATTR_REF}" ;
1158HAIKU_HOST_BUILD_ONLY		?= "${HAIKU_HOST_BUILD_ONLY}" ;
1159
1160JAMSHELL					?= ${JAMSHELL} -e -c ;
1161
1162HOST_CC						?= ${CC} ;
1163HOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
1164HOST_LD						?= ${HOST_GCC_LD} ;
1165HOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
1166HOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
1167HOST_SHA256					?= ${HOST_SHA256} ;
1168HOST_PYTHON					?= ${HOST_PYTHON} ;
1169HOST_WGET_RETRY_ON_HOST_ERROR			?= ${HOST_WGET_RETRY_ON_HOST_ERROR} ;
1170HAIKU_NASM					?= ${HAIKU_NASM} ;
1171
1172HAIKU_BUILD_ATTRIBUTES_DIR	?= "${HAIKU_BUILD_ATTRIBUTES_DIR}" ;
1173
1174HOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1175HAIKU_PORTS					?= ${HAIKU_PORTS} ;
1176HAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1177HAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1178
1179HAIKU_BOOT_EFI_PRIVATE_KEYFILE	?= ${HAIKU_EFI_SIGNING_KEY} ;
1180EOF
1181
1182for targetArch in $HAIKU_PACKAGING_ARCHS; do
1183	variables="
1184		HAIKU_CC					HAIKU_CC
1185		HAIKU_CC_IS_LEGACY_GCC		HAIKU_CC_IS_LEGACY_GCC
1186		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1187		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1188		HAIKU_CPU					HAIKU_CPU
1189		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1190		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1191		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1192		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
1193		HAIKU_BOOT_32_LIBGCC		HAIKU_BOOT_32_LIBGCC
1194		HAIKU_BOOT_32_LIBSUPC++		HAIKU_BOOT_32_LIBSUPCXX
1195		HAIKU_AR					HAIKU_AR
1196		HAIKU_LD					HAIKU_LD
1197		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1198		HAIKU_RANLIB				HAIKU_RANLIB
1199		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1200		HAIKU_STRIP					HAIKU_STRIP
1201		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1202		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1203		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1204		HAIKU_LINKFLAGS				HAIKU_LINKFLAGS
1205		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1206		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1207		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1208		"
1209	set -- $variables
1210	while [ $# -ge 2 ]; do
1211		value=`get_variable ${2}_$targetArch`
1212		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1213		shift 2
1214	done
1215
1216	# For variables that may have long values, distribute them over multiple
1217	# lines so that jam doesn't hit the maximum line length.
1218	variables="
1219		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
1220		HAIKU_BOOT_32_C++_HEADERS_DIR	HAIKU_BOOT_32_CXX_HEADERS_DIR
1221		"
1222	set -- $variables
1223	while [ $# -ge 2 ]; do
1224		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1225		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1226			>> "$buildConfigFile"
1227		echo "    ;" >> "$buildConfigFile"
1228		shift 2
1229	done
1230done
1231
1232
1233# Generate a Jamfile in the output directory.
1234
1235cat << EOF > $outputDir/Jamfile
1236# -- WARNING --
1237# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1238# overwritten the next time configure is run.
1239
1240HAIKU_TOP			= $(relative_to "${sourceDir}" "${outputDir}") ;
1241HAIKU_OUTPUT_DIR	= . ;
1242
1243include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1244
1245EOF
1246
1247echo "Configured successfully!"
1248