btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / configure
blob922665c76d189bb46c85d83f2eaa60f0e73b99d6
1 #!/bin/sh
3 # configure [ <options> ]
5 # usage
7 # Prints usage.
9 usage()
11 cat << EOF
13 Usage: $0 <options>
14 options:
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> [ <build tools dir> ]
29 Assume cross compilation. <build tools dir>
30 defines the location of the build tools sources.
31 They will be compiled and placed in the output
32 directory under "cross-tools". The HAIKU_* tools
33 variables will be set accordingly.
34 <arch> specifies the target architecture, either
35 "x86_gcc2", "x86", "x86_64", "ppc", "m68k", "arm"
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 For the first --build-cross-tools the
41 <build tools dir> argument must be specified and
42 for the subsequent ones it must be omitted.
43 --cross-tools-prefix <prefix>
44 Assume cross compilation. <prefix> should be a
45 path to the directory where the cross
46 compilation tools are located, plus the platform
47 prefix, e.g. "/path/to/tools/i586-pc-haiku-".
48 This overrides the HAIKU_* tool variables.
49 --distro-compatibility <level>
50 The distribution's level of compatibility with
51 the official Haiku distribution. The generated
52 files will contain the respective trademarks
53 accordingly.
54 official -- the official Haiku distribution.
55 compatible -- a Haiku Compatible (tm) distro.
56 default -- any other distro (default value).
57 --host-only Configure for building tools for the build host
58 only. Haiku cannot be built when configured like
59 this.
60 --include-patented-code Enable code that is known to implemented patented
61 ideas and techniques. If this option is not
62 specified, the resulting distribution may still
63 implement patented ideas and techniques. This
64 option only enables code that is currently known
65 to be problematic.
66 --include-sources Includes the source code of projects that require
67 either an offer of source code or a copy of the
68 patched sources. This is preferable when
69 distributing on physical mediums.
70 --include-3rdparty Include 3rdparty/ in the build system.
71 -j<n> Only relevant for --build-cross-tools. Is passed
72 on to the make building the build tools.
73 --no-downloads Do not download anything. Useful when trying to
74 bootstrap and build Haiku from source only.
75 --target=TARGET Select build target platform.
76 [default=${TARGET_PLATFORM}]
77 valid targets=r5,bone,dano,haiku
78 --target-arch <arch> Haiku only: Specify the target architecture to
79 build for. Must be one of the architectures of the
80 host system. The installed build tools for that
81 architecture will be used.
82 This option can be specified multiple times. The
83 first occurrence specifies the primary
84 architecture of the Haiku to build, subsequent
85 ones the secondary architectures.
86 --use-clang <arch> Build with host Clang instead of GCC cross
87 compiler, targeting <arch>
88 --use-gcc-pipe Build with GCC option -pipe. Speeds up the build
89 process, but uses more memory.
90 --use-gcc-graphite Build with GCC Graphite engine for loop
91 optimizations. (Only for GCC 4+.)
92 --use-32bit Use -m32 flag on 64bit host gcc compiler.
93 --no-full-xattr Do not use Linux/*BSD/Darwin's native extended file
94 attributes as Haiku attributes. If they are still
95 available, they will be used to store hashes for
96 the attribute emulation layer.
97 --no-xattr Do not use Linux/*BSD/Darwin's native extended file
98 attributes for Haiku extended attributes at all,
99 even if they are available.
100 --with-gdb <gdb sources dir>
101 specify the path to a GDB source dir, to build
102 GDB for each arch we build the cross-tools for.
104 environment variables:
105 CC The host compiler. Defaults to "gcc".
106 HAIKU_AR_<arch> The static library archiver for <arch>.
107 Defaults to "ar".
108 HAIKU_CC_<arch> The compiler for <arch>. Defaults to "gcc".
109 HAIKU_LD_<arch> The <arch> linker. Defaults to "ld".
110 HAIKU_OBJCOPY_<arch> The <arch> objcopy to be used. Defaults to
111 "objcopy".
112 HAIKU_RANLIB_<arch> The static library indexer for <arch>. Defaults
113 to "ranlib".
114 HAIKU_STRIP_<arch> The <arch> strip command. Defaults to "strip".
115 HAIKU_NASM The nasm assembler (x86 and x86_64 only).
116 HAIKU_CPPFLAGS_<arch> The preprocessor flags for target architecture
117 <arch>. Defaults to "".
118 HAIKU_CCFLAGS_<arch> The C flags for target architecture <arch>.
119 Defaults to "".
120 HAIKU_CXXFLAGS_<arch> The C++ flags for target architecture <arch>.
121 Defaults to "".
122 HAIKU_LDFLAGS_<arch> The linker flags for target architecture <arch>.
123 Defaults to "".
124 HAIKU_ARFLAGS_<arch> The flags passed to HAIKU_AR for target
125 architecture <arch> for archiving. Defaults to
126 "cru".
127 HAIKU_UNARFLAGS_<arch> The flags passed to HAIKU_AR for target
128 architecture <arch> for unarchiving. Defaults to
129 "x".
131 Non-default output directories:
132 By default all objects, build configuration, and other related files are
133 stored in /path/to/haiku_source/generated. To store objects in a non-default
134 location, run "../../relative/path/to/haiku_source/configure <options>" from
135 within your non-default location. "jam [ options ] targets" can then be run
136 directly inside your non-default location. Another option is to invoke "jam
137 [ options ] targets" from within haiku_source. This can be accomplished by
138 either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
139 jam or by creating a symlink of haiku_source/generated pointing to your
140 non-default location and running jam.
146 # assertparam
148 # Checks whether at least one parameter is left.
150 assertparam()
152 if [ $2 -lt 2 ]; then
153 echo $0: \`$1\': Parameter expected.
154 exit 1
158 # assertparams
160 # Checks whether at least a certain number of parameters is left.
162 assertparams()
164 if [ $3 -le $2 ]; then
165 echo $0: \`$1\': Not enough parameters.
166 exit 1
170 # absolute_path
172 # returns the absolute path of a given path.
174 absolute_path()
176 if [ "x$1" != "x${1#/}" ]; then
177 echo "$1"
178 else
179 echo "`pwd`/$1"
183 # check_dir_exists
185 # check if a directory exists or not
187 check_dir_exists()
189 if [ -d "$1" ]; then
190 return 0
191 else
192 return 1
196 # check_file_exists
198 # check if a file exists or not
200 check_file_exists()
202 if [ -f "$1" ]; then
203 return 0
204 else
205 return 1
209 # real_path
211 # returns the realpath of a symbolic link.
213 real_path()
215 perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
218 # standard_gcc_settings
220 # Sets the variables for a GCC platform.
222 standard_gcc_settings()
224 local gcc="$1"
226 if which greadlink > /dev/null 2>&1; then
227 readlink="greadlink -e"
228 elif which realpath > /dev/null 2>&1; then
229 readlink=realpath
230 elif readlink -e / > /dev/null 2>&1; then
231 readlink="readlink -e"
232 else
233 readlink=real_path
236 # PLATFORM_LINKLIBS
237 local gcclib=`$gcc -print-libgcc-file-name`
238 local gccdir=`dirname ${gcclib}`
240 local gccRawVersion=`$gcc -dumpversion`
241 local gccMachine=`$gcc -dumpmachine`
243 # determine architecture from machine triple
244 case $gccMachine in
245 arm-*) targetCpu=arm;;
246 i?86-*) targetCpu=x86;;
247 m68k-*) targetCpu=m68k;;
248 powerpc-*) targetCpu=ppc;;
249 x86_64-*) targetCpu=x86_64;;
251 echo "Unsupported gcc target machine: $gccMachine" >&2
252 exit 1
254 esac
256 local targetArch=$targetCpu
258 case $gccRawVersion in
259 2.9*)
260 # check for correct (most up-to-date) legacy compiler and complain
261 # if an older one is installed
262 if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
263 echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
264 echo "Please download it from www.haiku-os.org...";
265 exit 1;
268 targetArch=x86_gcc2
270 esac
272 local bootLibgcc
273 local bootLibSupCxx
274 local bootCxxHeaders
275 case $gccMachine in
276 x86_64-*)
277 # Boot loader is 32-bit, need the 32-bit libs and c++ config
278 bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a`
279 bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
281 local headersBase=$gccdir/../../../..
282 local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
283 if [ ! -d $headers ]; then
284 headers=$headersBase/include/c++/$gccRawVersion
286 bootCxxHeaders="$headers/$gccMachine/32"
288 esac
290 # determine whether graphite loop optimization should/can be used
291 local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
292 if [ -z "$useGraphite" ]; then
293 useGraphite=$useGccGraphiteDefault
296 if [ "$useGraphite" != 0 ]; then
297 UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
298 if [ $? != 0 ]; then
299 echo "GCC Graphite loop optimizations cannot be used on $targetArch"
300 useGraphite=0
304 set_variable HAIKU_CPU_$targetArch $targetCpu
306 get_build_tool_path CC_$targetArch "$gcc"
307 set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
308 set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
309 set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
310 set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
311 set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
312 set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
313 set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
314 set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
316 standard_gcc_settings_targetArch=$targetArch
319 # set_variable
321 # Set the value of a variable.
323 set_variable()
325 eval "$1=\"$2\""
328 # get_variable
330 # Echo the value of a variable.
332 get_variable()
334 eval "echo \${$1}"
337 # set_default_value
339 # Set the value for a variable, if no value is set yet.
341 set_default_value()
343 eval "$1=\${$1-$2}"
346 # get_build_tool_path
348 # Gets a usable absolute path of a build tool.
350 get_build_tool_path()
352 local var="HAIKU_$1"
353 local varval="`get_variable $var`"
354 local cmd="$2"
356 if [ ! -z "$varval" ]; then
357 # this variable is already set (probably by user) so grab its contents
358 cmd=$varval
361 local path=${cmd%% *}
363 if [ -f "$path" ]; then
364 # get absolute path from relative path
365 local oldPwd="`pwd`"
366 cd "`dirname "$path"`"
367 path="`pwd`/`basename "$path"`"
368 cd $oldPwd
369 else
370 which "$path" > /dev/null 2>&1 || {
371 echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
372 exit 1
376 if test "${cmd#* }" != "$cmd"; then
377 # $cmd contains arguments, so preserve them (and only them)
378 cmd=${cmd#* }
379 else
380 # $cmd does not contain arguments, so unset it
381 cmd=
383 eval "$var=\"$path $cmd\""
386 # check_native_xattrs
388 # Checks the host platform's support for extended attributes.
389 # 0: no support, 1: only enough for xattr-ref, 2: full support
391 check_native_xattrs()
393 local xattr_set=
394 local xattr_set_args=
395 local xattr_get=
396 local xattr_get_args=
397 case $HOST_PLATFORM in
398 darwin)
399 xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
400 xattr_get="xattr"; xattr_get_args="-p \$NAME"
402 freebsd)
403 xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
404 xattr_get="getextattr"; xattr_get_args="user \$NAME"
406 linux)
407 xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
408 xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
411 return 0
413 esac
414 if ! type $xattr_set >/dev/null 2>&1; then
415 echo "$0: could not find $xattr_set, assuming host has no extended attributes"
416 return 0
417 elif ! type $xattr_get >/dev/null 2>&1; then
418 echo "$0: could not find $xattr_get, assuming host has no extended attributes"
419 return 0
422 echo "xattr test file" >"$outputDir/xattrtest"
423 local i=0
424 # on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
425 # on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
426 while [ $i -lt 2 ]; do
427 local j=0
428 while [ $j -lt 3 ]; do
429 NAME=attr$j
430 VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
431 if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
432 echo "$0: warning: could not generate test data for extended attributes"
433 rm "$outputDir/xattrtest"
434 return $i
435 elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
436 "$outputDir/xattrtest" >/dev/null 2>&1 ; then
437 rm "$outputDir/xattrtest"
438 return $i
440 j=$((j+1))
441 done
442 i=$((i+1))
443 done
444 rm "$outputDir/xattrtest"
445 return 2
448 is_in_list()
450 local element
451 for element in $2; do
452 if [ "$1" = "$element" ]; then
453 return 0
455 done
456 return 1
459 # check for --help or -h and show usage immediately
460 if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
461 usage; exit 0;
464 # ensure umask is not too restrictive
465 if [ $(umask) -gt 22 ]; then
466 echo "Your umask is too restrictive (should be: <= 0022; is actually:" $(umask)")"
467 exit 1
470 # get cwd and the source directory
471 currentDir=`pwd`
472 cd `dirname "$0"`
473 sourceDir=`pwd`
474 cd "$currentDir"
476 # backup the passed arguments
477 configureArgs="$@"
478 configurePath=$0
480 # backup relevant environs
481 configureEnvirons=
482 for var in `env`; do
483 case "$var" in
484 CC\=*|HAIKU*\=*)
485 configureEnvirons="$configureEnvirons $var"
487 esac
488 done
490 # internal default parameter values
492 platform=`uname`
493 platformMachine=`uname -m`
494 targetArchs=
495 buildCrossTools=
496 buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
497 buildCrossToolsJobs=
498 useClang=0
499 useGccGraphiteDefault=0
500 unknownArchIndex=1
501 haikuTargetArchs=
502 gdbSources=
504 if [ -z "$CC" ]; then
505 CC=gcc
508 # exported (BuildSetup) default parameter values
510 HOST_GCC_RAW_VERSION=`$CC -dumpversion`
511 HOST_GCC_MACHINE=`$CC -dumpmachine`
512 HAIKU_INCLUDE_PATENTED_CODE=0
513 HAIKU_INCLUDE_SOURCES=0
514 HAIKU_INCLUDE_3RDPARTY=0
515 HAIKU_DISTRO_COMPATIBILITY=default
516 TARGET_PLATFORM=haiku
517 HAIKU_USE_GCC_PIPE=0
518 HAIKU_HOST_USE_32BIT=0
519 HAIKU_HOST_USE_XATTR=
520 HAIKU_HOST_USE_XATTR_REF=
521 HAIKU_HOST_BUILD_ONLY=0
522 HOST_EXTENDED_REGEX_SED="sed -r"
523 HOST_GCC_LD=`$CC -print-prog-name=ld`
524 HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
525 HOST_SHA256=
526 HOST_HAIKU_PORTER=
527 HAIKU_PORTS=
528 HAIKU_PORTS_CROSS=
529 HAIKU_IS_BOOTSTRAP=0
530 HAIKU_BOOT_BOARD=
531 HAIKU_NO_DOWNLOADS=0
533 HAIKU_PACKAGING_ARCHS=
535 set_default_value HAIKU_NASM nasm
537 if sha256sum < /dev/null > /dev/null 2>&1; then
538 HOST_SHA256=sha256sum
539 elif sha256 < /dev/null > /dev/null 2>&1; then
540 HOST_SHA256="sha256 -q"
541 elif shasum < /dev/null > /dev/null 2>&1; then
542 HOST_SHA256="shasum -a 256"
543 else
544 echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
545 exit 1
548 haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
549 export haikuRequiredLegacyGCCVersion
550 # version of legacy gcc required to build haiku
551 supportedTargetArchs="
553 m68k
556 x86_64
557 x86_gcc2
560 # determine output directory
561 if [ "$currentDir" = "$sourceDir" ]; then
562 outputDir=$currentDir/generated
563 else
564 outputDir=$currentDir
566 buildOutputDir="$outputDir/build"
567 HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
568 buildConfigFile="$buildOutputDir/BuildConfig"
570 # check for update request
571 if [ "$1" = "--update" ]; then
572 if ! [ -e "$buildConfigFile" ]; then
573 echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
574 exit 1
576 # get last configure invocation and flags from BuildConfig and call ourselves with it
577 lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
578 lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
579 lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
580 lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
581 if [ -z "$lastConfig" ]; then
582 echo "$0 --update: The previous configure invocation was not properly" \
583 "encoded into '$buildConfigFile' - updating not possible."
584 exit 1
586 cd $lastPwd
587 if [ -n "$lastEnv" ]; then
588 export $lastEnv
590 $lastConfig $lastArgs
591 exit $?
594 # parse parameters
596 while [ $# -gt 0 ] ; do
597 case "$1" in
598 --bootstrap)
599 assertparams "$1" 3 $#
600 HOST_HAIKU_PORTER="`absolute_path $2`"
601 HAIKU_PORTS_CROSS="`absolute_path $3`"
602 HAIKU_PORTS="`absolute_path $4`"
603 HAIKU_IS_BOOTSTRAP=1
604 HAIKU_NO_DOWNLOADS=1
605 check_file_exists "$HOST_HAIKU_PORTER" || (
606 echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
607 exit 1
609 check_dir_exists "$HAIKU_PORTS" || (
610 echo "Non-existent directory $HAIKU_PORTS" >&2
611 exit 1
613 check_dir_exists "$HAIKU_PORTS_CROSS" || (
614 echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
615 exit 1
617 shift 4
619 --build-cross-tools)
620 if [ -z "$buildCrossTools" ]; then
621 assertparams "$1" 2 $#
622 targetArch=$2
623 buildCrossTools=$3
624 shift 3
625 else
626 assertparam "$1" $#
627 targetArch=$2
628 shift 2
630 case "$targetArch" in
631 x86_gcc2) targetMachine=i586-pc-haiku;;
632 x86) targetMachine=i586-pc-haiku;;
633 x86_64) targetMachine=x86_64-unknown-haiku;;
634 ppc) targetMachine=powerpc-apple-haiku;;
635 m68k) targetMachine=m68k-unknown-haiku;;
636 arm) targetMachine=arm-unknown-haiku;;
638 echo "Unsupported target architecture: $2" >&2
639 exit 1
641 esac
642 set_variable buildCrossToolsMachine_$targetArch $targetMachine
643 targetArchs="$targetArchs $targetArch"
644 HAIKU_PACKAGING_ARCHS=
646 --cross-tools-prefix)
647 assertparam "$1" $#
648 targetArch=unknown${unknownArchIndex}
649 set_variable crossToolsPrefix_$targetArch "$2"
650 targetArchs="$targetArchs $targetArch"
651 HAIKU_PACKAGING_ARCHS=
652 unknownArchIndex=$(($unknownArchIndex + 1))
653 shift 2
655 --distro-compatibility)
656 assertparam "$1" $#
657 HAIKU_DISTRO_COMPATIBILITY=$2
658 case "$HAIKU_DISTRO_COMPATIBILITY" in
659 official) ;;
660 compatible) ;;
661 default) ;;
662 *) echo "Invalid distro compatibility" \
663 "level: $HAIKU_DISTRO_COMPATIBILITY"
664 exit 1;;
665 esac
666 shift 2
668 --host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;;
669 --include-patented-code) HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
670 --include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;;
671 --include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
672 -j*) buildCrossToolsJobs="$1"; shift 1;;
673 --no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;;
674 --target=*) TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
675 --target-arch)
676 assertparam "$1" $#
677 targetArch=$2
678 shift 2
679 if [ ! "$platform" = Haiku ]; then
680 echo "--target-arch can only be specified on Haiku." >&2
681 exit 1
683 is_in_list "$targetArch" "$supportedTargetArchs" || (
684 echo "Unsupported target architecture: \"$targetArch\"" >&2
685 exit 1
687 haikuTargetArchs="$haikuTargetArchs $targetArch"
689 --use-clang)
690 assertparam "$1" $#
691 targetArch=$2
692 useClang=1
693 case "$targetArch" in
694 x86) targetMachine=i586-pc-haiku;;
695 x86_64) targetMachine=x86_64-unknown-haiku;;
697 echo "Unsupported target architecture: $2" >&2
698 exit 1
700 esac
701 get_build_tool_path clang clang
702 if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
703 && [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
704 set_variable crossToolsPrefix_$targetArch llvm-
706 if ! test "${targetArchs#*$targetArch}" != "$targetArchs"; then
707 # we have not already added this arch to targetArchs, so add it now
708 targetArchs="$targetArchs $targetArch"
710 HAIKU_PACKAGING_ARCHS=
711 shift 2
713 --use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;;
714 --use-gcc-graphite) useGccGraphiteDefault=1; shift 1;;
715 --use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;;
716 --no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
717 --no-xattr) HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
718 --with-gdb) gdbSources=$2; shift 2;;
719 *) echo Invalid argument: \`$1\'; exit 1;;
720 esac
721 done
723 # detect the build platform
724 case "${platform}" in
725 Darwin) HOST_PLATFORM=darwin ;;
726 FreeBSD) HOST_PLATFORM=freebsd
727 if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
728 echo Unsupported platform: FreeBSD ${platformMachine}
729 exit 1
730 fi ;;
731 Haiku) HOST_PLATFORM=haiku_host ;;
732 Linux) HOST_PLATFORM=linux ;;
733 OpenBSD) HOST_PLATFORM=openbsd ;;
734 SunOS) HOST_PLATFORM=sunos ;;
735 CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
736 *) echo Unsupported platform: ${platform}
737 exit 1 ;;
738 esac
740 # check for case-sensitive filesystem
741 mkdir haikuCaseTest 2>/dev/null
742 mkdir haikucasetest 2>/dev/null
743 caseInsensitive=$?
744 rmdir haikuCaseTest haikucasetest 2>/dev/null
745 if [ $caseInsensitive != 0 ]; then
746 echo "You need a case-sensitive file-system to build Haiku."
747 if [ $HOST_PLATFORM = "darwin" ]; then
748 echo "You can create a case-sensitive disk image using Disk Utility."
750 exit 1
753 # check xattr support
754 if [ $HOST_PLATFORM != "haiku_host" ] && [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
755 check_native_xattrs
756 attrSupport=$?
757 if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
758 HAIKU_HOST_USE_XATTR=1
759 elif [ $attrSupport = 1 ]; then
760 HAIKU_HOST_USE_XATTR_REF=1
763 if [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
764 if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
766 # determine how to invoke sed with extended regexp support for non-GNU sed
767 if [ $HOST_PLATFORM = "darwin" ]; then
768 HOST_EXTENDED_REGEX_SED="sed -E"
771 # check if nasm can actually output ELF files
772 # (the stock version in OSX can't)
773 # XXX: should probably only test for x86* arch
774 if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
775 echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
776 if [ $HOST_PLATFORM = "darwin" ]; then
777 echo "You can install it from Mac Ports."
778 echo "Mac Ports is available at: http://www.macports.org/"
780 exit 1
783 # create output directory
784 mkdir -p "$buildOutputDir" || exit 1
786 if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
787 invalidCommand=$sourceDir/build/scripts/host_build_only
788 HAIKU_AR=$invalidCommand
789 HAIKU_CC=$invalidCommand
790 HAIKU_LD=$invalidCommand
791 HAIKU_OBJCOPY=$invalidCommand
792 HAIKU_RANLIB=$invalidCommand
793 HAIKU_ELFEDIT=$invalidCommand
794 HAIKU_NASM=$invalidCommand
795 HAIKU_STRIP=$invalidCommand
796 else
797 if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
798 targetArchs="$HAIKU_PACKAGING_ARCHS"
800 HAIKU_PACKAGING_ARCHS=
802 # On Haiku determine target architectures and tools automatically.
803 if [ -z "$targetArchs" ]; then
804 if [ $HOST_PLATFORM != haiku_host ]; then
805 echo "Please specify the build tools to use or build (via" \
806 "--cross-tools-prefix or --build-cross-tools) or specify a" \
807 "host-only build (--host-only)." >&2
808 echo "For more info, invoke $0 --help"
809 exit 1
812 # determine primary architecture
813 targetArch=`package list -i /system/packages/haiku-*.hpkg \
814 | sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
815 is_in_list "$targetArch" "$supportedTargetArchs" || (
816 echo "Unsupported target architecture: \"$targetArch\"" >&2
817 exit 1
819 targetArchs=$targetArch
821 set_default_value HAIKU_AR_$targetArch ar
822 set_default_value HAIKU_CC_$targetArch gcc
823 set_default_value HAIKU_LD_$targetArch ld
824 set_default_value HAIKU_OBJCOPY_$targetArch objcopy
825 set_default_value HAIKU_RANLIB_$targetArch ranlib
826 set_default_value HAIKU_ELFEDIT_$targetArch elfedit
827 set_default_value HAIKU_STRIP_$targetArch strip
829 # determine secondary architectures
830 for targetArch in $supportedTargetArchs; do
831 if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
832 targetArchs="$targetArchs $targetArch"
833 set_default_value HAIKU_AR_$targetArch ar-$targetArch
834 set_default_value HAIKU_CC_$targetArch gcc-$targetArch
835 set_default_value HAIKU_LD_$targetArch ld-$targetArch
836 set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch
837 set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch
838 set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch
839 set_default_value HAIKU_STRIP_$targetArch strip-$targetArch
841 done
843 # The target architectures might have been specified explicitly.
844 if [ -n "$haikuTargetArchs" ]; then
845 for targetArch in $haikuTargetArchs; do
846 is_in_list "$targetArch" "$targetArchs" || (
847 echo "Unsupported target architecture: \"$targetArch\"." \
848 "Only native architectures of the host platform can" \
849 "be specified." >&2
850 exit 1
852 done
853 targetArchs="$haikuTargetArchs"
857 isPrimaryArch=1
858 for targetArch in $targetArchs; do
859 # Note: targetArch is "unknown<n>" at this point, if a cross-tools
860 # prefix was specified. The standard_gcc_settings call below will get
861 # the actual architecture.
863 crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
865 # build cross tools from sources
866 if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
867 crossToolsDir="$outputDir/cross-tools-$targetArch"
868 targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
869 script="$buildCrossToolsScript"
870 scriptArgs=
871 if [ $targetArch != x86_gcc2 ]; then
872 script="${script}_gcc4"
873 scriptArgs="$targetMachine"
874 set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \
875 $useGccGraphiteDefault
877 secondaryArch=
878 if [ -z "$isPrimaryArch" ]; then
879 secondaryArch=$targetArch
882 case $HOST_PLATFORM in
883 freebsd|openbsd) MAKE=gmake;;
884 *) MAKE=make;;
885 esac
887 if [ ! -d "$crossToolsDir" ]; then
888 MAKE=$MAKE \
889 SECONDARY_ARCH=$secondaryArch \
890 HAIKU_USE_GCC_GRAPHITE=`get_variable \
891 HAIKU_USE_GCC_GRAPHITE_$targetArch` \
892 HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
893 HAIKU_USE_GDB="$gdbSources" \
894 "$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
895 "$crossToolsDir" $buildCrossToolsJobs || exit 1
896 else
897 echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
899 crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
902 # prepare gcc settings and get the actual target architecture
903 if [ $useClang = 1 ]; then
904 gcc="$HAIKU_clang -target ${targetMachine} -no-integrated-as"
906 # Clang's compiler intrinsics are not compatible with GCC's or even
907 # across versions of Clang, so we must collect them for use in the build.
908 mkdir -p "$outputDir/clang_headers" || exit 1
909 clangHeadersDir=`$gcc -print-resource-dir`/include/
910 cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1
911 elif [ -z "${crossToolsPrefix}" ]; then
912 gcc=`get_variable HAIKU_CC_$targetArch`
913 else
914 gcc="${crossToolsPrefix}gcc"
916 standard_gcc_settings "$gcc"
917 targetArch=$standard_gcc_settings_targetArch
919 # set default values for flags
920 set_default_value HAIKU_CPPFLAGS_$targetArch ""
921 set_default_value HAIKU_CCFLAGS_$targetArch ""
922 set_default_value HAIKU_CXXFLAGS_$targetArch ""
923 set_default_value HAIKU_LDFLAGS_$targetArch ""
924 set_default_value HAIKU_ARFLAGS_$targetArch cru
925 set_default_value HAIKU_UNARFLAGS_$targetArch x
927 # Override the cross tools variables, if the tools were built or a
928 # prefix was specified.
929 if [ -n "$crossToolsPrefix" ]; then
930 get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
931 get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
932 get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
933 get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
934 get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
936 case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
937 4.*|5.*|6.*|7.*|8.*)
938 get_build_tool_path ELFEDIT_$targetArch \
939 ${crossToolsPrefix}elfedit
941 esac
944 # check whether the Haiku compiler really targets Haiku
945 targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
946 case "$targetMachine" in
947 *-*-haiku) ;;
949 echo The compiler specified as Haiku target compiler is not a \
950 valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
951 echo compiler: $HAIKU_CC
952 echo compiler is configured for target: $targetMachine
953 exit 1 ;;
954 esac
956 HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
957 isPrimaryArch=
958 done
961 # Generate BuildConfig
962 cat << EOF > "$buildConfigFile"
963 # -- WARNING --
964 # This file was AUTOMATICALLY GENERATED by configure, and will be completely
965 # overwritten the next time configure is run.
967 #d ${currentDir}
968 #c ${configurePath}
969 #e ${configureEnvirons}
970 #a ${configureArgs}
972 TARGET_PLATFORM ?= "${TARGET_PLATFORM}" ;
973 HOST_PLATFORM ?= "${HOST_PLATFORM}" ;
975 HAIKU_INCLUDE_PATENTED_CODE ?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
976 HAIKU_INCLUDE_SOURCES ?= "${HAIKU_INCLUDE_SOURCES}" ;
977 HAIKU_INCLUDE_3RDPARTY ?= "${HAIKU_INCLUDE_3RDPARTY}" ;
978 HAIKU_DISTRO_COMPATIBILITY ?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
979 HAIKU_USE_GCC_PIPE ?= "${HAIKU_USE_GCC_PIPE}" ;
980 HAIKU_HOST_USE_32BIT ?= "${HAIKU_HOST_USE_32BIT}" ;
981 HAIKU_HOST_USE_XATTR ?= "${HAIKU_HOST_USE_XATTR}" ;
982 HAIKU_HOST_USE_XATTR_REF ?= "${HAIKU_HOST_USE_XATTR_REF}" ;
983 HAIKU_HOST_BUILD_ONLY ?= "${HAIKU_HOST_BUILD_ONLY}" ;
985 HAIKU_PACKAGING_ARCHS ?= ${HAIKU_PACKAGING_ARCHS} ;
987 HAIKU_NO_DOWNLOADS ?= "${HAIKU_NO_DOWNLOADS}" ;
989 HAIKU_BUILD_ATTRIBUTES_DIR ?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
991 HAIKU_NASM ?= ${HAIKU_NASM} ;
992 HAIKU_BOOT_BOARD ?= ${HAIKU_BOOT_BOARD} ;
994 HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ;
995 HOST_GCC_RAW_VERSION ?= ${HOST_GCC_RAW_VERSION} ;
996 HOST_GCC_MACHINE ?= ${HOST_GCC_MACHINE} ;
997 HOST_LD ?= ${HOST_GCC_LD} ;
998 HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ;
999 HOST_SHA256 ?= ${HOST_SHA256} ;
1001 HOST_HAIKU_PORTER ?= ${HOST_HAIKU_PORTER} ;
1002 HAIKU_PORTS ?= ${HAIKU_PORTS} ;
1003 HAIKU_PORTS_CROSS ?= ${HAIKU_PORTS_CROSS} ;
1004 HAIKU_IS_BOOTSTRAP ?= ${HAIKU_IS_BOOTSTRAP} ;
1008 for targetArch in $HAIKU_PACKAGING_ARCHS; do
1009 variables="
1010 HAIKU_GCC_RAW_VERSION HAIKU_GCC_RAW_VERSION
1011 HAIKU_GCC_MACHINE HAIKU_GCC_MACHINE
1012 HAIKU_GCC_LIB_DIR HAIKU_GCC_LIB_DIR
1013 HAIKU_CPU HAIKU_CPU
1014 HAIKU_BOOT_LIBGCC HAIKU_BOOT_LIBGCC
1015 HAIKU_BOOT_LIBSUPC++ HAIKU_BOOT_LIBSUPCXX
1016 HAIKU_AR HAIKU_AR
1017 HAIKU_CC HAIKU_CC
1018 HAIKU_CC_IS_CLANG HAIKU_CC_IS_CLANG
1019 HAIKU_LD HAIKU_LD
1020 HAIKU_OBJCOPY HAIKU_OBJCOPY
1021 HAIKU_RANLIB HAIKU_RANLIB
1022 HAIKU_ELFEDIT HAIKU_ELFEDIT
1023 HAIKU_STRIP HAIKU_STRIP
1024 HAIKU_CPPFLAGS HAIKU_CPPFLAGS
1025 HAIKU_CCFLAGS HAIKU_CCFLAGS
1026 HAIKU_C++FLAGS HAIKU_CXXFLAGS
1027 HAIKU_LDFLAGS HAIKU_LDFLAGS
1028 HAIKU_ARFLAGS HAIKU_ARFLAGS
1029 HAIKU_UNARFLAGS HAIKU_UNARFLAGS
1030 HAIKU_USE_GCC_GRAPHITE HAIKU_USE_GCC_GRAPHITE
1032 set -- $variables
1033 while [ $# -ge 2 ]; do
1034 value=`get_variable ${2}_$targetArch`
1035 echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1036 shift 2
1037 done
1039 # For variables that may have long values, distribute them over multiple
1040 # lines so that jam doesn't hit the maximum line length.
1041 variables="
1042 HAIKU_BOOT_C++_HEADERS_DIR HAIKU_BOOT_CXX_HEADERS_DIR
1044 set -- $variables
1045 while [ $# -ge 2 ]; do
1046 echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1047 get_variable ${2}_$targetArch | xargs -n 1 echo " " \
1048 >> "$buildConfigFile"
1049 echo " ;" >> "$buildConfigFile"
1050 shift 2
1051 done
1052 done
1055 # Generate a boot strap Jamfile in the output directory.
1057 cat << EOF > $outputDir/Jamfile
1058 # automatically generated Jamfile
1060 HAIKU_TOP = ${sourceDir} ;
1061 HAIKU_OUTPUT_DIR = ${outputDir} ;
1063 include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1067 echo "Configured successfully!"