docs/ikteam: Delete most files.
[haiku.git] / configure
blob80451268f70a62e58f8a8ae3c296efaeee7634f1
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 haiku_host)
399 xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
400 xattr_get="catattr"; xattr_get_args="\$NAME"
402 darwin)
403 xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
404 xattr_get="xattr"; xattr_get_args="-p \$NAME"
406 freebsd)
407 xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
408 xattr_get="getextattr"; xattr_get_args="user \$NAME"
410 linux)
411 xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
412 xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
415 return 0
417 esac
418 if ! type $xattr_set >/dev/null 2>&1; then
419 echo "$0: could not find $xattr_set, assuming host has no extended attributes"
420 return 0
421 elif ! type $xattr_get >/dev/null 2>&1; then
422 echo "$0: could not find $xattr_get, assuming host has no extended attributes"
423 return 0
426 echo "xattr test file" >"$outputDir/xattrtest"
427 local i=0
428 # on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
429 # on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
430 while [ $i -lt 2 ]; do
431 local j=0
432 while [ $j -lt 3 ]; do
433 NAME=attr$j
434 VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
435 if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
436 echo "$0: warning: could not generate test data for extended attributes"
437 rm "$outputDir/xattrtest"
438 return $i
439 elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
440 "$outputDir/xattrtest" >/dev/null 2>&1 ; then
441 rm "$outputDir/xattrtest"
442 return $i
444 j=$((j+1))
445 done
446 i=$((i+1))
447 done
448 rm "$outputDir/xattrtest"
449 return 2
452 is_in_list()
454 local element
455 for element in $2; do
456 if [ "$1" = "$element" ]; then
457 return 0
459 done
460 return 1
463 # check for --help or -h and show usage immediately
464 if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
465 usage; exit 0;
468 # ensure umask is not too restrictive
469 if [ $(umask) -gt 22 ]; then
470 echo "Your umask is too restrictive (should be: <= 0022; is actually:" $(umask)")"
471 exit 1
474 # get cwd and the source directory
475 currentDir=`pwd`
476 cd `dirname "$0"`
477 sourceDir=`pwd`
478 cd "$currentDir"
480 # backup the passed arguments
481 configureArgs="$@"
482 configurePath=$0
484 # backup relevant environs
485 configureEnvirons=
486 for var in `env`; do
487 case "$var" in
488 CC\=*|HAIKU*\=*)
489 configureEnvirons="$configureEnvirons $var"
491 esac
492 done
494 # internal default parameter values
496 platform=`uname`
497 platformMachine=`uname -m`
498 targetArchs=
499 buildCrossTools=
500 buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
501 buildCrossToolsJobs=
502 useClang=0
503 useGccGraphiteDefault=0
504 unknownArchIndex=1
505 haikuTargetArchs=
506 gdbSources=
508 if [ -z "$CC" ]; then
509 CC=gcc
512 # exported (BuildSetup) default parameter values
514 HOST_GCC_RAW_VERSION=`$CC -dumpversion`
515 HOST_GCC_MACHINE=`$CC -dumpmachine`
516 HAIKU_INCLUDE_PATENTED_CODE=0
517 HAIKU_INCLUDE_SOURCES=0
518 HAIKU_INCLUDE_3RDPARTY=0
519 HAIKU_DISTRO_COMPATIBILITY=default
520 TARGET_PLATFORM=haiku
521 HAIKU_USE_GCC_PIPE=0
522 HAIKU_HOST_USE_32BIT=0
523 HAIKU_HOST_USE_XATTR=
524 HAIKU_HOST_USE_XATTR_REF=
525 HAIKU_HOST_BUILD_ONLY=0
526 HOST_EXTENDED_REGEX_SED="sed -r"
527 HOST_GCC_LD=`$CC -print-prog-name=ld`
528 HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
529 HOST_SHA256=
530 HOST_HAIKU_PORTER=
531 HAIKU_PORTS=
532 HAIKU_PORTS_CROSS=
533 HAIKU_IS_BOOTSTRAP=0
534 HAIKU_BOOT_BOARD=
535 HAIKU_NO_DOWNLOADS=0
537 HAIKU_PACKAGING_ARCHS=
539 set_default_value HAIKU_NASM nasm
541 if sha256sum < /dev/null > /dev/null 2>&1; then
542 HOST_SHA256=sha256sum
543 elif sha256 < /dev/null > /dev/null 2>&1; then
544 HOST_SHA256="sha256 -q"
545 elif shasum < /dev/null > /dev/null 2>&1; then
546 HOST_SHA256="shasum -a 256"
547 else
548 echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
549 exit 1
552 haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
553 export haikuRequiredLegacyGCCVersion
554 # version of legacy gcc required to build haiku
555 supportedTargetArchs="
557 m68k
560 x86_64
561 x86_gcc2
564 # determine output directory
565 if [ "$currentDir" = "$sourceDir" ]; then
566 outputDir=$currentDir/generated
567 else
568 outputDir=$currentDir
570 buildOutputDir="$outputDir/build"
571 HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
572 buildConfigFile="$buildOutputDir/BuildConfig"
574 # check for update request
575 if [ "$1" = "--update" ]; then
576 if ! [ -e "$buildConfigFile" ]; then
577 echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
578 exit 1
580 # get last configure invocation and flags from BuildConfig and call ourselves with it
581 lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
582 lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
583 lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
584 lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
585 if [ -z "$lastConfig" ]; then
586 echo "$0 --update: The previous configure invocation was not properly" \
587 "encoded into '$buildConfigFile' - updating not possible."
588 exit 1
590 cd $lastPwd
591 if [ -n "$lastEnv" ]; then
592 export $lastEnv
594 $lastConfig $lastArgs
595 exit $?
598 # parse parameters
600 while [ $# -gt 0 ] ; do
601 case "$1" in
602 --bootstrap)
603 assertparams "$1" 3 $#
604 HOST_HAIKU_PORTER="`absolute_path $2`"
605 HAIKU_PORTS_CROSS="`absolute_path $3`"
606 HAIKU_PORTS="`absolute_path $4`"
607 HAIKU_IS_BOOTSTRAP=1
608 HAIKU_NO_DOWNLOADS=1
609 check_file_exists "$HOST_HAIKU_PORTER" || (
610 echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
611 exit 1
613 check_dir_exists "$HAIKU_PORTS" || (
614 echo "Non-existent directory $HAIKU_PORTS" >&2
615 exit 1
617 check_dir_exists "$HAIKU_PORTS_CROSS" || (
618 echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
619 exit 1
621 shift 4
623 --build-cross-tools)
624 if [ -z "$buildCrossTools" ]; then
625 assertparams "$1" 2 $#
626 targetArch=$2
627 buildCrossTools=$3
628 shift 3
629 else
630 assertparam "$1" $#
631 targetArch=$2
632 shift 2
634 case "$targetArch" in
635 x86_gcc2) targetMachine=i586-pc-haiku;;
636 x86) targetMachine=i586-pc-haiku;;
637 x86_64) targetMachine=x86_64-unknown-haiku;;
638 ppc) targetMachine=powerpc-apple-haiku;;
639 m68k) targetMachine=m68k-unknown-haiku;;
640 arm) targetMachine=arm-unknown-haiku;;
642 echo "Unsupported target architecture: $2" >&2
643 exit 1
645 esac
646 set_variable buildCrossToolsMachine_$targetArch $targetMachine
647 targetArchs="$targetArchs $targetArch"
648 HAIKU_PACKAGING_ARCHS=
650 --cross-tools-prefix)
651 assertparam "$1" $#
652 targetArch=unknown${unknownArchIndex}
653 set_variable crossToolsPrefix_$targetArch "$2"
654 targetArchs="$targetArchs $targetArch"
655 HAIKU_PACKAGING_ARCHS=
656 unknownArchIndex=$(($unknownArchIndex + 1))
657 shift 2
659 --distro-compatibility)
660 assertparam "$1" $#
661 HAIKU_DISTRO_COMPATIBILITY=$2
662 case "$HAIKU_DISTRO_COMPATIBILITY" in
663 official) ;;
664 compatible) ;;
665 default) ;;
666 *) echo "Invalid distro compatibility" \
667 "level: $HAIKU_DISTRO_COMPATIBILITY"
668 exit 1;;
669 esac
670 shift 2
672 --host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;;
673 --include-patented-code) HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
674 --include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;;
675 --include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
676 -j*) buildCrossToolsJobs="$1"; shift 1;;
677 --no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;;
678 --target=*) TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
679 --target-arch)
680 assertparam "$1" $#
681 targetArch=$2
682 shift 2
683 if [ ! "$platform" = Haiku ]; then
684 echo "--target-arch can only be specified on Haiku." >&2
685 exit 1
687 is_in_list "$targetArch" "$supportedTargetArchs" || (
688 echo "Unsupported target architecture: \"$targetArch\"" >&2
689 exit 1
691 haikuTargetArchs="$haikuTargetArchs $targetArch"
693 --use-clang)
694 assertparam "$1" $#
695 targetArch=$2
696 useClang=1
697 case "$targetArch" in
698 x86) targetMachine=i586-pc-haiku;;
699 x86_64) targetMachine=x86_64-unknown-haiku;;
701 echo "Unsupported target architecture: $2" >&2
702 exit 1
704 esac
705 get_build_tool_path clang clang
706 if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
707 && [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
708 set_variable crossToolsPrefix_$targetArch llvm-
710 if ! test "${targetArchs#*$targetArch}" != "$targetArchs"; then
711 # we have not already added this arch to targetArchs, so add it now
712 targetArchs="$targetArchs $targetArch"
714 HAIKU_PACKAGING_ARCHS=
715 shift 2
717 --use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;;
718 --use-gcc-graphite) useGccGraphiteDefault=1; shift 1;;
719 --use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;;
720 --no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
721 --no-xattr) HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
722 --with-gdb) gdbSources=$2; shift 2;;
723 *) echo Invalid argument: \`$1\'; exit 1;;
724 esac
725 done
727 # detect the build platform
728 case "${platform}" in
729 Darwin) HOST_PLATFORM=darwin ;;
730 FreeBSD) HOST_PLATFORM=freebsd
731 if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
732 echo Unsupported platform: FreeBSD ${platformMachine}
733 exit 1
734 fi ;;
735 Haiku) HOST_PLATFORM=haiku_host ;;
736 Linux) HOST_PLATFORM=linux ;;
737 OpenBSD) HOST_PLATFORM=openbsd ;;
738 SunOS) HOST_PLATFORM=sunos ;;
739 CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
740 *) echo Unsupported platform: ${platform}
741 exit 1 ;;
742 esac
744 # check for case-sensitive filesystem
745 mkdir haikuCaseTest 2>/dev/null
746 mkdir haikucasetest 2>/dev/null
747 caseInsensitive=$?
748 rmdir haikuCaseTest haikucasetest 2>/dev/null
749 if [ $caseInsensitive != 0 ]; then
750 echo "You need a case-sensitive file-system to build Haiku."
751 if [ $HOST_PLATFORM = "darwin" ]; then
752 echo "You can create a case-sensitive disk image using Disk Utility."
754 exit 1
757 # check xattr support
758 if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
759 check_native_xattrs
760 attrSupport=$?
761 if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
762 HAIKU_HOST_USE_XATTR=1
763 elif [ $attrSupport = 1 ]; then
764 HAIKU_HOST_USE_XATTR_REF=1
767 if [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
768 if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
770 # determine how to invoke sed with extended regexp support for non-GNU sed
771 if [ $HOST_PLATFORM = "darwin" ]; then
772 HOST_EXTENDED_REGEX_SED="sed -E"
775 # check if nasm can actually output ELF files
776 # (the stock version in OSX can't)
777 # XXX: should probably only test for x86* arch
778 if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
779 echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
780 if [ $HOST_PLATFORM = "darwin" ]; then
781 echo "You can install it from Mac Ports."
782 echo "Mac Ports is available at: http://www.macports.org/"
784 exit 1
787 # create output directory
788 mkdir -p "$buildOutputDir" || exit 1
790 if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
791 invalidCommand=$sourceDir/build/scripts/host_build_only
792 HAIKU_AR=$invalidCommand
793 HAIKU_CC=$invalidCommand
794 HAIKU_LD=$invalidCommand
795 HAIKU_OBJCOPY=$invalidCommand
796 HAIKU_RANLIB=$invalidCommand
797 HAIKU_ELFEDIT=$invalidCommand
798 HAIKU_NASM=$invalidCommand
799 HAIKU_STRIP=$invalidCommand
800 else
801 if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
802 targetArchs="$HAIKU_PACKAGING_ARCHS"
804 HAIKU_PACKAGING_ARCHS=
806 # On Haiku determine target architectures and tools automatically.
807 if [ -z "$targetArchs" ]; then
808 if [ $HOST_PLATFORM != haiku_host ]; then
809 echo "Please specify the build tools to use or build (via" \
810 "--cross-tools-prefix or --build-cross-tools) or specify a" \
811 "host-only build (--host-only)." >&2
812 echo "For more info, invoke $0 --help"
813 exit 1
816 # determine primary architecture
817 targetArch=`package list -i /system/packages/haiku-*.hpkg \
818 | sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
819 is_in_list "$targetArch" "$supportedTargetArchs" || (
820 echo "Unsupported target architecture: \"$targetArch\"" >&2
821 exit 1
823 targetArchs=$targetArch
825 set_default_value HAIKU_AR_$targetArch ar
826 set_default_value HAIKU_CC_$targetArch gcc
827 set_default_value HAIKU_LD_$targetArch ld
828 set_default_value HAIKU_OBJCOPY_$targetArch objcopy
829 set_default_value HAIKU_RANLIB_$targetArch ranlib
830 set_default_value HAIKU_ELFEDIT_$targetArch elfedit
831 set_default_value HAIKU_STRIP_$targetArch strip
833 # determine secondary architectures
834 for targetArch in $supportedTargetArchs; do
835 if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
836 targetArchs="$targetArchs $targetArch"
837 set_default_value HAIKU_AR_$targetArch ar-$targetArch
838 set_default_value HAIKU_CC_$targetArch gcc-$targetArch
839 set_default_value HAIKU_LD_$targetArch ld-$targetArch
840 set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch
841 set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch
842 set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch
843 set_default_value HAIKU_STRIP_$targetArch strip-$targetArch
845 done
847 # The target architectures might have been specified explicitly.
848 if [ -n "$haikuTargetArchs" ]; then
849 for targetArch in $haikuTargetArchs; do
850 is_in_list "$targetArch" "$targetArchs" || (
851 echo "Unsupported target architecture: \"$targetArch\"." \
852 "Only native architectures of the host platform can" \
853 "be specified." >&2
854 exit 1
856 done
857 targetArchs="$haikuTargetArchs"
861 isPrimaryArch=1
862 for targetArch in $targetArchs; do
863 # Note: targetArch is "unknown<n>" at this point, if a cross-tools
864 # prefix was specified. The standard_gcc_settings call below will get
865 # the actual architecture.
867 crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
869 # build cross tools from sources
870 if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
871 crossToolsDir="$outputDir/cross-tools-$targetArch"
872 targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
873 script="$buildCrossToolsScript"
874 scriptArgs=
875 if [ $targetArch != x86_gcc2 ]; then
876 script="${script}_gcc4"
877 scriptArgs="$targetMachine"
878 set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \
879 $useGccGraphiteDefault
881 secondaryArch=
882 if [ -z "$isPrimaryArch" ]; then
883 secondaryArch=$targetArch
886 case $HOST_PLATFORM in
887 freebsd|openbsd) MAKE=gmake;;
888 *) MAKE=make;;
889 esac
891 if [ ! -d "$crossToolsDir" ]; then
892 MAKE=$MAKE \
893 SECONDARY_ARCH=$secondaryArch \
894 HAIKU_USE_GCC_GRAPHITE=`get_variable \
895 HAIKU_USE_GCC_GRAPHITE_$targetArch` \
896 HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
897 HAIKU_USE_GDB="$gdbSources" \
898 "$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
899 "$crossToolsDir" $buildCrossToolsJobs || exit 1
900 else
901 echo "$targetArch crosstools already exist in $crossToolsDir; skipping build"
903 crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
906 # prepare gcc settings and get the actual target architecture
907 if [ $useClang = 1 ]; then
908 gcc="$HAIKU_clang -target ${targetMachine} -no-integrated-as"
910 # Clang's compiler intrinsics are not compatible with GCC's or even
911 # across versions of Clang, so we must collect them for use in the build.
912 mkdir -p "$outputDir/clang_headers" || exit 1
913 clangHeadersDir=`$gcc -print-resource-dir`/include/
914 cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1
915 elif [ -z "${crossToolsPrefix}" ]; then
916 gcc=`get_variable HAIKU_CC_$targetArch`
917 else
918 gcc="${crossToolsPrefix}gcc"
920 standard_gcc_settings "$gcc"
921 targetArch=$standard_gcc_settings_targetArch
923 # set default values for flags
924 set_default_value HAIKU_CPPFLAGS_$targetArch ""
925 set_default_value HAIKU_CCFLAGS_$targetArch ""
926 set_default_value HAIKU_CXXFLAGS_$targetArch ""
927 set_default_value HAIKU_LDFLAGS_$targetArch ""
928 set_default_value HAIKU_ARFLAGS_$targetArch cru
929 set_default_value HAIKU_UNARFLAGS_$targetArch x
931 # Override the cross tools variables, if the tools were built or a
932 # prefix was specified.
933 if [ -n "$crossToolsPrefix" ]; then
934 get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
935 get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
936 get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
937 get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
938 get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
940 case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
941 4.*|5.*|6.*|7.*|8.*)
942 get_build_tool_path ELFEDIT_$targetArch \
943 ${crossToolsPrefix}elfedit
945 esac
948 # check whether the Haiku compiler really targets Haiku
949 targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
950 case "$targetMachine" in
951 *-*-haiku) ;;
953 echo The compiler specified as Haiku target compiler is not a \
954 valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
955 echo compiler: $HAIKU_CC
956 echo compiler is configured for target: $targetMachine
957 exit 1 ;;
958 esac
960 HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
961 isPrimaryArch=
962 done
965 # Generate BuildConfig
966 cat << EOF > "$buildConfigFile"
967 # -- WARNING --
968 # This file was AUTOMATICALLY GENERATED by configure, and will be completely
969 # overwritten the next time configure is run.
971 #d ${currentDir}
972 #c ${configurePath}
973 #e ${configureEnvirons}
974 #a ${configureArgs}
976 TARGET_PLATFORM ?= "${TARGET_PLATFORM}" ;
977 HOST_PLATFORM ?= "${HOST_PLATFORM}" ;
979 HAIKU_INCLUDE_PATENTED_CODE ?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
980 HAIKU_INCLUDE_SOURCES ?= "${HAIKU_INCLUDE_SOURCES}" ;
981 HAIKU_INCLUDE_3RDPARTY ?= "${HAIKU_INCLUDE_3RDPARTY}" ;
982 HAIKU_DISTRO_COMPATIBILITY ?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
983 HAIKU_USE_GCC_PIPE ?= "${HAIKU_USE_GCC_PIPE}" ;
984 HAIKU_HOST_USE_32BIT ?= "${HAIKU_HOST_USE_32BIT}" ;
985 HAIKU_HOST_USE_XATTR ?= "${HAIKU_HOST_USE_XATTR}" ;
986 HAIKU_HOST_USE_XATTR_REF ?= "${HAIKU_HOST_USE_XATTR_REF}" ;
987 HAIKU_HOST_BUILD_ONLY ?= "${HAIKU_HOST_BUILD_ONLY}" ;
989 HAIKU_PACKAGING_ARCHS ?= ${HAIKU_PACKAGING_ARCHS} ;
991 HAIKU_NO_DOWNLOADS ?= "${HAIKU_NO_DOWNLOADS}" ;
993 HAIKU_BUILD_ATTRIBUTES_DIR ?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
995 HAIKU_NASM ?= ${HAIKU_NASM} ;
996 HAIKU_BOOT_BOARD ?= ${HAIKU_BOOT_BOARD} ;
998 HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ;
999 HOST_GCC_RAW_VERSION ?= ${HOST_GCC_RAW_VERSION} ;
1000 HOST_GCC_MACHINE ?= ${HOST_GCC_MACHINE} ;
1001 HOST_LD ?= ${HOST_GCC_LD} ;
1002 HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ;
1003 HOST_SHA256 ?= ${HOST_SHA256} ;
1005 HOST_HAIKU_PORTER ?= ${HOST_HAIKU_PORTER} ;
1006 HAIKU_PORTS ?= ${HAIKU_PORTS} ;
1007 HAIKU_PORTS_CROSS ?= ${HAIKU_PORTS_CROSS} ;
1008 HAIKU_IS_BOOTSTRAP ?= ${HAIKU_IS_BOOTSTRAP} ;
1012 for targetArch in $HAIKU_PACKAGING_ARCHS; do
1013 variables="
1014 HAIKU_GCC_RAW_VERSION HAIKU_GCC_RAW_VERSION
1015 HAIKU_GCC_MACHINE HAIKU_GCC_MACHINE
1016 HAIKU_GCC_LIB_DIR HAIKU_GCC_LIB_DIR
1017 HAIKU_CPU HAIKU_CPU
1018 HAIKU_BOOT_LIBGCC HAIKU_BOOT_LIBGCC
1019 HAIKU_BOOT_LIBSUPC++ HAIKU_BOOT_LIBSUPCXX
1020 HAIKU_AR HAIKU_AR
1021 HAIKU_CC HAIKU_CC
1022 HAIKU_CC_IS_CLANG HAIKU_CC_IS_CLANG
1023 HAIKU_LD HAIKU_LD
1024 HAIKU_OBJCOPY HAIKU_OBJCOPY
1025 HAIKU_RANLIB HAIKU_RANLIB
1026 HAIKU_ELFEDIT HAIKU_ELFEDIT
1027 HAIKU_STRIP HAIKU_STRIP
1028 HAIKU_CPPFLAGS HAIKU_CPPFLAGS
1029 HAIKU_CCFLAGS HAIKU_CCFLAGS
1030 HAIKU_C++FLAGS HAIKU_CXXFLAGS
1031 HAIKU_LDFLAGS HAIKU_LDFLAGS
1032 HAIKU_ARFLAGS HAIKU_ARFLAGS
1033 HAIKU_UNARFLAGS HAIKU_UNARFLAGS
1034 HAIKU_USE_GCC_GRAPHITE HAIKU_USE_GCC_GRAPHITE
1036 set -- $variables
1037 while [ $# -ge 2 ]; do
1038 value=`get_variable ${2}_$targetArch`
1039 echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
1040 shift 2
1041 done
1043 # For variables that may have long values, distribute them over multiple
1044 # lines so that jam doesn't hit the maximum line length.
1045 variables="
1046 HAIKU_BOOT_C++_HEADERS_DIR HAIKU_BOOT_CXX_HEADERS_DIR
1048 set -- $variables
1049 while [ $# -ge 2 ]; do
1050 echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
1051 get_variable ${2}_$targetArch | xargs -n 1 echo " " \
1052 >> "$buildConfigFile"
1053 echo " ;" >> "$buildConfigFile"
1054 shift 2
1055 done
1056 done
1059 # Generate a boot strap Jamfile in the output directory.
1061 cat << EOF > $outputDir/Jamfile
1062 # automatically generated Jamfile
1064 HAIKU_TOP = ${sourceDir} ;
1065 HAIKU_OUTPUT_DIR = ${outputDir} ;
1067 include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
1071 echo "Configured successfully!"