IORequest: NULL check does not belong in method body.
[haiku.git] / configure
blob6b9a2fd775ee1b586f067ec0921202590844cd4f
1 #!/bin/sh
3 # configure [ <options> ]
5 # usage
7 # Prints usage.
9 usage()
11 cat << EOF
13 Usage: $0 <options>
14 options:
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 This option and --cross-tools-prefix can be
34 specified multiple times. The first cross tools
35 specify the primary tools, the subsequent ones the
36 secondary tools (for "hybrid" images).
37 For the first --build-cross-tools the
38 <build tools dir> argument must be specified and
39 for the subsequent ones it must be omitted.
40 --cross-tools-prefix <prefix>
41 Assume cross compilation. <prefix> should be a
42 path to the directory where the cross
43 compilation tools are located, plus the platform
44 prefix, e.g. "/path/to/tools/i586-pc-haiku-".
45 This overrides the HAIKU_* tool variables.
46 --distro-compatibility <level>
47 The distribution's level of compatibility with
48 the official Haiku distribution. The generated
49 files will contain the respective trademarks
50 accordingly.
51 official -- the official Haiku distribution.
52 compatible -- a Haiku Compatible (tm) distro.
53 default -- any other distro (default value).
54 --help Prints out this help.
55 --host-only Configure for building tools for the build host
56 only. Haiku cannot be built when configured like
57 this.
58 --include-patented-code Enable code that is known to implemented patented
59 ideas and techniques. If this option is not
60 specified, the resulting distribution may still
61 implement patented ideas and techniques. This
62 option only disables code that is currently known
63 to be problematic.
64 --include-sources Includes the source code of projects that require
65 either an offer of source code or a copy of the
66 patched sources. This is preferable when
67 distributing on physical mediums.
68 --include-3rdparty Include 3rdparty/ in the build system.
69 -j<n> Only relevant for --build-cross-tools. Is passed
70 on to the make building the build tools.
71 --no-downloads Do not download anything. Useful when trying to
72 bootstrap and build Haiku from source only.
73 --target=TARGET Select build target platform.
74 [default=${TARGET_PLATFORM}]
75 valid targets=r5,bone,dano,haiku
76 --target-arch <arch> Haiku only: Specify the target architecture to
77 build for. Must be one of the architectures of the
78 host system. The installed build tools for that
79 architecture will be used.
80 This option can be specified multiple times. The
81 first occurrence specifies the primary
82 architecture of the Haiku to build, subsequent
83 ones the secondary architectures.
84 --update re-runs last configure invocation [must be given
85 as first option!]
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 --use-xattr Use Linux xattr respectively *BSD extattr support
94 for BeOS attribute emulation. Warning: Make sure
95 your file system supports sufficient attribute
96 sizes (4 KB per file for all attributes won't
97 suffice).
98 --use-xattr-ref Use the generic BeOS attribute emulation, but use
99 Linux xattr respectively *BSD extattr support to
100 make it more robust (i.e. attribute mix-ups become
101 less likely).
102 --with-gdb <gdb sources dir>
103 specify the path to a GDB source dir, to build
104 GDB for each arch we build the cross-tools for.
106 environment variables:
107 CC The host compiler. Defaults to "gcc".
108 HAIKU_AR_<arch> The static library archiver for <arch>.
109 Defaults to "ar".
110 HAIKU_CC_<arch> The compiler for <arch>. Defaults to "gcc".
111 HAIKU_LD_<arch> The <arch> linker. Defaults to "ld".
112 HAIKU_OBJCOPY_<arch> The <arch> objcopy to be used. Defaults to
113 "objcopy".
114 HAIKU_RANLIB_<arch> The static library indexer for <arch>. Defaults
115 to "ranlib".
116 HAIKU_STRIP_<arch> The <arch> strip command. Defaults to "strip".
117 HAIKU_NASM The nasm assembler (x86 and x86_64 only).
118 HAIKU_CPPFLAGS_<arch> The preprocessor flags for target architecture
119 <arch>. Defaults to "".
120 HAIKU_CCFLAGS_<arch> The C flags for target architecture <arch>.
121 Defaults to "".
122 HAIKU_CXXFLAGS_<arch> The C++ flags for target architecture <arch>.
123 Defaults to "".
124 HAIKU_LDFLAGS_<arch> The linker flags for target architecture <arch>.
125 Defaults to "".
126 HAIKU_ARFLAGS_<arch> The flags passed to HAIKU_AR for target
127 architecture <arch> for archiving. Defaults to
128 "cru".
129 HAIKU_UNARFLAGS_<arch> The flags passed to HAIKU_AR for target
130 architecture <arch> for unarchiving. Defaults to
131 "x".
133 Non-default output directories:
134 By default all objects, build configuration, and other related files are
135 stored in /path/to/haiku_source/generated. To store objects in a non-default
136 location, run "../../relative/path/to/haiku_source/configure <options>" from
137 within your non-default location. "jam [ options ] targets" can then be run
138 directly inside your non-default location. Another option is to invoke "jam
139 [ options ] targets" from within haiku_source. This can be accomplished by
140 either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
141 jam or by creating a symlink of haiku_source/generated pointing to your
142 non-default location and running jam.
148 # assertparam
150 # Checks whether at least one parameter is left.
152 assertparam()
154 if [ $2 -lt 2 ]; then
155 echo $0: \`$1\': Parameter expected.
156 exit 1
160 # assertparams
162 # Checks whether at least a certain number of parameters is left.
164 assertparams()
166 if [ $3 -le $2 ]; then
167 echo $0: \`$1\': Not enough parameters.
168 exit 1
172 # absolute_path
174 # returns the absolute path of a given path.
176 absolute_path()
178 if [ "x$1" != "x${1#/}" ]; then
179 echo "$1"
180 else
181 echo "`pwd`/$1"
185 # check_dir_exists
187 # check if a directory exists or not
189 check_dir_exists()
191 if [ -d "$1" ]; then
192 return 0
193 else
194 return 1
198 # check_file_exists
200 # check if a file exists or not
202 check_file_exists()
204 if [ -f "$1" ]; then
205 return 0
206 else
207 return 1
211 # real_path
213 # returns the realpath of a symbolic link.
215 real_path()
217 perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
220 # standard_gcc_settings
222 # Sets the variables for a GCC platform.
224 standard_gcc_settings()
226 local gcc="$1"
228 if which greadlink > /dev/null 2>&1; then
229 readlink="greadlink -e"
230 elif which realpath > /dev/null 2>&1; then
231 readlink=realpath
232 elif readlink -e / > /dev/null 2>&1; then
233 readlink="readlink -e"
234 else
235 readlink=real_path
238 # PLATFORM_LINKLIBS
239 local gcclib=`$gcc -print-libgcc-file-name`
240 local gccdir=`dirname ${gcclib}`
242 local gccRawVersion=`$gcc -dumpversion`
243 local gccMachine=`$gcc -dumpmachine`
245 # determine architecture from machine triple
246 case $gccMachine in
247 arm-*) targetCpu=arm;;
248 i?86-*) targetCpu=x86;;
249 m68k-*) targetCpu=m68k;;
250 powerpc-*) targetCpu=ppc;;
251 x86_64-*) targetCpu=x86_64;;
253 echo "Unsupported gcc target machine: $gccMachine" >&2
254 exit 1
256 esac
258 local targetArch=$targetCpu
260 case $gccRawVersion in
261 2.9*)
262 # check for correct (most up-to-date) legacy compiler and complain
263 # if an older one is installed
264 if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
265 echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
266 echo "Please download it from www.haiku-os.org...";
267 exit 1;
270 targetArch=x86_gcc2
272 esac
274 local bootLibgcc
275 local bootLibSupCxx
276 local bootCxxHeaders
277 case $gccMachine in
278 x86_64-*)
279 # Boot loader is 32-bit, need the 32-bit libs and c++ config
280 bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a`
281 bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
283 local headersBase=$gccdir/../../../..
284 local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
285 if [ ! -d $headers ]; then
286 headers=$headersBase/include/c++/$gccRawVersion
288 bootCxxHeaders="$headers/$gccMachine/32"
290 esac
292 # determine whether graphite loop optimization should/can be used
293 local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
294 if [ -z "$useGraphite" ]; then
295 useGraphite=$useGccGraphiteDefault
298 if [ "$useGraphite" != 0 ]; then
299 UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
300 if [ $? != 0 ]; then
301 echo "GCC Graphite loop optimizations cannot be used on $targetArch"
302 useGraphite=0
306 set_variable HAIKU_CPU_$targetArch $targetCpu
308 get_build_tool_path CC_$targetArch "$gcc"
309 set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
310 set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
311 set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
312 set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
313 set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
314 set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
315 set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
316 set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
318 standard_gcc_settings_targetArch=$targetArch
321 # set_variable
323 # Set the value of a variable.
325 set_variable()
327 eval "$1=\"$2\""
330 # get_variable
332 # Echo the value of a variable.
334 get_variable()
336 eval "echo \${$1}"
339 # set_default_value
341 # Set the value for a variable, if no value is set yet.
343 set_default_value()
345 eval "$1=\${$1-$2}"
348 # get_build_tool_path
350 # Gets a usable absolute path of a build tool.
352 get_build_tool_path()
354 local var="HAIKU_$1"
355 local varval="`get_variable $var`"
356 local cmd="$2"
358 if [ ! -z "$varval" ]; then
359 # this variable is already set (probably by user) so grab its contents
360 cmd=$varval
363 local path=${cmd%% *}
365 if [ -f "$path" ]; then
366 # get absolute path from relative path
367 local oldPwd="`pwd`"
368 cd "`dirname "$path"`"
369 path="`pwd`/`basename "$path"`"
370 cd $oldPwd
371 else
372 which "$path" > /dev/null 2>&1 || {
373 echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
374 exit 1
378 if test "${cmd#* }" != "$cmd"; then
379 # $cmd contains arguments, so preserve them (and only them)
380 cmd=${cmd#* }
381 else
382 # $cmd does not contain arguments, so unset it
383 cmd=
385 eval "$var=\"$path $cmd\""
388 is_in_list()
390 local element
391 for element in $2; do
392 if [ "$1" = "$element" ]; then
393 return 0
395 done
396 return 1
399 # check for --help or -h and show usage immediately
400 if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
401 usage; exit 0;
404 # ensure umask is not too restrictive
405 if [ $(umask) -gt 22 ]; then
406 echo "Your umask is too restrictive (should be: <= 0022; is actually:" $(umask)")"
407 exit 1
410 # get cwd and the source directory
411 currentDir=`pwd`
412 cd `dirname "$0"`
413 sourceDir=`pwd`
414 cd "$currentDir"
416 # backup the passed arguments
417 configureArgs="$@"
419 # internal default parameter values
421 platform=`uname`
422 platformMachine=`uname -m`
423 targetArchs=
424 buildCrossTools=
425 buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
426 buildCrossToolsJobs=
427 useClang=0
428 useGccGraphiteDefault=0
429 unknownArchIndex=1
430 haikuTargetArchs=
431 gdbSources=
433 if [ -z "$CC" ]; then
434 CC=gcc
437 # exported (BuildSetup) default parameter values
439 HOST_GCC_RAW_VERSION=`$CC -dumpversion`
440 HOST_GCC_MACHINE=`$CC -dumpmachine`
441 HAIKU_INCLUDE_PATENTED_CODE=0
442 HAIKU_INCLUDE_SOURCES=0
443 HAIKU_INCLUDE_3RDPARTY=0
444 HAIKU_DISTRO_COMPATIBILITY=default
445 TARGET_PLATFORM=haiku
446 HAIKU_USE_GCC_PIPE=0
447 HAIKU_HOST_USE_32BIT=0
448 HAIKU_HOST_USE_XATTR=0
449 HAIKU_HOST_USE_XATTR_REF=0
450 HAIKU_HOST_BUILD_ONLY=0
451 HOST_EXTENDED_REGEX_SED="sed -r"
452 HOST_GCC_LD=`$CC -print-prog-name=ld`
453 HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
454 HOST_SHA256=
455 HOST_HAIKU_PORTER=
456 HAIKU_PORTS=
457 HAIKU_PORTS_CROSS=
458 HAIKU_IS_BOOTSTRAP=0
459 HAIKU_BOOT_BOARD=
460 HAIKU_NO_DOWNLOADS=0
462 HAIKU_PACKAGING_ARCHS=
464 set_default_value HAIKU_NASM nasm
466 if sha256sum < /dev/null > /dev/null 2>&1; then
467 HOST_SHA256=sha256sum
468 elif sha256 < /dev/null > /dev/null 2>&1; then
469 HOST_SHA256="sha256 -q"
470 elif shasum < /dev/null > /dev/null 2>&1; then
471 HOST_SHA256="shasum -a 256"
472 else
473 echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
474 exit 1
477 haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
478 export haikuRequiredLegacyGCCVersion
479 # version of legacy gcc required to build haiku
480 supportedTargetArchs="
482 m68k
485 x86_64
486 x86_gcc2
489 # determine output directory
490 if [ "$currentDir" = "$sourceDir" ]; then
491 outputDir=$currentDir/generated
492 else
493 outputDir=$currentDir
495 buildOutputDir="$outputDir/build"
496 HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
497 buildConfigFile="$buildOutputDir/BuildConfig"
499 # check for update request
500 if [ "$1" = "--update" ]; then
501 if ! [ -e "$buildConfigFile" ]; then
502 echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
503 exit 1
505 if ! type perl >/dev/null 2>&1; then
506 echo $0 --update: \'perl\' not found - updating not possible.
507 exit 1
509 # convert BuildConfig from jam format to shell format and evaluate it
510 shellConfigFile="${buildConfigFile}.shell"
511 perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \
512 <"$buildConfigFile" >"$shellConfigFile"
513 . "$shellConfigFile"
514 rm "$shellConfigFile"
515 shift
518 # parse parameters
520 while [ $# -gt 0 ] ; do
521 case "$1" in
522 --bootstrap)
523 assertparams "$1" 3 $#
524 HOST_HAIKU_PORTER="`absolute_path $2`"
525 HAIKU_PORTS_CROSS="`absolute_path $3`"
526 HAIKU_PORTS="`absolute_path $4`"
527 HAIKU_IS_BOOTSTRAP=1
528 HAIKU_NO_DOWNLOADS=1
529 check_file_exists "$HOST_HAIKU_PORTER" || (
530 echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
531 exit 1
533 check_dir_exists "$HAIKU_PORTS" || (
534 echo "Non-existent directory $HAIKU_PORTS" >&2
535 exit 1
537 check_dir_exists "$HAIKU_PORTS_CROSS" || (
538 echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
539 exit 1
541 shift 4
543 --build-cross-tools)
544 if [ -z "$buildCrossTools" ]; then
545 assertparams "$1" 2 $#
546 targetArch=$2
547 buildCrossTools=$3
548 shift 3
549 else
550 assertparam "$1" $#
551 targetArch=$2
552 shift 2
554 case "$targetArch" in
555 x86_gcc2) targetMachine=i586-pc-haiku;;
556 x86) targetMachine=i586-pc-haiku;;
557 x86_64) targetMachine=x86_64-unknown-haiku;;
558 ppc) targetMachine=powerpc-apple-haiku;;
559 m68k) targetMachine=m68k-unknown-haiku;;
560 arm) targetMachine=arm-unknown-haiku;;
562 echo "Unsupported target architecture: $2" >&2
563 exit 1
565 esac
566 set_variable buildCrossToolsMachine_$targetArch $targetMachine
567 targetArchs="$targetArchs $targetArch"
568 HAIKU_PACKAGING_ARCHS=
570 --cross-tools-prefix)
571 assertparam "$1" $#
572 targetArch=unknown${unknownArchIndex}
573 set_variable crossToolsPrefix_$targetArch "$2"
574 targetArchs="$targetArchs $targetArch"
575 HAIKU_PACKAGING_ARCHS=
576 unknownArchIndex=$(($unknownArchIndex + 1))
577 shift 2
579 --distro-compatibility)
580 assertparam "$1" $#
581 HAIKU_DISTRO_COMPATIBILITY=$2
582 case "$HAIKU_DISTRO_COMPATIBILITY" in
583 official) ;;
584 compatible) ;;
585 default) ;;
586 *) echo "Invalid distro compatibility" \
587 "level: $HAIKU_DISTRO_COMPATIBILITY"
588 exit 1;;
589 esac
590 shift 2
592 --host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;;
593 --include-patented-code) HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;;
594 --include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;;
595 --include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
596 -j*) buildCrossToolsJobs="$1"; shift 1;;
597 --no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;;
598 --target=*) TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;;
599 --target-arch)
600 assertparam "$1" $#
601 targetArch=$2
602 shift 2
603 if [ ! "$platform" = Haiku ]; then
604 echo "--target-arch can only be specified on Haiku." >&2
605 exit 1
607 is_in_list "$targetArch" "$supportedTargetArchs" || (
608 echo "Unsupported target architecture: \"$targetArch\"" >&2
609 exit 1
611 haikuTargetArchs="$haikuTargetArchs $targetArch"
613 --use-clang)
614 assertparam "$1" $#
615 targetArch=$2
616 useClang=1
617 case "$targetArch" in
618 x86) targetMachine=i586-pc-haiku;;
619 x86_64) targetMachine=x86_64-unknown-haiku;;
621 echo "Unsupported target architecture: $2" >&2
622 exit 1
624 esac
625 get_build_tool_path clang clang
626 if [ -n "crossToolsPrefix_$targetArch" ]; then
627 set_variable crossToolsPrefix_$targetArch llvm-
629 targetArchs="$targetArchs $targetArch"
630 HAIKU_PACKAGING_ARCHS=
631 shift 2
633 --use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;;
634 --use-gcc-graphite) useGccGraphiteDefault=1; shift 1;;
635 --use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;;
636 --use-xattr) HAIKU_HOST_USE_XATTR=1; shift 1;;
637 --use-xattr-ref) HAIKU_HOST_USE_XATTR_REF=1; shift 1;;
638 --with-gdb) gdbSources=$2; shift 2;;
639 *) echo Invalid argument: \`$1\'; exit 1;;
640 esac
641 done
643 # detect the build platform
644 case "${platform}" in
645 Darwin) HOST_PLATFORM=darwin ;;
646 FreeBSD) HOST_PLATFORM=freebsd
647 if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
648 echo Unsupported platform: FreeBSD ${platformMachine}
649 exit 1
650 fi ;;
651 Haiku) HOST_PLATFORM=haiku_host ;;
652 Linux) HOST_PLATFORM=linux ;;
653 OpenBSD) HOST_PLATFORM=openbsd ;;
654 SunOS) HOST_PLATFORM=sunos ;;
655 CYGWIN_NT-*) HOST_PLATFORM=cygwin ;;
656 *) echo Unsupported platform: ${platform}
657 exit 1 ;;
658 esac
660 # check for case-sensitive filesystem
661 mkdir haikuCaseTest 2>/dev/null
662 mkdir haikucasetest 2>/dev/null
663 caseInsensitive=$?
664 rmdir haikuCaseTest haikucasetest 2>/dev/null
665 if [ $caseInsensitive != 0 ]; then
666 echo "You need a case-sensitive file-system to build Haiku."
667 if [ $HOST_PLATFORM = "darwin" ]; then
668 echo "You can create a case-sensitive disk image using Disk Utility."
670 exit 1
673 # determine how to invoke sed with extended regexp support for non-GNU sed
674 if [ $HOST_PLATFORM = "darwin" ]; then
675 HOST_EXTENDED_REGEX_SED="sed -E"
678 # check if nasm can actually output ELF files
679 # (the stock version in OSX can't)
680 # XXX: should probably only test for x86* arch
681 if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
682 echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
683 if [ $HOST_PLATFORM = "darwin" ]; then
684 echo "You can install it from Mac Ports."
685 echo "Mac Ports is available at: http://www.macports.org/"
687 exit 1
690 # create output directory
691 mkdir -p "$buildOutputDir" || exit 1
693 if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
694 invalidCommand=$sourceDir/build/scripts/host_build_only
695 HAIKU_AR=$invalidCommand
696 HAIKU_CC=$invalidCommand
697 HAIKU_LD=$invalidCommand
698 HAIKU_OBJCOPY=$invalidCommand
699 HAIKU_RANLIB=$invalidCommand
700 HAIKU_ELFEDIT=$invalidCommand
701 HAIKU_NASM=$invalidCommand
702 HAIKU_STRIP=$invalidCommand
703 else
704 if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then
705 targetArchs="$HAIKU_PACKAGING_ARCHS"
707 HAIKU_PACKAGING_ARCHS=
709 # On Haiku determine target architectures and tools automatically.
710 if [ -z "$targetArchs" ]; then
711 if [ $HOST_PLATFORM != haiku_host ]; then
712 echo "Please specify the build tools to use or build (via" \
713 "--cross-tools-prefix or --build-cross-tools) or specify a" \
714 "host-only build (--host-only)." >&2
715 echo "For more info, invoke $0 --help"
716 exit 1
719 # determine primary architecture
720 targetArch=`package list -i /system/packages/haiku-*.hpkg \
721 | sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
722 is_in_list "$targetArch" "$supportedTargetArchs" || (
723 echo "Unsupported target architecture: \"$targetArch\"" >&2
724 exit 1
726 targetArchs=$targetArch
728 set_default_value HAIKU_AR_$targetArch ar
729 set_default_value HAIKU_CC_$targetArch gcc
730 set_default_value HAIKU_LD_$targetArch ld
731 set_default_value HAIKU_OBJCOPY_$targetArch objcopy
732 set_default_value HAIKU_RANLIB_$targetArch ranlib
733 set_default_value HAIKU_ELFEDIT_$targetArch elfedit
734 set_default_value HAIKU_STRIP_$targetArch strip
736 # determine secondary architectures
737 for targetArch in $supportedTargetArchs; do
738 if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
739 targetArchs="$targetArchs $targetArch"
740 set_default_value HAIKU_AR_$targetArch ar-$targetArch
741 set_default_value HAIKU_CC_$targetArch gcc-$targetArch
742 set_default_value HAIKU_LD_$targetArch ld-$targetArch
743 set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch
744 set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch
745 set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch
746 set_default_value HAIKU_STRIP_$targetArch strip-$targetArch
748 done
750 # The target architectures might have been specified explicitly.
751 if [ -n "$haikuTargetArchs" ]; then
752 for targetArch in $haikuTargetArchs; do
753 is_in_list "$targetArch" "$targetArchs" || (
754 echo "Unsupported target architecture: \"$targetArch\"." \
755 "Only native architectures of the host platform can" \
756 "be specified." >&2
757 exit 1
759 done
760 targetArchs="$haikuTargetArchs"
764 isPrimaryArch=1
765 for targetArch in $targetArchs; do
766 # Note: targetArch is "unknown<n>" at this point, if a cross-tools
767 # prefix was specified. The standard_gcc_settings call below will get
768 # the actual architecture.
770 crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
772 # build cross tools from sources
773 if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
774 crossToolsDir="$outputDir/cross-tools-$targetArch"
775 targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
776 script="$buildCrossToolsScript"
777 scriptArgs=
778 if [ $targetArch != x86_gcc2 ]; then
779 script="${script}_gcc4"
780 scriptArgs="$targetMachine"
781 set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \
782 $useGccGraphiteDefault
784 secondaryArch=
785 if [ -z "$isPrimaryArch" ]; then
786 secondaryArch=$targetArch
789 case $HOST_PLATFORM in
790 freebsd|openbsd) MAKE=gmake;;
791 *) MAKE=make;;
792 esac
794 MAKE=$MAKE \
795 SECONDARY_ARCH=$secondaryArch \
796 HAIKU_USE_GCC_GRAPHITE=`get_variable \
797 HAIKU_USE_GCC_GRAPHITE_$targetArch` \
798 HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \
799 HAIKU_USE_GDB="$gdbSources" \
800 "$script" $scriptArgs "$sourceDir" "$buildCrossTools" \
801 "$crossToolsDir" $buildCrossToolsJobs || exit 1
802 crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-"
805 # prepare gcc settings and get the actual target architecture
806 if [ $useClang = 1 ]; then
807 gcc="$HAIKU_clang -target ${targetMachine} -no-integrated-as"
809 # Clang's compiler intrinsics are not compatible with GCC's or even
810 # across versions of Clang, so we must collect them for use in the build.
811 mkdir -p "$outputDir/clang_headers" || exit 1
812 clangHeadersDir=`$gcc -print-resource-dir`/include/
813 cp $clangHeadersDir/*intrin* $clangHeadersDir/mm3* "$outputDir/clang_headers" || exit 1
814 elif [ -z "${crossToolsPrefix}" ]; then
815 gcc=`get_variable HAIKU_CC_$targetArch`
816 else
817 gcc="${crossToolsPrefix}gcc"
819 standard_gcc_settings "$gcc"
820 targetArch=$standard_gcc_settings_targetArch
822 # set default values for flags
823 set_default_value HAIKU_CPPFLAGS_$targetArch ""
824 set_default_value HAIKU_CCFLAGS_$targetArch ""
825 set_default_value HAIKU_CXXFLAGS_$targetArch ""
826 set_default_value HAIKU_LDFLAGS_$targetArch ""
827 set_default_value HAIKU_ARFLAGS_$targetArch cru
828 set_default_value HAIKU_UNARFLAGS_$targetArch x
830 # Override the cross tools variables, if the tools were built or a
831 # prefix was specified.
832 if [ -n "$crossToolsPrefix" ]; then
833 get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar
834 get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld
835 get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy
836 get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib
837 get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip
839 case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in
840 4.*|5.*|6.*|7.*|8.*)
841 get_build_tool_path ELFEDIT_$targetArch \
842 ${crossToolsPrefix}elfedit
844 esac
847 # check whether the Haiku compiler really targets Haiku
848 targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch`
849 case "$targetMachine" in
850 *-*-haiku) ;;
852 echo The compiler specified as Haiku target compiler is not a \
853 valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2
854 echo compiler: $HAIKU_CC
855 echo compiler is configured for target: $targetMachine
856 exit 1 ;;
857 esac
859 HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch"
860 isPrimaryArch=
861 done
864 # Generate BuildConfig
865 cat << EOF > "$buildConfigFile"
866 # BuildConfig
867 # Note: This file has been automatically generated by configure with the
868 # following arguments:
869 # ${configureArgs}
871 TARGET_PLATFORM ?= "${TARGET_PLATFORM}" ;
872 HOST_PLATFORM ?= "${HOST_PLATFORM}" ;
874 HAIKU_INCLUDE_PATENTED_CODE ?= "${HAIKU_INCLUDE_PATENTED_CODE}" ;
875 HAIKU_INCLUDE_SOURCES ?= "${HAIKU_INCLUDE_SOURCES}" ;
876 HAIKU_INCLUDE_3RDPARTY ?= "${HAIKU_INCLUDE_3RDPARTY}" ;
877 HAIKU_DISTRO_COMPATIBILITY ?= "${HAIKU_DISTRO_COMPATIBILITY}" ;
878 HAIKU_USE_GCC_PIPE ?= "${HAIKU_USE_GCC_PIPE}" ;
879 HAIKU_HOST_USE_32BIT ?= "${HAIKU_HOST_USE_32BIT}" ;
880 HAIKU_HOST_USE_XATTR ?= "${HAIKU_HOST_USE_XATTR}" ;
881 HAIKU_HOST_USE_XATTR_REF ?= "${HAIKU_HOST_USE_XATTR_REF}" ;
882 HAIKU_HOST_BUILD_ONLY ?= "${HAIKU_HOST_BUILD_ONLY}" ;
884 HAIKU_PACKAGING_ARCHS ?= ${HAIKU_PACKAGING_ARCHS} ;
886 HAIKU_NO_DOWNLOADS ?= "${HAIKU_NO_DOWNLOADS}" ;
888 HAIKU_BUILD_ATTRIBUTES_DIR ?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ;
890 HAIKU_NASM ?= ${HAIKU_NASM} ;
891 HAIKU_BOOT_BOARD ?= ${HAIKU_BOOT_BOARD} ;
893 HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ;
894 HOST_GCC_RAW_VERSION ?= ${HOST_GCC_RAW_VERSION} ;
895 HOST_GCC_MACHINE ?= ${HOST_GCC_MACHINE} ;
896 HOST_LD ?= ${HOST_GCC_LD} ;
897 HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ;
898 HOST_SHA256 ?= ${HOST_SHA256} ;
900 HOST_HAIKU_PORTER ?= ${HOST_HAIKU_PORTER} ;
901 HAIKU_PORTS ?= ${HAIKU_PORTS} ;
902 HAIKU_PORTS_CROSS ?= ${HAIKU_PORTS_CROSS} ;
903 HAIKU_IS_BOOTSTRAP ?= ${HAIKU_IS_BOOTSTRAP} ;
907 for targetArch in $HAIKU_PACKAGING_ARCHS; do
908 variables="
909 HAIKU_GCC_RAW_VERSION HAIKU_GCC_RAW_VERSION
910 HAIKU_GCC_MACHINE HAIKU_GCC_MACHINE
911 HAIKU_GCC_LIB_DIR HAIKU_GCC_LIB_DIR
912 HAIKU_CPU HAIKU_CPU
913 HAIKU_BOOT_LIBGCC HAIKU_BOOT_LIBGCC
914 HAIKU_BOOT_LIBSUPC++ HAIKU_BOOT_LIBSUPCXX
915 HAIKU_AR HAIKU_AR
916 HAIKU_CC HAIKU_CC
917 HAIKU_CC_IS_CLANG HAIKU_CC_IS_CLANG
918 HAIKU_LD HAIKU_LD
919 HAIKU_OBJCOPY HAIKU_OBJCOPY
920 HAIKU_RANLIB HAIKU_RANLIB
921 HAIKU_ELFEDIT HAIKU_ELFEDIT
922 HAIKU_STRIP HAIKU_STRIP
923 HAIKU_CPPFLAGS HAIKU_CPPFLAGS
924 HAIKU_CCFLAGS HAIKU_CCFLAGS
925 HAIKU_C++FLAGS HAIKU_CXXFLAGS
926 HAIKU_LDFLAGS HAIKU_LDFLAGS
927 HAIKU_ARFLAGS HAIKU_ARFLAGS
928 HAIKU_UNARFLAGS HAIKU_UNARFLAGS
929 HAIKU_USE_GCC_GRAPHITE HAIKU_USE_GCC_GRAPHITE
931 set -- $variables
932 while [ $# -ge 2 ]; do
933 value=`get_variable ${2}_$targetArch`
934 echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile"
935 shift 2
936 done
938 # For variables that may have long values, distribute them over multiple
939 # lines so that jam doesn't hit the maximum line length.
940 variables="
941 HAIKU_BOOT_C++_HEADERS_DIR HAIKU_BOOT_CXX_HEADERS_DIR
943 set -- $variables
944 while [ $# -ge 2 ]; do
945 echo "${1}_${targetArch} ?= " >> "$buildConfigFile"
946 get_variable ${2}_$targetArch | xargs -n 1 echo " " \
947 >> "$buildConfigFile"
948 echo " ;" >> "$buildConfigFile"
949 shift 2
950 done
951 done
954 # Generate a boot strap Jamfile in the output directory.
956 cat << EOF > $outputDir/Jamfile
957 # automatically generated Jamfile
959 HAIKU_TOP = ${sourceDir} ;
960 HAIKU_OUTPUT_DIR = ${outputDir} ;
962 include [ FDirName \$(HAIKU_TOP) Jamfile ] ;
966 echo "Configured successfully!"