xref: /haiku/configure (revision 2a39b810fa53ad6d9f9f408bb49f0b1d6a4a2550)
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	echo The host tools cannot be built with a legacy version of GCC.
607	echo Please specify a more modern compiler in the "CC" environ.
608	exit 1
609fi
610
611# detect the build platform
612case "${platform}" in
613	Darwin)  HOST_PLATFORM=darwin ;;
614	FreeBSD) HOST_PLATFORM=freebsd
615	         if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
616	         	echo Unsupported platform: FreeBSD ${platformMachine}
617	         	exit 1
618	         fi ;;
619	Haiku)   HOST_PLATFORM=haiku_host ;;
620	Linux)   HOST_PLATFORM=linux ;;
621	OpenBSD) HOST_PLATFORM=openbsd ;;
622	*)       echo Unsupported platform: ${platform}
623	         exit 1 ;;
624esac
625
626case $HOST_PLATFORM in
627	darwin|freebsd|openbsd) statCmd='stat -f' ;;
628	*)                      statCmd='stat -c' ;;
629esac
630
631# ensure git checkout was not done with a restrictive umask
632if [ `$statCmd '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
633	echo "The source tree was cloned with a umask > 0022. It seems you"
634	echo have already corrected your umask, but not re-checked-out the
635	echo source tree. Try running:
636	echo "	git checkout --force"
637	echo to fix this problem.
638	exit 1
639fi
640
641# exported (BuildSetup) default parameter values
642#
643GIT_DIR=`git -C "$configureDir" rev-parse --git-dir | sed 's/^gitdir: //'`
644HOST_GCC_MACHINE=`$CC -dumpmachine`
645HAIKU_INCLUDE_SOURCES=0
646HAIKU_INCLUDE_3RDPARTY=0
647HAIKU_DISTRO_COMPATIBILITY=default
648TARGET_PLATFORM=haiku
649HAIKU_USE_GCC_PIPE=0
650HAIKU_HOST_USE_32BIT=0
651HAIKU_HOST_USE_XATTR=
652HAIKU_HOST_USE_XATTR_REF=
653HAIKU_HOST_BUILD_ONLY=0
654HOST_EXTENDED_REGEX_SED="sed -r"
655HOST_GCC_LD=`$CC -print-prog-name=ld`
656HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
657HOST_SHA256=
658HOST_HAIKU_PORTER=
659HAIKU_PORTS=
660HAIKU_PORTS_CROSS=
661HAIKU_IS_BOOTSTRAP=0
662HAIKU_NO_DOWNLOADS=0
663
664HAIKU_PACKAGING_ARCHS=
665
666set_default_value HAIKU_NASM		nasm
667
668if sha256sum < /dev/null > /dev/null 2>&1; then
669	HOST_SHA256=sha256sum
670elif sha256 < /dev/null > /dev/null 2>&1; then
671	HOST_SHA256="sha256 -q"
672elif shasum < /dev/null > /dev/null 2>&1; then
673	HOST_SHA256="shasum -a 256"
674else
675	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
676	exit 1
677fi
678
679haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
680export haikuRequiredLegacyGCCVersion
681	# version of legacy gcc required to build haiku
682supportedTargetArchs="
683	arm
684	arm64
685	m68k
686	ppc
687	riscv64
688	sparc
689	x86
690	x86_64
691	x86_gcc2
692	"
693
694# parse parameters
695#
696while [ $# -gt 0 ] ; do
697	case "$1" in
698		--sysroot)
699			assertparam "$1" $#
700			crossToolsSysroot=$2
701			shift 2
702			;;
703		--bootstrap)
704			assertparams "$1" 3 $#
705			HOST_HAIKU_PORTER="`absolute_path $2`"
706			HAIKU_PORTS_CROSS="`absolute_path $3`"
707			HAIKU_PORTS="`absolute_path $4`"
708			HAIKU_IS_BOOTSTRAP=1
709			HAIKU_NO_DOWNLOADS=1
710			check_file_exists "$HOST_HAIKU_PORTER" || (
711				echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
712				exit 1
713			)
714			check_dir_exists "$HAIKU_PORTS" || (
715				echo "Non-existent directory $HAIKU_PORTS" >&2
716				exit 1
717			)
718			check_dir_exists "$HAIKU_PORTS_CROSS" || (
719				echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
720				exit 1
721			)
722			shift 4
723			;;
724		--cross-tools-source)
725			assertparam "$1" $#
726			buildCrossTools=$2
727			shift 2
728			;;
729		--build-cross-tools)
730			assertparam "$1" $#
731			targetArch=$2
732			shift 2
733			case "$targetArch" in
734				x86_gcc2)	targetMachine=i586-pc-haiku;;
735				x86)		targetMachine=i586-pc-haiku;;
736				x86_64)		targetMachine=x86_64-unknown-haiku;;
737				ppc)		targetMachine=powerpc-apple-haiku;;
738				m68k)		targetMachine=m68k-unknown-haiku;;
739				arm)		targetMachine=arm-unknown-haiku;;
740				arm64)		targetMachine=aarch64-unknown-haiku;;
741				riscv64)	targetMachine=riscv64-unknown-haiku;;
742				sparc)		targetMachine=sparc64-unknown-haiku;;
743				*)
744					echo "Unsupported target architecture: $targetArch" >&2
745					exit 1
746					;;
747			esac
748			set_variable buildCrossToolsMachine_$targetArch $targetMachine
749			targetArchs="$targetArchs $targetArch"
750			;;
751		--cross-tools-prefix)
752			assertparam "$1" $#
753			targetArch=unknown${unknownArchIndex}
754			set_variable crossToolsPrefix_$targetArch "$2"
755			targetArchs="$targetArchs $targetArch"
756			unknownArchIndex=$(($unknownArchIndex + 1))
757			shift 2
758			;;
759		--distro-compatibility)
760			assertparam "$1" $#
761			HAIKU_DISTRO_COMPATIBILITY=$2
762			case "$HAIKU_DISTRO_COMPATIBILITY" in
763				official)	;;
764				compatible)	;;
765				default)	;;
766				*)			echo "Invalid distro compatibility" \
767								"level: $HAIKU_DISTRO_COMPATIBILITY"
768							exit 1;;
769			esac
770			shift 2
771			;;
772		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
773		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
774		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
775        -j*)				buildCrossToolsJobs="$1"; shift 1;;
776		--no-downloads)	HAIKU_NO_DOWNLOADS=1; shift 1;;
777		--target-arch)
778			assertparam "$1" $#
779			targetArch=$2
780			shift 2
781			if [ ! "$platform" = Haiku ]; then
782				echo "--target-arch can only be specified on Haiku." >&2
783				exit 1
784			fi
785			is_in_list "$targetArch" "$supportedTargetArchs" || (
786				echo "Unsupported target architecture: \"$targetArch\"" >&2
787				exit 1
788			)
789			haikuTargetArchs="$haikuTargetArchs $targetArch"
790			;;
791		--use-clang)
792			assertparam "$1" $#
793			targetArch=$2
794			useClang=1
795			case "$targetArch" in
796				x86)		targetMachine=i586-pc-haiku;;
797				x86_64)		targetMachine=x86_64-unknown-haiku;;
798				ppc)		targetMachine=powerpc-apple-haiku;;
799				arm)		targetMachine=arm-unknown-haiku;;
800				arm64)		targetMachine=aarch64-unknown-haiku;;
801				riscv64)	targetMachine=riscv64-unknown-haiku;;
802				sparc)		targetMachine=sparc64-unknown-haiku;;
803				*)
804					echo "Unsupported target architecture: $2" >&2
805					exit 1
806					;;
807			esac
808			get_build_tool_path clang clang
809			if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
810					&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
811				set_variable crossToolsPrefix_$targetArch llvm-
812			fi
813			clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
814			if [ `echo $clangVersion | cut -d'.' -f1` -lt 7 ]; then
815				echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
816				echo "Please install a newer version."
817				exit 1
818			fi
819			targetArchs="$targetArchs $targetArch"
820			shift 2
821			;;
822		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
823		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
824		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
825		--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
826		--no-xattr)		HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
827		--with-gdb)	gdbSources=$2; shift 2;;
828		--use-stack-protector)	HAIKU_USE_STACK_PROTECTOR=1; shift 1;;
829		--efi-signing-key)
830			assertparam "$1" $#
831			HAIKU_EFI_SIGNING_KEY="$2"
832			shift 2
833			;;
834		*)				echo Invalid argument: \`$1\'; exit 1;;
835	esac
836done
837
838# check for case-sensitive filesystem
839mkdir haikuCaseTest 2>/dev/null
840mkdir haikucasetest 2>/dev/null
841caseInsensitive=$?
842rmdir haikuCaseTest haikucasetest 2>/dev/null
843if [ $caseInsensitive != 0 ]; then
844	echo "You need a case-sensitive file-system to build Haiku."
845	if [ $HOST_PLATFORM = "darwin" ]; then
846		echo "You can create a case-sensitive disk image using Disk Utility."
847	fi
848	exit 1
849fi
850
851# check xattr support
852if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
853	check_native_xattrs
854	attrSupport=$?
855	if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
856		HAIKU_HOST_USE_XATTR=1
857	elif [ $attrSupport = 1 ]; then
858		HAIKU_HOST_USE_XATTR_REF=1
859	fi
860fi
861if [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
862if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
863
864# determine how to invoke sed with extended regexp support for non-GNU sed
865if [ $HOST_PLATFORM = "darwin" ]; then
866	HOST_EXTENDED_REGEX_SED="sed -E"
867fi
868
869# pick a JAMSHELL
870if [ "$JAMSHELL" = "" ]; then
871	if check_file_exists /bin/dash; then
872		JAMSHELL=/bin/dash
873	else
874		JAMSHELL=/bin/sh
875	fi
876fi
877if ! $JAMSHELL -c true; then
878	echo "$JAMSHELL does not work! Please specify a working JAMSHELL."
879	exit 1
880fi
881
882# locate python
883if [ -z "$HOST_PYTHON" ]; then
884	if python3 --version < /dev/null > /dev/null 2>&1; then
885		HOST_PYTHON="python3"
886	elif python --version < /dev/null > /dev/null 2>&1; then
887		HOST_PYTHON="python"
888	else
889		echo "a python interpreter is required"
890		exit 1
891	fi
892fi
893
894# check is python is new enough
895# usage of python by HDS requires at least 3.9
896PYTHON_VERSION=$("$HOST_PYTHON" --version 2>&1 | sed -e 's/Python //')
897
898case $PYTHON_VERSION in
899	2.* | 3.[1-8].*)
900		echo "Python $PYTHON_VERSION is too old; need at least Python 3.9."
901		echo "(maybe specify a Python interpreter to use in HOST_PYTHON?)"
902		exit 1
903		;;
904	*)
905		;;
906esac
907
908# check if wget supports --retry-on-host-error
909if wget --retry-on-host-error --version > /dev/null 2>&1; then
910	HOST_WGET_RETRY_ON_HOST_ERROR=1
911fi
912
913# check if nasm can actually output ELF files
914# (the stock version in OSX can't)
915# XXX: should probably only test for x86* arch
916if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
917	echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
918	if [ $HOST_PLATFORM = "darwin" ]; then
919		echo "You can install it from Mac Ports."
920		echo "Mac Ports is available at: http://www.macports.org/"
921	fi
922	exit 1
923fi
924
925# create output directory
926mkdir -p "$buildOutputDir" || exit 1
927
928if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
929	invalidCommand=$sourceDir/build/scripts/host_build_only
930	HAIKU_AR=$invalidCommand
931	HAIKU_CC=$invalidCommand
932	HAIKU_LD=$invalidCommand
933	HAIKU_OBJCOPY=$invalidCommand
934	HAIKU_RANLIB=$invalidCommand
935	HAIKU_ELFEDIT=$invalidCommand
936	HAIKU_NASM=$invalidCommand
937	HAIKU_STRIP=$invalidCommand
938else
939	# On Haiku determine target architectures and tools automatically.
940	if [ -z "$targetArchs" ]; then
941		if [ $HOST_PLATFORM != haiku_host ]; then
942			echo "Please specify the build tools to use or build (via" \
943				"--cross-tools-prefix or --build-cross-tools) or specify a" \
944				"host-only build (--host-only)." >&2
945			echo "For more info, invoke $0 --help"
946			exit 1
947		fi
948
949		# determine primary architecture
950		targetArch=`package list -i /system/packages/haiku-*.hpkg \
951			| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
952		is_in_list "$targetArch" "$supportedTargetArchs" || (
953			echo "Unsupported target architecture: \"$targetArch\"" >&2
954			exit 1
955		)
956		targetArchs=$targetArch
957
958		set_default_value HAIKU_AR_$targetArch			ar
959		set_default_value HAIKU_CC_$targetArch			gcc
960		set_default_value HAIKU_LD_$targetArch			ld
961		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
962		set_default_value HAIKU_RANLIB_$targetArch		ranlib
963		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
964		set_default_value HAIKU_STRIP_$targetArch		strip
965
966		# determine secondary architectures
967		for targetArch in $supportedTargetArchs; do
968			if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
969				targetArchs="$targetArchs $targetArch"
970				set_default_value HAIKU_AR_$targetArch		ar-$targetArch
971				set_default_value HAIKU_CC_$targetArch		gcc-$targetArch
972				set_default_value HAIKU_LD_$targetArch		ld-$targetArch
973				set_default_value HAIKU_OBJCOPY_$targetArch	objcopy-$targetArch
974				set_default_value HAIKU_RANLIB_$targetArch	ranlib-$targetArch
975				set_default_value HAIKU_ELFEDIT_$targetArch	elfedit-$targetArch
976				set_default_value HAIKU_STRIP_$targetArch	strip-$targetArch
977			fi
978		done
979
980		# The target architectures might have been specified explicitly.
981		if [ -n "$haikuTargetArchs" ]; then
982			for targetArch in $haikuTargetArchs; do
983				is_in_list "$targetArch" "$targetArchs" || (
984					echo "Unsupported target architecture: \"$targetArch\"." \
985						"Only native architectures of the host platform can" \
986						"be specified." >&2
987					exit 1
988				)
989			done
990			targetArchs="$haikuTargetArchs"
991		fi
992	fi
993
994	if [ "$targetArchs" = " x86_gcc2" ]; then
995		echo "Building a GCC2-only Haiku is no longer supported."
996		echo "Please configure the secondary architecture."
997		exit 1
998	fi
999
1000	isPrimaryArch=1
1001	for targetArch in $targetArchs; do
1002		# Note: targetArch is "unknown<n>" at this point if a cross-tools
1003		# prefix was specified. The standard_gcc_settings call below will get
1004		# the actual architecture.
1005
1006		for existingArch in $HAIKU_PACKAGING_ARCHS; do
1007			if [ $existingArch = $targetArch ]; then
1008				# somehow we wound up with a duplicate arch; skip this one
1009				targetArch=
1010				break
1011			fi
1012		done
1013		if [ -z "$targetArch" ]; then
1014			continue
1015		fi
1016
1017		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
1018
1019		# build cross tools from sources
1020		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
1021			crossToolsDir="$outputDir/cross-tools-$targetArch"
1022			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
1023			script="$buildCrossToolsScript"
1024			scriptArgs=
1025			if [ $targetArch != x86_gcc2 ]; then
1026				script="${script}_gcc4"
1027				scriptArgs="$targetMachine"
1028				set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch	\
1029					$useGccGraphiteDefault
1030			fi
1031			secondaryArch=
1032			if [ -z "$isPrimaryArch" ]; then
1033				secondaryArch=$targetArch
1034			fi
1035
1036			case $HOST_PLATFORM in
1037				freebsd|openbsd)	MAKE=gmake;;
1038				*)					MAKE=make;;
1039			esac
1040
1041			if ! valid_toolchain "${targetMachine}" "${crossToolsDir}" "${buildCrossTools}"; then
1042				MAKE=$MAKE \
1043				SECONDARY_ARCH=$secondaryArch \
1044				HAIKU_USE_GCC_GRAPHITE=`get_variable \
1045					HAIKU_USE_GCC_GRAPHITE_$targetArch` \
1046				HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
1047				HAIKU_USE_GDB="$gdbSources" \
1048				HAIKU_USE_SYSROOT="$crossToolsSysroot" \
1049				"$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
1050					"$crossToolsDir" $buildCrossToolsJobs || exit 1
1051			else
1052				echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
1053			fi
1054			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
1055		fi
1056
1057		# prepare gcc settings and get the actual target architecture
1058		if [ $useClang = 1 ]; then
1059			gcc="$HAIKU_clang -target ${targetMachine}"
1060			if [ ! -z "${crossToolsPrefix}" ]; then
1061				gcc="$gcc -B ${crossToolsPrefix}"
1062			fi
1063
1064			# Clang's compiler intrinsics are not compatible with GCC's or even
1065			# across versions of Clang, so we must collect them for use in the build.
1066			mkdir -p "$outputDir/clang_headers" || exit 1
1067			clangHeadersDir=`$gcc -print-resource-dir`/include/
1068			case $targetArch in
1069				x86*) cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1 ;;
1070				ppc*) cp $clangHeadersDir/*altivec* "$outputDir/clang_headers" || exit 1 ;;
1071				arm*) cp $clangHeadersDir/*arm* "$outputDir/clang_headers" || exit 1 ;;
1072			esac
1073		elif [ -z "${crossToolsPrefix}" ]; then
1074			gcc=`get_variable HAIKU_CC_$targetArch`
1075		else
1076			gcc="${crossToolsPrefix}gcc"
1077		fi
1078
1079		if [ -z "$gcc" ]; then
1080			echo "Please specify the build tools to use or build (via" \
1081				"--cross-tools-prefix or --build-cross-tools)." >&2
1082			echo "For more info, invoke $0 --help"
1083			exit 1
1084		fi
1085		standard_gcc_settings "$gcc"
1086		targetArch=$standard_gcc_settings_targetArch
1087
1088		# set default values for flags
1089		set_default_value HAIKU_CPPFLAGS_$targetArch	""
1090		set_default_value HAIKU_CCFLAGS_$targetArch		""
1091		set_default_value HAIKU_CXXFLAGS_$targetArch	""
1092		set_default_value HAIKU_LINKFLAGS_$targetArch	""
1093		set_default_value HAIKU_LDFLAGS_$targetArch		""
1094		set_default_value HAIKU_ARFLAGS_$targetArch		cru
1095		set_default_value HAIKU_UNARFLAGS_$targetArch	x
1096
1097		# Override the cross tools variables, if the tools were built or a
1098		# prefix was specified.
1099		if [ -n "$crossToolsPrefix" ]; then
1100			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
1101			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
1102			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
1103			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
1104
1105			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
1106			if [ `get_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch` -eq 0 ]; then
1107				get_build_tool_path ELFEDIT_$targetArch ${crossToolsPrefix}elfedit
1108			fi
1109		fi
1110
1111		# check whether the Haiku compiler really targets Haiku
1112		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
1113		case "$targetMachine" in
1114			*-*-haiku)	;;
1115			*)
1116				echo The compiler specified as Haiku target compiler is not a \
1117				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
1118				echo compiler: $HAIKU_CC
1119				echo compiler is configured for target: $targetMachine
1120				exit 1 ;;
1121		esac
1122
1123		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
1124		isPrimaryArch=
1125	done
1126fi
1127
1128# Generate BuildConfig
1129cat << EOF > "$buildConfigFile"
1130# -- WARNING --
1131# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1132# overwritten the next time configure is run.
1133#
1134#d ${currentDir}
1135#c ${configurePath}
1136#e ${configureEnvirons}
1137#a ${configureArgs}
1138
1139GIT_DIR						?= "${GIT_DIR}" ;
1140
1141HOST_PLATFORM				?= "${HOST_PLATFORM}" ;
1142TARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
1143HAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
1144
1145HAIKU_NO_DOWNLOADS			?= "${HAIKU_NO_DOWNLOADS}" ;
1146HAIKU_INCLUDE_SOURCES		?= "${HAIKU_INCLUDE_SOURCES}" ;
1147HAIKU_INCLUDE_3RDPARTY		?= "${HAIKU_INCLUDE_3RDPARTY}" ;
1148HAIKU_DISTRO_COMPATIBILITY	?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
1149
1150HAIKU_USE_GCC_PIPE			?= "${HAIKU_USE_GCC_PIPE}" ;
1151HAIKU_HOST_USE_32BIT		?= "${HAIKU_HOST_USE_32BIT}" ;
1152HAIKU_HOST_USE_XATTR		?= "${HAIKU_HOST_USE_XATTR}" ;
1153HAIKU_HOST_USE_XATTR_REF	?= "${HAIKU_HOST_USE_XATTR_REF}" ;
1154HAIKU_HOST_BUILD_ONLY		?= "${HAIKU_HOST_BUILD_ONLY}" ;
1155
1156JAMSHELL					?= ${JAMSHELL} -e -c ;
1157
1158HOST_CC						?= ${CC} ;
1159HOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
1160HOST_LD						?= ${HOST_GCC_LD} ;
1161HOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
1162HOST_EXTENDED_REGEX_SED		?= ${HOST_EXTENDED_REGEX_SED} ;
1163HOST_SHA256					?= ${HOST_SHA256} ;
1164HOST_PYTHON					?= ${HOST_PYTHON} ;
1165HOST_WGET_RETRY_ON_HOST_ERROR			?= ${HOST_WGET_RETRY_ON_HOST_ERROR} ;
1166HAIKU_NASM					?= ${HAIKU_NASM} ;
1167
1168HAIKU_BUILD_ATTRIBUTES_DIR	?= "${HAIKU_BUILD_ATTRIBUTES_DIR}" ;
1169
1170HOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
1171HAIKU_PORTS					?= ${HAIKU_PORTS} ;
1172HAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
1173HAIKU_IS_BOOTSTRAP			?= ${HAIKU_IS_BOOTSTRAP} ;
1174
1175HAIKU_BOOT_EFI_PRIVATE_KEYFILE	?= ${HAIKU_EFI_SIGNING_KEY} ;
1176EOF
1177
1178for targetArch in $HAIKU_PACKAGING_ARCHS; do
1179	variables="
1180		HAIKU_CC					HAIKU_CC
1181		HAIKU_CC_IS_LEGACY_GCC		HAIKU_CC_IS_LEGACY_GCC
1182		HAIKU_CC_IS_CLANG			HAIKU_CC_IS_CLANG
1183		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
1184		HAIKU_CPU					HAIKU_CPU
1185		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
1186		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
1187		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
1188		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
1189		HAIKU_BOOT_32_LIBGCC		HAIKU_BOOT_32_LIBGCC
1190		HAIKU_BOOT_32_LIBSUPC++		HAIKU_BOOT_32_LIBSUPCXX
1191		HAIKU_AR					HAIKU_AR
1192		HAIKU_LD					HAIKU_LD
1193		HAIKU_OBJCOPY				HAIKU_OBJCOPY
1194		HAIKU_RANLIB				HAIKU_RANLIB
1195		HAIKU_ELFEDIT				HAIKU_ELFEDIT
1196		HAIKU_STRIP					HAIKU_STRIP
1197		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
1198		HAIKU_CCFLAGS				HAIKU_CCFLAGS
1199		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
1200		HAIKU_LINKFLAGS				HAIKU_LINKFLAGS
1201		HAIKU_LDFLAGS				HAIKU_LDFLAGS
1202		HAIKU_ARFLAGS				HAIKU_ARFLAGS
1203		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
1204		"
1205	set -- $variables
1206	while [ $# -ge 2 ]; do
1207		value=`get_variable ${2}_$targetArch`
1208		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1209		shift 2
1210	done
1211
1212	# For variables that may have long values, distribute them over multiple
1213	# lines so that jam doesn't hit the maximum line length.
1214	variables="
1215		HAIKU_BOOT_C++_HEADERS_DIR	HAIKU_BOOT_CXX_HEADERS_DIR
1216		HAIKU_BOOT_32_C++_HEADERS_DIR	HAIKU_BOOT_32_CXX_HEADERS_DIR
1217		"
1218	set -- $variables
1219	while [ $# -ge 2 ]; do
1220		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1221		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
1222			>> "$buildConfigFile"
1223		echo "    ;" >> "$buildConfigFile"
1224		shift 2
1225	done
1226done
1227
1228
1229# Generate a Jamfile in the output directory.
1230
1231cat << EOF > $outputDir/Jamfile
1232# -- WARNING --
1233# This file was AUTOMATICALLY GENERATED by configure, and will be completely
1234# overwritten the next time configure is run.
1235
1236HAIKU_TOP			= $(relative_to "${sourceDir}" "${outputDir}") ;
1237HAIKU_OUTPUT_DIR	= . ;
1238
1239include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1240
1241EOF
1242
1243echo "Configured successfully!"
1244