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