xref: /haiku/configure (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
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  --bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo>
16                              Prepare for a bootstrap build. No pre-built
17                              packages will be used, instead they will be built
18                              from the sources (in several phases).
19                              <haikuporter> is the path to the haikuporter tool
20                              suitable for the host platform.
21                              <HaikuPorts cross repo> is the path to a checked
22                              out HaikuPorts cross-compilation repository.
23                              <HaikuPorts repo> is the path to a checked out
24                              HaikuPorts repository.
25  --build-cross-tools <arch> [ <build tools dir> ]
26                              Assume cross compilation. <build tools dir>
27                              defines the location of the build tools sources.
28                              They will be compiled and placed in the output
29                              directory under "cross-tools". The HAIKU_* tools
30                              variables will be set accordingly.
31                              <arch> specifies the target architecture, either
32                              "x86_gcc2", "x86", "x86_64", "ppc", "m68k", "arm",
33                              or "mipsel".
34                              This option and --cross-tools-prefix can be
35                              specified multiple times. The first cross tools
36                              specify the primary tools, the subsequent ones the
37                              secondary tools (for "hybrid" images).
38                              For the first --build-cross-tools the
39                              <build tools dir> argument must be specified and
40                              for the subsequent ones it must be omitted.
41  --cross-tools-prefix <prefix>
42                              Assume cross compilation. <prefix> should be a
43                              path to the directory where the cross
44                              compilation tools are located, plus the platform
45                              prefix, e.g. "/path/to/tools/i586-pc-haiku-".
46                              This overrides the HAIKU_* tool variables.
47  --distro-compatibility <level>
48                              The distribution's level of compatibility with
49                              the official Haiku distribution. The generated
50                              files will contain the respective trademarks
51                              accordingly.
52                              official -- the official Haiku distribution.
53                              compatible -- a Haiku Compatible (tm) distro.
54                              default -- any other distro (default value).
55  --enable-multiuser          Enable experimental multiuser support.
56  --help                      Prints out this help.
57  --host-only                 Configure for building tools for the build host
58                              only. Haiku cannot be built when configured like
59                              this.
60  --include-gpl-addons        Include GPL licensed add-ons.
61  --include-patented-code     Enable code that is known to implemented patented
62                              ideas and techniques. If this option is not
63                              specified, the resulting distribution may still
64                              implement patented ideas and techniques. This
65                              option only disables code that is currently known
66                              to be problematic.
67  --include-sources           Includes the source code of projects that require
68                              either an offer of source code or a copy of the
69                              patched sources. This is preferable when
70                              distributing on physical mediums.
71  --include-3rdparty          Include 3rdparty/ in the build system.
72  -j<n>                       Only relevant for --build-cross-tools and
73                              --build-cross-tools-gcc4. Is passed on to the
74                              make building the build tools.
75  --target=TARGET             Select build target platform.
76                              [default=${TARGET_PLATFORM}]
77                              valid targets=r5,bone,dano,haiku
78  --update                    re-runs last configure invocation [must be given
79                              as first option!]
80  --use-gcc-pipe              Build with GCC option -pipe. Speeds up the build
81                              process, but uses more memory.
82  --use-gcc-graphite          Build with GCC Graphite engine for loop
83                              optimizations. Only for gcc 4.
84  --use-32bit                 Use -m32 flag on 64bit host gcc compiler.
85  --use-xattr                 Use Linux xattr respectively *BSD extattr support
86                              for BeOS attribute emulation. Warning: Make sure
87                              your file system supports sufficient attribute
88                              sizes (4 KB per file for all attributes won't
89                              suffice).
90  --use-xattr-ref             Use the generic BeOS attribute emulation, but use
91                              Linux xattr respectively *BSD extattr support to
92                              make it more robust (i.e. attribute mix-ups become
93                              less likely).
94
95environment variables:
96  HAIKU_AR_x86_gcc2           The static library archiver for x86_gcc2.
97                              Defaults to "ar".
98  HAIKU_CC_x86_gcc2           The x86_gcc2 compiler. Defaults to "gcc".
99  HAIKU_LD_x86_gcc2           The x86_gcc2 linker. Defaults to "ld".
100  HAIKU_OBJCOPY_x86_gcc2      The x86_gcc2 objcopy to be used. Defaults to
101                              "objcopy".
102  HAIKU_RANLIB_x86_gcc2       The static library indexer for x86_gcc2. Defaults
103                              to "ranlib".
104  HAIKU_STRIP_x86_gcc2        The x86_gcc2 strip command. Defaults to "strip".
105  HAIKU_YASM                  The yasm assembler (x86 only).
106  HAIKU_CPPFLAGS_<arch>       The preprocessor flags for target architecture
107                              <arch>. Defaults to "".
108  HAIKU_CCFLAGS_<arch>        The C flags for target architecture <arch>.
109                              Defaults to "".
110  HAIKU_CXXFLAGS_<arch>       The C++ flags for target architecture <arch>.
111                              Defaults to "".
112  HAIKU_LDFLAGS_<arch>        The linker flags for target architecture <arch>.
113                              Defaults to "".
114  HAIKU_ARFLAGS_<arch>        The flags passed to HAIKU_AR for target
115                              architecture <arch> for archiving. Defaults to
116                              "cru".
117  HAIKU_UNARFLAGS_<arch>      The flags passed to HAIKU_AR for target
118                              architecture <arch> for unarchiving. Defaults to
119                              "x".
120
121Non-default output directories:
122  By default all objects, build configuration, and other related files are
123  stored in /path/to/haiku_source/generated.  To store objects in a non-default
124  location, run "../../relative/path/to/haiku_source/configure <options>" from
125  within your non-default location.  "jam [ options ] targets" can then be run
126  directly inside your non-default location.  Another option is to invoke "jam
127  [ options ] targets" from within haiku_source.  This can be accomplished by
128  either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
129  jam or by creating a symlink of haiku_source/generated pointing to your
130  non-default location and running jam.
131
132
133EOF
134}
135
136# assertparam
137#
138# Checks whether at least one parameter is left.
139#
140assertparam()
141{
142	if [ $2 -lt 2 ]; then
143		echo $0: \`$1\': Parameter expected.
144		exit 1
145	fi
146}
147
148# assertparams
149#
150# Checks whether at least a certain number of parameters is left.
151#
152assertparams()
153{
154	if [ $3 -le $2 ]; then
155		echo $0: \`$1\': Not enough parameters.
156		exit 1
157	fi
158}
159
160# absolute_path
161#
162# returns the absolute path of a given path.
163#
164absolute_path()
165{
166	if [[ "$1" == /* ]]; then
167		echo "$1"
168	else
169		echo "`pwd`/$1"
170	fi
171}
172
173# real_path
174#
175# returns the realpath of a symbolic link.
176#
177real_path()
178{
179	perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
180}
181
182# standard_gcc_settings
183#
184# Sets the variables for a GCC platform.
185#
186standard_gcc_settings()
187{
188	local gcc=$1
189
190	if which greadlink > /dev/null 2>&1; then
191		readlink="greadlink -e"
192	elif which realpath > /dev/null 2>&1; then
193		readlink=realpath
194	elif readlink -e / > /dev/null 2>&1; then
195		readlink="readlink -e"
196	else
197		readlink=real_path
198	fi
199
200	# PLATFORM_LINKLIBS
201	local gcclib=`$gcc -print-libgcc-file-name`
202	local gccdir=`dirname ${gcclib}`
203
204	local gccRawVersion=`$gcc -dumpversion`
205	local gccMachine=`$gcc -dumpmachine`
206
207	local libgcc=${gccdir}/libgcc.a
208
209	# determine architecture from machine triple
210	case $gccMachine in
211		arm-*)		targetCpu=arm;;
212		i?86-*)		targetCpu=x86;;
213		m68k-*)		targetCpu=m68k;;
214		mipsel-*)	targetCpu=mipsel;;
215		powerpc-*)	targetCpu=ppc;;
216		x86_64-*)	targetCpu=x86_64;;
217		*)
218			echo "Unsupported gcc target machine: $gccMachine" >&2
219			exit 1
220			;;
221	esac
222
223	local targetArch=$targetCpu
224	local staticLibStdCxx
225	local sharedLibStdCxx
226	local staticLibSupCxx
227	local sharedLibSupCxx
228	local kernelLibgcc
229	local cxxHeaders
230
231	case $gccRawVersion in
232		4.*)
233			# for gcc 4 we use the libstdc++ and libsupc++ that come with the
234			# compiler
235			staticLibStdCxx=`$gcc -print-file-name=libstdc++.a`
236			sharedLibStdCxx=`$gcc -print-file-name=libstdc++.so`
237			staticLibSupCxx=`$gcc -print-file-name=libsupc++.a`
238			sharedLibSupCxx=`$gcc -print-file-name=libsupc++.so`
239
240			# If the architecture has separate runtime libraries for the
241			# kernel, use them.
242			kernelLibgcc=`$gcc -print-file-name=libgcc-kernel.a`
243			if [ $kernelLibgcc = libgcc-kernel.a ]; then
244				kernelLibgcc=$libgcc
245			fi
246			kernelLibSupCxx=`$gcc -print-file-name=libsupc++-kernel.a`
247			if [ $kernelLibSupCxx = libsupc++-kernel.a ]; then
248				kernelLibSupCxx=$staticLibSupCxx
249			fi
250
251			local headersBase=$gccdir/../../../..
252			local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
253			if [ ! -d $headers ]; then
254				headers=$headersBase/include/c++/$gccRawVersion
255			fi
256
257			cxxHeaders=$headers
258			for d in $gccMachine backward ext; do
259				# Note: We need the line break, otherwise the line might become
260				# too long for jam (512 bytes max).
261				cxxHeaders="$cxxHeaders $headers/$d"
262			done
263
264			# Unset the HAIKU_{SHARED,STATIC}_LIB{STD,SUP}CXX variables, if the
265			# compiler didn't give us actual file names. Otherwise resolve
266			# symlinks to avoid problems when copying the libraries to the
267			# image.
268
269			if [ $staticLibStdCxx = libstdc++.a ]; then
270				staticLibStdCxx=
271			else
272				staticLibStdCxx=`$readlink $staticLibStdCxx`
273			fi
274
275			if [ $sharedLibStdCxx = libstdc++.so ]; then
276				sharedLibStdCxx=
277			else
278				sharedLibStdCxx=`$readlink $sharedLibStdCxx`
279			fi
280
281			if [ $staticLibSupCxx = libsupc++.a ]; then
282				staticLibSupCxx=
283			else
284				staticLibSupCxx=`$readlink $staticLibSupCxx`
285			fi
286
287			if [ $sharedLibSupCxx = libsupc++.so ]; then
288				sharedLibSupCxx=
289			else
290				sharedLibSupCxx=`$readlink $sharedLibSupCxx`
291			fi
292			;;
293		2.9*)
294			# check for correct (most up-to-date) legacy compiler and complain
295			# if an older one is installed
296			if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
297				echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
298				echo "Please download it from www.haiku-os.org...";
299				exit 1;
300			fi
301
302			kernelLibgcc=$libgcc
303			kernelLibSupCxx=
304			targetArch=x86_gcc2
305			;;
306	esac
307
308	local bootLibgcc
309	local bootLibSupCxx
310	case $gccMachine in
311		x86_64-*)
312			# Boot loader is 32-bit, need the 32-bit libs.
313			bootLibgcc=`$gcc -m32 -print-libgcc-file-name`
314			bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
315			;;
316		*)
317			bootLibgcc=$libgcc
318			bootLibSupCxx=$staticLibSupCxx
319			;;
320	esac
321
322	# determine whether graphite loop optimization should/can be used
323	local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
324	if [ -z "$useGraphite" ]; then
325		useGraphite=$useGccGraphiteDefault
326	fi
327
328	if [ "$useGraphite" != 0 ]; then
329		UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
330		if [ $? != 0 ]; then
331			echo "GCC Graphite loop optimizations cannot be used on $targetArch"
332			useGraphite=0
333		fi
334	fi
335
336	set_variable HAIKU_CPU_$targetArch $targetCpu
337
338	get_build_tool_path CC_$targetArch "$gcc"
339	set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
340	set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
341	set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
342	set_variable HAIKU_GCC_LIBGCC_$targetArch $libgcc
343	set_variable HAIKU_GCC_GLUE_CODE_$targetArch "crtbegin.o crtend.o"
344	set_variable HAIKU_GCC_HEADERS_DIR_$targetArch \
345		"${gccdir}/include ${gccdir}/include-fixed"
346	set_variable HAIKU_STATIC_LIBSTDCXX_$targetArch "$staticLibStdCxx"
347	set_variable HAIKU_SHARED_LIBSTDCXX_$targetArch "$sharedLibStdCxx"
348	set_variable HAIKU_STATIC_LIBSUPCXX_$targetArch "$staticLibSupCxx"
349	set_variable HAIKU_SHARED_LIBSUPCXX_$targetArch "$sharedLibSupCxx"
350	set_variable HAIKU_KERNEL_LIBSUPCXX_$targetArch "$kernelLibSupCxx"
351	set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
352	set_variable HAIKU_KERNEL_LIBGCC_$targetArch $kernelLibgcc
353	set_variable HAIKU_CXX_HEADERS_DIR_$targetArch "$cxxHeaders"
354	set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
355	set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
356
357	standard_gcc_settings_targetArch=$targetArch
358}
359
360# set_variable
361#
362# Set the value of a variable.
363#
364set_variable()
365{
366	eval "$1=\"$2\""
367}
368
369# get_variable
370#
371# Echo the value of a variable.
372#
373get_variable()
374{
375	eval "echo \${$1}"
376}
377
378# set_default_value
379#
380# Set the value for a variable, if no value is set yet.
381#
382set_default_value()
383{
384	eval "$1=\${$1-$2}"
385}
386
387# get_build_tool_path
388#
389# Gets a usable absolute path of a build tool.
390#
391get_build_tool_path()
392{
393	local var="HAIKU_$1"
394	local path=$2
395
396	if [ -f "$path" ]; then
397		# get absolute path
398		local oldPwd="`pwd`"
399		cd "`dirname "$path"`"
400		path="`pwd`/`basename "$path"`"
401		cd $oldPwd
402	else
403		which "$path" > /dev/null 2>&1 || {
404			echo "Build tool \"$path\" not found." >&2
405			exit 1
406		}
407	fi
408
409	eval "$var=$path"
410}
411
412# get cwd and the source directory
413currentDir=`pwd`
414cd `dirname "$0"`
415sourceDir=`pwd`
416cd "$currentDir"
417
418# backup the passed arguments
419configureArgs="$@"
420
421# internal default parameter values
422#
423platform=`uname`
424platformMachine=`uname  -m`
425targetArchs=
426buildCrossTools=
427buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
428buildCrossToolsJobs=
429useGccGraphiteDefault=0
430unknownArchIndex=1
431
432# exported (BuildSetup) default parameter values
433#
434HOST_GCC_RAW_VERSION=`gcc -dumpversion`
435HOST_GCC_MACHINE=`gcc -dumpmachine`
436HAIKU_INCLUDE_GPL_ADDONS=0
437HAIKU_INCLUDE_PATENTED_CODE=0
438HAIKU_INCLUDE_SOURCES=0
439HAIKU_INCLUDE_3RDPARTY=0
440HAIKU_ENABLE_MULTIUSER=0
441HAIKU_DISTRO_COMPATIBILITY=default
442TARGET_PLATFORM=haiku
443HAIKU_USE_GCC_PIPE=0
444HAIKU_HOST_USE_32BIT=0
445HAIKU_HOST_USE_XATTR=0
446HAIKU_HOST_USE_XATTR_REF=0
447HAIKU_HOST_BUILD_ONLY=0
448HOST_GCC_LD=`gcc -print-prog-name=ld`
449HOST_GCC_OBJCOPY=`gcc -print-prog-name=objcopy`
450SFDISK_BINARY=sfdisk
451HOST_SFDISK=$SFDISK_BINARY
452HOST_SHA256=
453HOST_HAIKU_PORTER=
454HAIKU_PORTS=
455HAIKU_PORTS_CROSS=
456
457HAIKU_PACKAGING_ARCHS=
458
459set_default_value HAIKU_YASM		yasm
460
461if sha256sum < /dev/null > /dev/null 2>&1; then
462	HOST_SHA256=sha256sum
463elif sha256 < /dev/null > /dev/null 2>&1; then
464	HOST_SHA256="sha256 -q"
465else
466	echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
467	exit 1
468fi
469
470haikuRequiredLegacyGCCVersion="2.95.3-haiku-2013_07_15"
471export haikuRequiredLegacyGCCVersion
472	# version of legacy gcc required to build haiku
473
474# determine output directory
475if [ "$currentDir" = "$sourceDir" ]; then
476	outputDir=$currentDir/generated
477else
478	outputDir=$currentDir
479fi
480buildOutputDir="$outputDir/build"
481HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
482buildConfigFile="$buildOutputDir/BuildConfig"
483
484# check for update request
485if [ "$1" = "--update" ]; then
486	if ! [ -e "$buildConfigFile" ]; then
487		echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
488		exit 1
489	fi
490	if ! type perl >/dev/null 2>&1; then
491		echo $0 --update: \'perl\' not found - updating not possible.
492		exit 1
493	fi
494	# convert BuildConfig from jam format to shell format and evaluate it
495	shellConfigFile="${buildConfigFile}.shell"
496	perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \
497		<"$buildConfigFile" >"$shellConfigFile"
498	. "$shellConfigFile"
499	rm "$shellConfigFile"
500	shift
501fi
502
503# parse parameters
504#
505while [ $# -gt 0 ] ; do
506	case "$1" in
507		--bootstrap)
508			assertparams "$1" 3 $#
509			HOST_HAIKU_PORTER="`absolute_path $2`"
510			HAIKU_PORTS_CROSS="`absolute_path $3`"
511			HAIKU_PORTS="`absolute_path $4`"
512			shift 4
513			;;
514		--build-cross-tools)
515			if [ -z "$buildCrossTools" ]; then
516				assertparams "$1" 2 $#
517				targetArch=$2
518				buildCrossTools=$3
519				shift 3
520			else
521				assertparam "$1" $#
522				targetArch=$2
523				shift 2
524			fi
525			case "$targetArch" in
526				x86_gcc2)	targetMachine=i586-pc-haiku;;
527				x86)		targetMachine=i586-pc-haiku;;
528				x86_64)		targetMachine=x86_64-unknown-haiku;;
529				ppc)		targetMachine=powerpc-apple-haiku;;
530				m68k)		targetMachine=m68k-unknown-haiku;;
531				arm)		targetMachine=arm-unknown-haiku;;
532				mipsel)		targetMachine=mipsel-unknown-haiku;;
533				*)
534					echo "Unsupported target architecture: $2" >&2
535					exit 1
536					;;
537			esac
538			set_variable buildCrossToolsMachine_$targetArch $targetMachine
539			targetArchs="$targetArchs $targetArch"
540			HAIKU_PACKAGING_ARCHS=
541			;;
542		--cross-tools-prefix)
543			assertparam "$1" $#
544			targetArch=unknown${unknownArchIndex}
545			set_variable crossToolsPrefix_$targetArch "$2"
546			targetArchs="$targetArchs $targetArch"
547			HAIKU_PACKAGING_ARCHS=
548			unknownArchIndex=$[$unknownArchIndex + 1]
549			shift 2
550			;;
551		--distro-compatibility)
552			assertparam "$1" $#
553			HAIKU_DISTRO_COMPATIBILITY=$2
554			case "$HAIKU_DISTRO_COMPATIBILITY" in
555				official)	;;
556				compatible)	;;
557				default)	;;
558				*)			echo "Invalid distro compatibility" \
559								"level: $HAIKU_DISTRO_COMPATIBILITY"
560							exit 1;;
561			esac
562			shift 2
563			;;
564		--enable-multiuser)	HAIKU_ENABLE_MULTIUSER=1; shift 1;;
565		--help | -h)	usage; exit 0;;
566		--host-only)	HAIKU_HOST_BUILD_ONLY=1; shift 1;;
567		--include-gpl-addons)	HAIKU_INCLUDE_GPL_ADDONS=1; shift 1;;
568		--include-patented-code)	HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
569		--include-sources)	HAIKU_INCLUDE_SOURCES=1; shift 1;;
570		--include-3rdparty)	HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
571        -j*)				buildCrossToolsJobs="$1"; shift 1;;
572		--target=*)     TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
573		--use-gcc-pipe)	HAIKU_USE_GCC_PIPE=1; shift 1;;
574		--use-gcc-graphite)	useGccGraphiteDefault=1; shift 1;;
575		--use-32bit)	HAIKU_HOST_USE_32BIT=1; shift 1;;
576		--use-xattr)	HAIKU_HOST_USE_XATTR=1; shift 1;;
577		--use-xattr-ref)	HAIKU_HOST_USE_XATTR_REF=1; shift 1;;
578		*)				echo Invalid argument: \`$1\'; exit 1;;
579	esac
580done
581
582# detect the build platform
583case "${platform}" in
584	Darwin)	HOST_PLATFORM=darwin ;;
585	FreeBSD)	HOST_PLATFORM=freebsd
586				SFDISK_BINARY=sfdisk-linux
587				if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
588					echo Unsupported platform: FreeBSD ${platformMachine}
589					exit 1
590				fi	;;
591	Haiku)	HOST_PLATFORM=haiku_host ;;
592	Linux)	HOST_PLATFORM=linux ;;
593	OpenBSD) HOST_PLATFORM=openbsd ;;
594	SunOS)	HOST_PLATFORM=sunos ;;
595	CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
596	*)		echo Unsupported platform: ${platform}
597			exit 1 ;;
598esac
599
600# check common locations for sfdisk
601for sfdiskDir in /sbin /usr/sbin /usr/local/sbin ; do
602	if [ -e ${sfdiskDir}/${SFDISK_BINARY} ]; then
603		HOST_SFDISK=${sfdiskDir}/${SFDISK_BINARY}
604	fi
605done
606
607# check for case-sensitive filesystem
608mkdir haikuCaseTest 2>/dev/null
609mkdir haikucasetest 2>/dev/null
610caseInsensitive=$?
611rmdir haikuCaseTest haikucasetest 2>/dev/null
612if [ $caseInsensitive != 0 ]; then
613	echo "You need a case-sensitive file-system to build Haiku."
614	if [ $HOST_PLATFORM = "darwin" ]; then
615		echo "You can create a case-sensitive disk image using Disk Utility and use"
616		echo "it to store the Haiku sources on."
617	fi
618	exit 1
619fi
620
621# create output directory
622mkdir -p "$buildOutputDir" || exit 1
623
624if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
625	invalidCommand=$sourceDir/build/scripts/host_build_only
626	HAIKU_AR=$invalidCommand
627	HAIKU_CC=$invalidCommand
628	HAIKU_LD=$invalidCommand
629	HAIKU_OBJCOPY=$invalidCommand
630	HAIKU_RANLIB=$invalidCommand
631	HAIKU_ELFEDIT=$invalidCommand
632	HAIKU_YASM=$invalidCommand
633	HAIKU_STRIP=$invalidCommand
634else
635	if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
636		targetArchs="$HAIKU_PACKAGING_ARCHS"
637	fi
638	HAIKU_PACKAGING_ARCHS=
639
640	if [ -z "$targetArchs" ]; then
641		targetArch=x86_gcc2
642		targetArchs=$targetArch
643		set_default_value HAIKU_AR_$targetArch			ar
644		set_default_value HAIKU_CC_$targetArch			gcc
645		set_default_value HAIKU_LD_$targetArch			ld
646		set_default_value HAIKU_OBJCOPY_$targetArch		objcopy
647		set_default_value HAIKU_RANLIB_$targetArch		ranlib
648		set_default_value HAIKU_ELFEDIT_$targetArch		elfedit
649		set_default_value HAIKU_STRIP_$targetArch		strip
650	fi
651
652	isPrimaryArch=1
653	for targetArch in $targetArchs; do
654		# Note: targetArch is "unknown<n>" at this point, if a cross-tools
655		# prefix was specified. The standard_gcc_settings call below will get
656		# the actual architecture.
657
658		crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
659
660		# build cross tools from sources
661		if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
662			crossToolsDir="$outputDir/cross-tools-$targetArch"
663			targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
664			script="$buildCrossToolsScript"
665			if [ $targetArch != x86_gcc2 ]; then
666				script="${script}_gcc4 $targetMachine"
667			fi
668			secondaryArch=
669			if [ -z "$isPrimaryArch" ]; then
670				secondaryArch=$targetArch
671			fi
672			SECONDARY_ARCH=$secondaryArch \
673			HAIKU_USE_GCC_GRAPHITE=`get_variable \
674				HAIKU_USE_GCC_GRAPHITE_$targetArch` \
675			$script "$sourceDir" "$buildCrossTools" "$crossToolsDir" \
676				$buildCrossToolsJobs || exit 1
677			crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
678		fi
679
680		# prepare gcc settings and get the actual target architecture
681		gcc="${crossToolsPrefix}gcc"
682		if [ -z "${crossToolsPrefix}" ]; then
683			gcc=`get_variable HAIKU_CC_$targetArch`
684		fi
685		standard_gcc_settings "$gcc"
686		targetArch=$standard_gcc_settings_targetArch
687
688		# set default values for flags
689		set_default_value HAIKU_CPPFLAGS_$targetArch	""
690		set_default_value HAIKU_CCFLAGS_$targetArch		""
691		set_default_value HAIKU_CXXFLAGS_$targetArch	""
692		set_default_value HAIKU_LDFLAGS_$targetArch		""
693		set_default_value HAIKU_ARFLAGS_$targetArch		cru
694		set_default_value HAIKU_UNARFLAGS_$targetArch	x
695
696		# Override the cross tools variables, if the tools were built or a
697		# prefix was specified.
698		if [ -n "$crossToolsPrefix" ]; then
699			get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
700			get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
701			get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
702			get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
703			get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
704
705			case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
706				4.*)
707					get_build_tool_path ELFEDIT_$targetArch \
708						${crossToolsPrefix}elfedit
709				;;
710			esac
711		fi
712
713		# Get the libgcc objects. We couldn't do that in standard_gcc_settings,
714		# since we need "ar", which may be set later.
715		ar=`get_variable HAIKU_AR_$targetArch`
716		libgcc=`get_variable HAIKU_GCC_LIBGCC_$targetArch`
717		set_variable HAIKU_GCC_LIBGCC_OBJECTS_$targetArch \
718			"`$ar t $libgcc | grep -v eabi.o`"
719			# Note: We filter out eabi.o. It's present in gcc's libgcc for PPC
720			# and neither needed nor wanted.
721
722		# check whether the Haiku compiler really targets Haiku
723		targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
724		case "$targetMachine" in
725			*-*-haiku)	;;
726			*)
727				echo The compiler specified as Haiku target compiler is not a \
728				valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
729				echo compiler: $HAIKU_CC
730				echo compiler is configured for target: $targetMachine
731				exit 1 ;;
732		esac
733
734		HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
735		isPrimaryArch=
736	done
737fi
738
739# Generate BuildConfig
740cat << EOF > "$buildConfigFile"
741# BuildConfig
742# Note: This file has been automatically generated by configure with the
743# following arguments:
744# ${configureArgs}
745
746TARGET_PLATFORM 			?= "${TARGET_PLATFORM}" ;
747HOST_PLATFORM				?= "${HOST_PLATFORM}" ;
748
749HAIKU_INCLUDE_GPL_ADDONS			?= "${HAIKU_INCLUDE_GPL_ADDONS}" ;
750HAIKU_INCLUDE_PATENTED_CODE			?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
751HAIKU_INCLUDE_SOURCES				?= "${HAIKU_INCLUDE_SOURCES}" ;
752HAIKU_INCLUDE_3RDPARTY				?= "${HAIKU_INCLUDE_3RDPARTY}" ;
753HAIKU_ENABLE_MULTIUSER				?= "${HAIKU_ENABLE_MULTIUSER}" ;
754HAIKU_DISTRO_COMPATIBILITY			?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
755HAIKU_USE_GCC_PIPE					?= "${HAIKU_USE_GCC_PIPE}" ;
756HAIKU_HOST_USE_32BIT				?= "${HAIKU_HOST_USE_32BIT}" ;
757HAIKU_HOST_USE_XATTR				?= "${HAIKU_HOST_USE_XATTR}" ;
758HAIKU_HOST_USE_XATTR_REF			?= "${HAIKU_HOST_USE_XATTR_REF}" ;
759HAIKU_HOST_BUILD_ONLY				?= "${HAIKU_HOST_BUILD_ONLY}" ;
760
761HAIKU_PACKAGING_ARCHS		?= ${HAIKU_PACKAGING_ARCHS} ;
762
763HAIKU_BUILD_ATTRIBUTES_DIR	?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
764
765HAIKU_YASM					?= ${HAIKU_YASM} ;
766
767HOST_GCC_RAW_VERSION		?= ${HOST_GCC_RAW_VERSION} ;
768HOST_GCC_MACHINE			?= ${HOST_GCC_MACHINE} ;
769HOST_LD						?= ${HOST_GCC_LD} ;
770HOST_OBJCOPY				?= ${HOST_GCC_OBJCOPY} ;
771HOST_SFDISK					?= ${HOST_SFDISK} ;
772HOST_SHA256					?= ${HOST_SHA256} ;
773
774HOST_HAIKU_PORTER			?= ${HOST_HAIKU_PORTER} ;
775HAIKU_PORTS					?= ${HAIKU_PORTS} ;
776HAIKU_PORTS_CROSS			?= ${HAIKU_PORTS_CROSS} ;
777
778EOF
779
780for targetArch in $HAIKU_PACKAGING_ARCHS; do
781	variables="
782		HAIKU_GCC_RAW_VERSION		HAIKU_GCC_RAW_VERSION
783		HAIKU_GCC_MACHINE			HAIKU_GCC_MACHINE
784		HAIKU_GCC_LIB_DIR			HAIKU_GCC_LIB_DIR
785		HAIKU_GCC_LIBGCC			HAIKU_GCC_LIBGCC
786		HAIKU_CPU					HAIKU_CPU
787		HAIKU_STATIC_LIBSTDC++		HAIKU_STATIC_LIBSTDCXX
788		HAIKU_SHARED_LIBSTDC++		HAIKU_SHARED_LIBSTDCXX
789		HAIKU_STATIC_LIBSUPC++		HAIKU_STATIC_LIBSUPCXX
790		HAIKU_SHARED_LIBSUPC++		HAIKU_SHARED_LIBSUPCXX
791		HAIKU_KERNEL_LIBGCC			HAIKU_KERNEL_LIBGCC
792		HAIKU_KERNEL_LIBSUPC++		HAIKU_KERNEL_LIBSUPCXX
793		HAIKU_BOOT_LIBGCC			HAIKU_BOOT_LIBGCC
794		HAIKU_BOOT_LIBSUPC++		HAIKU_BOOT_LIBSUPCXX
795		HAIKU_AR					HAIKU_AR
796		HAIKU_CC					HAIKU_CC
797		HAIKU_LD					HAIKU_LD
798		HAIKU_OBJCOPY				HAIKU_OBJCOPY
799		HAIKU_RANLIB				HAIKU_RANLIB
800		HAIKU_ELFEDIT				HAIKU_ELFEDIT
801		HAIKU_STRIP					HAIKU_STRIP
802		HAIKU_CPPFLAGS				HAIKU_CPPFLAGS
803		HAIKU_CCFLAGS				HAIKU_CCFLAGS
804		HAIKU_C++FLAGS				HAIKU_CXXFLAGS
805		HAIKU_LDFLAGS				HAIKU_LDFLAGS
806		HAIKU_ARFLAGS				HAIKU_ARFLAGS
807		HAIKU_UNARFLAGS				HAIKU_UNARFLAGS
808		HAIKU_USE_GCC_GRAPHITE		HAIKU_USE_GCC_GRAPHITE
809		"
810	set -- $variables
811	while [ $# -ge 2 ]; do
812		value=`get_variable ${2}_$targetArch`
813		echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
814		shift 2
815	done
816
817	# For variables that may have long values, distribute them over multiple
818	# lines so that jam doesn't hit the maximum line length.
819	variables="
820		HAIKU_GCC_HEADERS_DIR		HAIKU_GCC_HEADERS_DIR
821		HAIKU_C++_HEADERS_DIR		HAIKU_CXX_HEADERS_DIR
822		HAIKU_GCC_LIBGCC_OBJECTS	HAIKU_GCC_LIBGCC_OBJECTS
823		"
824	set -- $variables
825	while [ $# -ge 2 ]; do
826		echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
827		get_variable ${2}_$targetArch | xargs -n 1 echo "   " \
828			>> "$buildConfigFile"
829		echo "    ;" >> "$buildConfigFile"
830		shift 2
831	done
832done
833
834
835# Generate a boot strap Jamfile in the output directory.
836
837cat << EOF > $outputDir/Jamfile
838# automatically generated Jamfile
839
840HAIKU_TOP			= ${sourceDir} ;
841HAIKU_OUTPUT_DIR	= ${outputDir} ;
842
843include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
844
845EOF
846