1#!/bin/sh 2# 3# configure [ <options> ] 4 5# usage 6# 7# Prints usage. 8# 9usage() 10{ 11 cat << EOF 12 13Usage: $0 <options> 14options: 15 --bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo> 16 Prepare for a bootstrap build. No pre-built 17 packages will be used, instead they will be built 18 from the sources (in several phases). 19 <haikuporter> is the path to the haikuporter tool 20 suitable for the host platform. 21 <HaikuPorts cross repo> is the path to a checked 22 out HaikuPorts cross-compilation repository. 23 <HaikuPorts repo> is the path to a checked out 24 HaikuPorts repository. 25 --build-cross-tools <arch> [ <build tools dir> ] 26 Assume cross compilation. <build tools dir> 27 defines the location of the build tools sources. 28 They will be compiled and placed in the output 29 directory under "cross-tools". The HAIKU_* tools 30 variables will be set accordingly. 31 <arch> specifies the target architecture, either 32 "x86_gcc2", "x86", "x86_64", "ppc", "m68k", "arm" 33 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 --enable-multiuser Enable experimental multiuser support. 55 --help Prints out this help. 56 --host-only Configure for building tools for the build host 57 only. Haiku cannot be built when configured like 58 this. 59 --include-gpl-addons Include GPL licensed add-ons. 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 disables 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 --target-board <board> ARM only: Target board to build for. 87 <board> is one of: "beagleboard","beaglebone", 88 "rpi1","rpi2","cubieboard4","verdex","overo" 89 --update re-runs last configure invocation [must be given 90 as first option!] 91 --use-clang Build with host Clang instead of GCC cross 92 compiler 93 --use-gcc-pipe Build with GCC option -pipe. Speeds up the build 94 process, but uses more memory. 95 --use-gcc-graphite Build with GCC Graphite engine for loop 96 optimizations. Only for gcc 4. 97 --use-32bit Use -m32 flag on 64bit host gcc compiler. 98 --use-xattr Use Linux xattr respectively *BSD extattr support 99 for BeOS attribute emulation. Warning: Make sure 100 your file system supports sufficient attribute 101 sizes (4 KB per file for all attributes won't 102 suffice). 103 --use-xattr-ref Use the generic BeOS attribute emulation, but use 104 Linux xattr respectively *BSD extattr support to 105 make it more robust (i.e. attribute mix-ups become 106 less likely). 107 --with-gdb <gdb sources dir> 108 specify the path to a GDB source dir, to build 109 GDB for each arch we build the cross-tools for. 110 111environment variables: 112 CC The host compiler. Defaults to "gcc". 113 HAIKU_AR_x86_gcc2 The static library archiver for x86_gcc2. 114 Defaults to "ar". 115 HAIKU_CC_x86_gcc2 The x86_gcc2 compiler. Defaults to "gcc". 116 HAIKU_LD_x86_gcc2 The x86_gcc2 linker. Defaults to "ld". 117 HAIKU_OBJCOPY_x86_gcc2 The x86_gcc2 objcopy to be used. Defaults to 118 "objcopy". 119 HAIKU_RANLIB_x86_gcc2 The static library indexer for x86_gcc2. Defaults 120 to "ranlib". 121 HAIKU_STRIP_x86_gcc2 The x86_gcc2 strip command. Defaults to "strip". 122 HAIKU_NASM The nasm assembler (x86 and x86_64 only). 123 HAIKU_CPPFLAGS_<arch> The preprocessor flags for target architecture 124 <arch>. Defaults to "". 125 HAIKU_CCFLAGS_<arch> The C flags for target architecture <arch>. 126 Defaults to "". 127 HAIKU_CXXFLAGS_<arch> The C++ flags for target architecture <arch>. 128 Defaults to "". 129 HAIKU_LDFLAGS_<arch> The linker flags for target architecture <arch>. 130 Defaults to "". 131 HAIKU_ARFLAGS_<arch> The flags passed to HAIKU_AR for target 132 architecture <arch> for archiving. Defaults to 133 "cru". 134 HAIKU_UNARFLAGS_<arch> The flags passed to HAIKU_AR for target 135 architecture <arch> for unarchiving. Defaults to 136 "x". 137 138Non-default output directories: 139 By default all objects, build configuration, and other related files are 140 stored in /path/to/haiku_source/generated. To store objects in a non-default 141 location, run "../../relative/path/to/haiku_source/configure <options>" from 142 within your non-default location. "jam [ options ] targets" can then be run 143 directly inside your non-default location. Another option is to invoke "jam 144 [ options ] targets" from within haiku_source. This can be accomplished by 145 either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking 146 jam or by creating a symlink of haiku_source/generated pointing to your 147 non-default location and running jam. 148 149 150EOF 151} 152 153# assertparam 154# 155# Checks whether at least one parameter is left. 156# 157assertparam() 158{ 159 if [ $2 -lt 2 ]; then 160 echo $0: \`$1\': Parameter expected. 161 exit 1 162 fi 163} 164 165# assertparams 166# 167# Checks whether at least a certain number of parameters is left. 168# 169assertparams() 170{ 171 if [ $3 -le $2 ]; then 172 echo $0: \`$1\': Not enough parameters. 173 exit 1 174 fi 175} 176 177# absolute_path 178# 179# returns the absolute path of a given path. 180# 181absolute_path() 182{ 183 if [ "x$1" != "x${1#/}" ]; then 184 echo "$1" 185 else 186 echo "`pwd`/$1" 187 fi 188} 189 190# check_dir_exists 191# 192# check if a directory exists or not 193# 194check_dir_exists() 195{ 196 if [ -d "$1" ]; then 197 return 0 198 else 199 return 1 200 fi 201} 202 203# check_file_exists 204# 205# check if a file exists or not 206# 207check_file_exists() 208{ 209 if [ -f "$1" ]; then 210 return 0 211 else 212 return 1 213 fi 214} 215 216# real_path 217# 218# returns the realpath of a symbolic link. 219# 220real_path() 221{ 222 perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1" 223} 224 225# standard_gcc_settings 226# 227# Sets the variables for a GCC platform. 228# 229standard_gcc_settings() 230{ 231 local gcc=$1 232 233 if which greadlink > /dev/null 2>&1; then 234 readlink="greadlink -e" 235 elif which realpath > /dev/null 2>&1; then 236 readlink=realpath 237 elif readlink -e / > /dev/null 2>&1; then 238 readlink="readlink -e" 239 else 240 readlink=real_path 241 fi 242 243 # PLATFORM_LINKLIBS 244 local gcclib=`$gcc -print-libgcc-file-name` 245 local gccdir=`dirname ${gcclib}` 246 247 local gccRawVersion=`$gcc -dumpversion` 248 local gccMachine=`$gcc -dumpmachine` 249 250 # determine architecture from machine triple 251 case $gccMachine in 252 arm-*) targetCpu=arm;; 253 i?86-*) targetCpu=x86;; 254 m68k-*) targetCpu=m68k;; 255 powerpc-*) targetCpu=ppc;; 256 x86_64-*) targetCpu=x86_64;; 257 *) 258 echo "Unsupported gcc target machine: $gccMachine" >&2 259 exit 1 260 ;; 261 esac 262 263 local targetArch=$targetCpu 264 265 case $gccRawVersion in 266 2.9*) 267 # check for correct (most up-to-date) legacy compiler and complain 268 # if an older one is installed 269 if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then 270 echo "GCC version $haikuRequiredLegacyGCCVersion is required!"; 271 echo "Please download it from www.haiku-os.org..."; 272 exit 1; 273 fi 274 275 targetArch=x86_gcc2 276 ;; 277 esac 278 279 local bootLibgcc 280 local bootLibSupCxx 281 local bootCxxHeaders 282 case $gccMachine in 283 x86_64-*) 284 # Boot loader is 32-bit, need the 32-bit libs and c++ config 285 bootLibgcc=`$gcc -m32 -print-file-name=libgcc.a` 286 bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a` 287 288 local headersBase=$gccdir/../../../.. 289 local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion 290 if [ ! -d $headers ]; then 291 headers=$headersBase/include/c++/$gccRawVersion 292 fi 293 bootCxxHeaders="$headers/$gccMachine/32" 294 ;; 295 esac 296 297 # determine whether graphite loop optimization should/can be used 298 local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu` 299 if [ -z "$useGraphite" ]; then 300 useGraphite=$useGccGraphiteDefault 301 fi 302 303 if [ "$useGraphite" != 0 ]; then 304 UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1` 305 if [ $? != 0 ]; then 306 echo "GCC Graphite loop optimizations cannot be used on $targetArch" 307 useGraphite=0 308 fi 309 fi 310 311 set_variable HAIKU_CPU_$targetArch $targetCpu 312 313 get_build_tool_path CC_$targetArch "$gcc" 314 set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang 315 set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion 316 set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine 317 set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir 318 set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders" 319 set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx" 320 set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc 321 set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite 322 323 standard_gcc_settings_targetArch=$targetArch 324} 325 326# set_variable 327# 328# Set the value of a variable. 329# 330set_variable() 331{ 332 eval "$1=\"$2\"" 333} 334 335# get_variable 336# 337# Echo the value of a variable. 338# 339get_variable() 340{ 341 eval "echo \${$1}" 342} 343 344# set_default_value 345# 346# Set the value for a variable, if no value is set yet. 347# 348set_default_value() 349{ 350 eval "$1=\${$1-$2}" 351} 352 353# get_build_tool_path 354# 355# Gets a usable absolute path of a build tool. 356# 357get_build_tool_path() 358{ 359 local var="HAIKU_$1" 360 local cmd=$2 361 local path=${2%% *} 362 363 if [ -f "$path" ]; then 364 # get absolute 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." >&2 372 exit 1 373 } 374 fi 375 376 eval "$var=\"$path ${cmd#${2%% *}}\"" 377} 378 379is_in_list() 380{ 381 local element 382 for element in $2; do 383 if [ "$1" = "$element" ]; then 384 return 0 385 fi 386 done 387 return 1 388} 389 390# check for --help or -h and show usage immediately 391if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then 392 usage; exit 0; 393fi 394 395 396# get cwd and the source directory 397currentDir=`pwd` 398cd `dirname "$0"` 399sourceDir=`pwd` 400cd "$currentDir" 401 402# backup the passed arguments 403configureArgs="$@" 404 405# internal default parameter values 406# 407platform=`uname` 408platformMachine=`uname -m` 409targetArchs= 410buildCrossTools= 411buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 412buildCrossToolsJobs= 413useClang=0 414useGccGraphiteDefault=0 415unknownArchIndex=1 416haikuTargetArchs= 417gdbSources= 418 419if [ -z "$CC" ]; then 420 CC=gcc 421fi 422 423# exported (BuildSetup) default parameter values 424# 425HOST_GCC_RAW_VERSION=`$CC -dumpversion` 426HOST_GCC_MACHINE=`$CC -dumpmachine` 427HAIKU_INCLUDE_GPL_ADDONS=0 428HAIKU_INCLUDE_PATENTED_CODE=0 429HAIKU_INCLUDE_SOURCES=0 430HAIKU_INCLUDE_3RDPARTY=0 431HAIKU_ENABLE_MULTIUSER=0 432HAIKU_DISTRO_COMPATIBILITY=default 433TARGET_PLATFORM=haiku 434HAIKU_USE_GCC_PIPE=0 435HAIKU_HOST_USE_32BIT=0 436HAIKU_HOST_USE_XATTR=0 437HAIKU_HOST_USE_XATTR_REF=0 438HAIKU_HOST_BUILD_ONLY=0 439HOST_EXTENDED_REGEX_SED="sed -r" 440HOST_GCC_LD=`$CC -print-prog-name=ld` 441HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy` 442HOST_SHA256= 443HOST_HAIKU_PORTER= 444HAIKU_PORTS= 445HAIKU_PORTS_CROSS= 446HAIKU_IS_BOOTSTRAP=0 447HAIKU_BOOT_BOARD= 448HAIKU_NO_DOWNLOADS=0 449 450HAIKU_PACKAGING_ARCHS= 451 452set_default_value HAIKU_NASM nasm 453 454if sha256sum < /dev/null > /dev/null 2>&1; then 455 HOST_SHA256=sha256sum 456elif sha256 < /dev/null > /dev/null 2>&1; then 457 HOST_SHA256="sha256 -q" 458elif shasum < /dev/null > /dev/null 2>&1; then 459 HOST_SHA256="shasum -a 256" 460else 461 echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2 462 exit 1 463fi 464 465haikuRequiredLegacyGCCVersion="2.95.3-haiku-2014_07_26" 466export haikuRequiredLegacyGCCVersion 467 # version of legacy gcc required to build haiku 468supportedTargetArchs=" 469 arm 470 m68k 471 ppc 472 x86 473 x86_64 474 x86_gcc2 475 " 476supportedTargetBoards=" 477 beagleboard 478 beaglebone 479 rpi1 480 rpi2 481 cubieboard4 482 verdex 483 overo 484 " 485 486# determine output directory 487if [ "$currentDir" = "$sourceDir" ]; then 488 outputDir=$currentDir/generated 489else 490 outputDir=$currentDir 491fi 492buildOutputDir="$outputDir/build" 493HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes" 494buildConfigFile="$buildOutputDir/BuildConfig" 495 496# check for update request 497if [ "$1" = "--update" ]; then 498 if ! [ -e "$buildConfigFile" ]; then 499 echo $0 --update: \'$buildConfigFile\' not found - updating not possible. 500 exit 1 501 fi 502 if ! type perl >/dev/null 2>&1; then 503 echo $0 --update: \'perl\' not found - updating not possible. 504 exit 1 505 fi 506 # convert BuildConfig from jam format to shell format and evaluate it 507 shellConfigFile="${buildConfigFile}.shell" 508 perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \ 509 <"$buildConfigFile" >"$shellConfigFile" 510 . "$shellConfigFile" 511 rm "$shellConfigFile" 512 shift 513fi 514 515# parse parameters 516# 517while [ $# -gt 0 ] ; do 518 case "$1" in 519 --bootstrap) 520 assertparams "$1" 3 $# 521 HOST_HAIKU_PORTER="`absolute_path $2`" 522 HAIKU_PORTS_CROSS="`absolute_path $3`" 523 HAIKU_PORTS="`absolute_path $4`" 524 HAIKU_IS_BOOTSTRAP=1 525 HAIKU_NO_DOWNLOADS=1 526 check_file_exists "$HOST_HAIKU_PORTER" || ( 527 echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2 528 exit 1 529 ) 530 check_dir_exists "$HAIKU_PORTS" || ( 531 echo "Non-existent directory $HAIKU_PORTS" >&2 532 exit 1 533 ) 534 check_dir_exists "$HAIKU_PORTS_CROSS" || ( 535 echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2 536 exit 1 537 ) 538 shift 4 539 ;; 540 --build-cross-tools) 541 if [ -z "$buildCrossTools" ]; then 542 assertparams "$1" 2 $# 543 targetArch=$2 544 buildCrossTools=$3 545 shift 3 546 else 547 assertparam "$1" $# 548 targetArch=$2 549 shift 2 550 fi 551 case "$targetArch" in 552 x86_gcc2) targetMachine=i586-pc-haiku;; 553 x86) targetMachine=i586-pc-haiku;; 554 x86_64) targetMachine=x86_64-unknown-haiku;; 555 ppc) targetMachine=powerpc-apple-haiku;; 556 m68k) targetMachine=m68k-unknown-haiku;; 557 arm) targetMachine=arm-unknown-haiku;; 558 *) 559 echo "Unsupported target architecture: $2" >&2 560 exit 1 561 ;; 562 esac 563 set_variable buildCrossToolsMachine_$targetArch $targetMachine 564 targetArchs="$targetArchs $targetArch" 565 HAIKU_PACKAGING_ARCHS= 566 ;; 567 --cross-tools-prefix) 568 assertparam "$1" $# 569 targetArch=unknown${unknownArchIndex} 570 set_variable crossToolsPrefix_$targetArch "$2" 571 targetArchs="$targetArchs $targetArch" 572 HAIKU_PACKAGING_ARCHS= 573 unknownArchIndex=$(($unknownArchIndex + 1)) 574 shift 2 575 ;; 576 --distro-compatibility) 577 assertparam "$1" $# 578 HAIKU_DISTRO_COMPATIBILITY=$2 579 case "$HAIKU_DISTRO_COMPATIBILITY" in 580 official) ;; 581 compatible) ;; 582 default) ;; 583 *) echo "Invalid distro compatibility" \ 584 "level: $HAIKU_DISTRO_COMPATIBILITY" 585 exit 1;; 586 esac 587 shift 2 588 ;; 589 --enable-multiuser) HAIKU_ENABLE_MULTIUSER=1; shift 1;; 590 --host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;; 591 --include-gpl-addons) HAIKU_INCLUDE_GPL_ADDONS=1; shift 1;; 592 --include-patented-code) HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;; 593 --include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;; 594 --include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;; 595 -j*) buildCrossToolsJobs="$1"; shift 1;; 596 --no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;; 597 --target=*) TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;; 598 --target-arch) 599 assertparam "$1" $# 600 targetArch=$2 601 shift 2 602 if [ ! "$platform" = Haiku ]; then 603 echo "--target-arch can only be specified on Haiku." >&2 604 exit 1 605 fi 606 is_in_list "$targetArch" "$supportedTargetArchs" || ( 607 echo "Unsupported target architecture: \"$targetArch\"" >&2 608 exit 1 609 ) 610 haikuTargetArchs="$haikuTargetArchs $targetArch" 611 ;; 612 --target-board) 613 assertparam "$1" $# 614 HAIKU_BOOT_BOARD=$2 615 is_in_list "$HAIKU_BOOT_BOARD" "$supportedTargetBoards" || ( 616 echo "Unsupported target board: \"$HAIKU_BOOT_BOARD\"" >&2 617 exit 1 618 ) 619 shift 2 620 ;; 621 --use-clang) useClang=1; shift 1;; 622 --use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;; 623 --use-gcc-graphite) useGccGraphiteDefault=1; shift 1;; 624 --use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;; 625 --use-xattr) HAIKU_HOST_USE_XATTR=1; shift 1;; 626 --use-xattr-ref) HAIKU_HOST_USE_XATTR_REF=1; shift 1;; 627 --with-gdb) gdbSources=$2; shift 2;; 628 *) echo Invalid argument: \`$1\'; exit 1;; 629 esac 630done 631 632# detect the build platform 633case "${platform}" in 634 Darwin) HOST_PLATFORM=darwin ;; 635 FreeBSD) HOST_PLATFORM=freebsd 636 if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then 637 echo Unsupported platform: FreeBSD ${platformMachine} 638 exit 1 639 fi ;; 640 Haiku) HOST_PLATFORM=haiku_host ;; 641 Linux) HOST_PLATFORM=linux ;; 642 OpenBSD) HOST_PLATFORM=openbsd ;; 643 SunOS) HOST_PLATFORM=sunos ;; 644 CYGWIN_NT-*) HOST_PLATFORM=cygwin ;; 645 *) echo Unsupported platform: ${platform} 646 exit 1 ;; 647esac 648 649# check for case-sensitive filesystem 650mkdir haikuCaseTest 2>/dev/null 651mkdir haikucasetest 2>/dev/null 652caseInsensitive=$? 653rmdir haikuCaseTest haikucasetest 2>/dev/null 654if [ $caseInsensitive != 0 ]; then 655 echo "You need a case-sensitive file-system to build Haiku." 656 if [ $HOST_PLATFORM = "darwin" ]; then 657 echo "You can create a case-sensitive disk image using Disk Utility." 658 fi 659 exit 1 660fi 661 662# determine how to invoke sed with extended regexp support for non-GNU sed 663if [ $HOST_PLATFORM = "darwin" ]; then 664 HOST_EXTENDED_REGEX_SED="sed -E" 665fi 666 667# check if nasm can actually output ELF files 668# (the stock version in OSX can't) 669# XXX: should probably only test for x86* arch 670if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then 671 echo "$HAIKU_NASM cannot generate ELF files. Please install a working version." 672 if [ $HOST_PLATFORM = "darwin" ]; then 673 echo "You can install it from Mac Ports." 674 echo "Mac Ports is available at: http://www.macports.org/" 675 fi 676 exit 1 677fi 678 679# create output directory 680mkdir -p "$buildOutputDir" || exit 1 681 682if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then 683 invalidCommand=$sourceDir/build/scripts/host_build_only 684 HAIKU_AR=$invalidCommand 685 HAIKU_CC=$invalidCommand 686 HAIKU_LD=$invalidCommand 687 HAIKU_OBJCOPY=$invalidCommand 688 HAIKU_RANLIB=$invalidCommand 689 HAIKU_ELFEDIT=$invalidCommand 690 HAIKU_NASM=$invalidCommand 691 HAIKU_STRIP=$invalidCommand 692else 693 if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then 694 targetArchs="$HAIKU_PACKAGING_ARCHS" 695 fi 696 HAIKU_PACKAGING_ARCHS= 697 698 # On Haiku determine target architectures and tools automatically. 699 if [ -z "$targetArchs" ]; then 700 if [ $HOST_PLATFORM != haiku_host ]; then 701 echo "Please specify the build tools to use or build (via" \ 702 "--cross-tools-prefix or --build-cross-tools) or specify a" \ 703 "host-only build (--host-only)." >&2 704 echo "For more info, invoke $0 --help" 705 exit 1 706 fi 707 708 # determine primary architecture 709 targetArch=`package list -i /system/packages/haiku-*.hpkg \ 710 | sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'` 711 is_in_list "$targetArch" "$supportedTargetArchs" || ( 712 echo "Unsupported target architecture: \"$targetArch\"" >&2 713 exit 1 714 ) 715 targetArchs=$targetArch 716 717 set_default_value HAIKU_AR_$targetArch ar 718 set_default_value HAIKU_CC_$targetArch gcc 719 set_default_value HAIKU_LD_$targetArch ld 720 set_default_value HAIKU_OBJCOPY_$targetArch objcopy 721 set_default_value HAIKU_RANLIB_$targetArch ranlib 722 set_default_value HAIKU_ELFEDIT_$targetArch elfedit 723 set_default_value HAIKU_STRIP_$targetArch strip 724 725 # determine secondary architectures 726 for targetArch in $supportedTargetArchs; do 727 if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then 728 targetArchs="$targetArchs $targetArch" 729 set_default_value HAIKU_AR_$targetArch ar-$targetArch 730 set_default_value HAIKU_CC_$targetArch gcc-$targetArch 731 set_default_value HAIKU_LD_$targetArch ld-$targetArch 732 set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch 733 set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch 734 set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch 735 set_default_value HAIKU_STRIP_$targetArch strip-$targetArch 736 fi 737 done 738 739 # The target architectures might have been specified explicitly. 740 if [ -n "$haikuTargetArchs" ]; then 741 for targetArch in $haikuTargetArchs; do 742 is_in_list "$targetArch" "$targetArchs" || ( 743 echo "Unsupported target architecture: \"$targetArch\"." \ 744 "Only native architectures of the host platform can" \ 745 "be specified." >&2 746 exit 1 747 ) 748 done 749 targetArchs="$haikuTargetArchs" 750 fi 751 fi 752 753 isPrimaryArch=1 754 for targetArch in $targetArchs; do 755 # Note: targetArch is "unknown<n>" at this point, if a cross-tools 756 # prefix was specified. The standard_gcc_settings call below will get 757 # the actual architecture. 758 759 crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch` 760 761 # build cross tools from sources 762 if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then 763 crossToolsDir="$outputDir/cross-tools-$targetArch" 764 targetMachine=`get_variable buildCrossToolsMachine_$targetArch` 765 script="$buildCrossToolsScript" 766 scriptArgs= 767 if [ $targetArch != x86_gcc2 ]; then 768 script="${script}_gcc4" 769 scriptArgs="$targetMachine" 770 set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \ 771 $useGccGraphiteDefault 772 fi 773 secondaryArch= 774 if [ -z "$isPrimaryArch" ]; then 775 secondaryArch=$targetArch 776 fi 777 778 case $HOST_PLATFORM in 779 freebsd|openbsd) MAKE=gmake;; 780 *) MAKE=make;; 781 esac 782 783 MAKE=$MAKE \ 784 SECONDARY_ARCH=$secondaryArch \ 785 HAIKU_USE_GCC_GRAPHITE=`get_variable \ 786 HAIKU_USE_GCC_GRAPHITE_$targetArch` \ 787 HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \ 788 HAIKU_USE_GDB="$gdbSources" \ 789 "$script" $scriptArgs "$sourceDir" "$buildCrossTools" \ 790 "$crossToolsDir" $buildCrossToolsJobs || exit 1 791 crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-" 792 fi 793 794 # prepare gcc settings and get the actual target architecture 795 if [ $useClang = 1 ]; then 796 target=${crossToolsPrefix##*/} 797 target=${target%-} 798 gcc="clang -target ${target} -no-integrated-as" 799 else 800 gcc="${crossToolsPrefix}gcc" 801 fi 802 if [ -z "${crossToolsPrefix}" ]; then 803 gcc=`get_variable HAIKU_CC_$targetArch` 804 fi 805 standard_gcc_settings "$gcc" 806 targetArch=$standard_gcc_settings_targetArch 807 808 # set default values for flags 809 set_default_value HAIKU_CPPFLAGS_$targetArch "" 810 set_default_value HAIKU_CCFLAGS_$targetArch "" 811 set_default_value HAIKU_CXXFLAGS_$targetArch "" 812 set_default_value HAIKU_LDFLAGS_$targetArch "" 813 set_default_value HAIKU_ARFLAGS_$targetArch cru 814 set_default_value HAIKU_UNARFLAGS_$targetArch x 815 816 # Override the cross tools variables, if the tools were built or a 817 # prefix was specified. 818 if [ -n "$crossToolsPrefix" ]; then 819 get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar 820 get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld 821 get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy 822 get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib 823 get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip 824 825 case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in 826 4.*|5.*|6.*|7.*) 827 get_build_tool_path ELFEDIT_$targetArch \ 828 ${crossToolsPrefix}elfedit 829 ;; 830 esac 831 fi 832 833 # check whether the Haiku compiler really targets Haiku 834 targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch` 835 case "$targetMachine" in 836 *-*-haiku) ;; 837 *) 838 echo The compiler specified as Haiku target compiler is not a \ 839 valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 840 echo compiler: $HAIKU_CC 841 echo compiler is configured for target: $targetMachine 842 exit 1 ;; 843 esac 844 845 HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch" 846 isPrimaryArch= 847 done 848fi 849 850# Generate BuildConfig 851cat << EOF > "$buildConfigFile" 852# BuildConfig 853# Note: This file has been automatically generated by configure with the 854# following arguments: 855# ${configureArgs} 856 857TARGET_PLATFORM ?= "${TARGET_PLATFORM}" ; 858HOST_PLATFORM ?= "${HOST_PLATFORM}" ; 859 860HAIKU_INCLUDE_GPL_ADDONS ?= "${HAIKU_INCLUDE_GPL_ADDONS}" ; 861HAIKU_INCLUDE_PATENTED_CODE ?= "${HAIKU_INCLUDE_PATENTED_CODE}" ; 862HAIKU_INCLUDE_SOURCES ?= "${HAIKU_INCLUDE_SOURCES}" ; 863HAIKU_INCLUDE_3RDPARTY ?= "${HAIKU_INCLUDE_3RDPARTY}" ; 864HAIKU_ENABLE_MULTIUSER ?= "${HAIKU_ENABLE_MULTIUSER}" ; 865HAIKU_DISTRO_COMPATIBILITY ?= "${HAIKU_DISTRO_COMPATIBILITY}" ; 866HAIKU_USE_GCC_PIPE ?= "${HAIKU_USE_GCC_PIPE}" ; 867HAIKU_HOST_USE_32BIT ?= "${HAIKU_HOST_USE_32BIT}" ; 868HAIKU_HOST_USE_XATTR ?= "${HAIKU_HOST_USE_XATTR}" ; 869HAIKU_HOST_USE_XATTR_REF ?= "${HAIKU_HOST_USE_XATTR_REF}" ; 870HAIKU_HOST_BUILD_ONLY ?= "${HAIKU_HOST_BUILD_ONLY}" ; 871 872HAIKU_PACKAGING_ARCHS ?= ${HAIKU_PACKAGING_ARCHS} ; 873 874HAIKU_NO_DOWNLOADS ?= "${HAIKU_NO_DOWNLOADS}" ; 875 876HAIKU_BUILD_ATTRIBUTES_DIR ?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ; 877 878HAIKU_NASM ?= ${HAIKU_NASM} ; 879HAIKU_BOOT_BOARD ?= ${HAIKU_BOOT_BOARD} ; 880 881HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ; 882HOST_GCC_RAW_VERSION ?= ${HOST_GCC_RAW_VERSION} ; 883HOST_GCC_MACHINE ?= ${HOST_GCC_MACHINE} ; 884HOST_LD ?= ${HOST_GCC_LD} ; 885HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ; 886HOST_SHA256 ?= ${HOST_SHA256} ; 887 888HOST_HAIKU_PORTER ?= ${HOST_HAIKU_PORTER} ; 889HAIKU_PORTS ?= ${HAIKU_PORTS} ; 890HAIKU_PORTS_CROSS ?= ${HAIKU_PORTS_CROSS} ; 891HAIKU_IS_BOOTSTRAP ?= ${HAIKU_IS_BOOTSTRAP} ; 892 893EOF 894 895for targetArch in $HAIKU_PACKAGING_ARCHS; do 896 variables=" 897 HAIKU_GCC_RAW_VERSION HAIKU_GCC_RAW_VERSION 898 HAIKU_GCC_MACHINE HAIKU_GCC_MACHINE 899 HAIKU_GCC_LIB_DIR HAIKU_GCC_LIB_DIR 900 HAIKU_CPU HAIKU_CPU 901 HAIKU_BOOT_LIBGCC HAIKU_BOOT_LIBGCC 902 HAIKU_BOOT_LIBSUPC++ HAIKU_BOOT_LIBSUPCXX 903 HAIKU_AR HAIKU_AR 904 HAIKU_CC HAIKU_CC 905 HAIKU_CC_IS_CLANG HAIKU_CC_IS_CLANG 906 HAIKU_LD HAIKU_LD 907 HAIKU_OBJCOPY HAIKU_OBJCOPY 908 HAIKU_RANLIB HAIKU_RANLIB 909 HAIKU_ELFEDIT HAIKU_ELFEDIT 910 HAIKU_STRIP HAIKU_STRIP 911 HAIKU_CPPFLAGS HAIKU_CPPFLAGS 912 HAIKU_CCFLAGS HAIKU_CCFLAGS 913 HAIKU_C++FLAGS HAIKU_CXXFLAGS 914 HAIKU_LDFLAGS HAIKU_LDFLAGS 915 HAIKU_ARFLAGS HAIKU_ARFLAGS 916 HAIKU_UNARFLAGS HAIKU_UNARFLAGS 917 HAIKU_USE_GCC_GRAPHITE HAIKU_USE_GCC_GRAPHITE 918 " 919 set -- $variables 920 while [ $# -ge 2 ]; do 921 value=`get_variable ${2}_$targetArch` 922 echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile" 923 shift 2 924 done 925 926 # For variables that may have long values, distribute them over multiple 927 # lines so that jam doesn't hit the maximum line length. 928 variables=" 929 HAIKU_BOOT_C++_HEADERS_DIR HAIKU_BOOT_CXX_HEADERS_DIR 930 " 931 set -- $variables 932 while [ $# -ge 2 ]; do 933 echo "${1}_${targetArch} ?= " >> "$buildConfigFile" 934 get_variable ${2}_$targetArch | xargs -n 1 echo " " \ 935 >> "$buildConfigFile" 936 echo " ;" >> "$buildConfigFile" 937 shift 2 938 done 939done 940 941 942# Generate a boot strap Jamfile in the output directory. 943 944cat << EOF > $outputDir/Jamfile 945# automatically generated Jamfile 946 947HAIKU_TOP = ${sourceDir} ; 948HAIKU_OUTPUT_DIR = ${outputDir} ; 949 950include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 951 952EOF 953