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,raspberry_pi,verdex. 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 local libgcc=${gccdir}/libgcc.a 252 253 # determine architecture from machine triple 254 case $gccMachine in 255 arm-*) targetCpu=arm;; 256 i?86-*) targetCpu=x86;; 257 m68k-*) targetCpu=m68k;; 258 powerpc-*) targetCpu=ppc;; 259 x86_64-*) targetCpu=x86_64;; 260 *) 261 echo "Unsupported gcc target machine: $gccMachine" >&2 262 exit 1 263 ;; 264 esac 265 266 local targetArch=$targetCpu 267 local staticLibStdCxx 268 local sharedLibStdCxx 269 local staticLibSupCxx 270 local sharedLibSupCxx 271 local kernelLibgcc 272 local cxxHeaders 273 274 case $gccRawVersion in 275 4.*) 276 # for gcc 4 we use the libstdc++ and libsupc++ that come with the 277 # compiler 278 staticLibStdCxx=`$gcc -print-file-name=libstdc++.a` 279 sharedLibStdCxx=`$gcc -print-file-name=libstdc++.so` 280 staticLibSupCxx=`$gcc -print-file-name=libsupc++.a` 281 sharedLibSupCxx=`$gcc -print-file-name=libsupc++.so` 282 283 # If the architecture has separate runtime libraries for the 284 # kernel, use them. 285 kernelLibgcc=`$gcc -print-file-name=libgcc-kernel.a` 286 if [ $kernelLibgcc = libgcc-kernel.a ]; then 287 kernelLibgcc=$libgcc 288 fi 289 kernelLibSupCxx=`$gcc -print-file-name=libsupc++-kernel.a` 290 if [ $kernelLibSupCxx = libsupc++-kernel.a ]; then 291 kernelLibSupCxx=$staticLibSupCxx 292 fi 293 294 local headersBase=$gccdir/../../../.. 295 local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion 296 if [ ! -d $headers ]; then 297 headers=$headersBase/include/c++/$gccRawVersion 298 fi 299 300 cxxHeaders=$headers 301 for d in $gccMachine backward ext; do 302 # Note: We need the line break, otherwise the line might become 303 # too long for jam (512 bytes max). 304 cxxHeaders="$cxxHeaders $headers/$d" 305 done 306 307 # Unset the HAIKU_{SHARED,STATIC}_LIB{STD,SUP}CXX variables, if the 308 # compiler didn't give us actual file names. Otherwise resolve 309 # symlinks to avoid problems when copying the libraries to the 310 # image. 311 312 if [ $staticLibStdCxx = libstdc++.a ]; then 313 staticLibStdCxx= 314 else 315 staticLibStdCxx=`$readlink $staticLibStdCxx` 316 fi 317 318 if [ $sharedLibStdCxx = libstdc++.so ]; then 319 sharedLibStdCxx= 320 else 321 sharedLibStdCxx=`$readlink $sharedLibStdCxx` 322 fi 323 324 if [ $staticLibSupCxx = libsupc++.a ]; then 325 staticLibSupCxx= 326 else 327 staticLibSupCxx=`$readlink $staticLibSupCxx` 328 fi 329 330 if [ $sharedLibSupCxx = libsupc++.so ]; then 331 sharedLibSupCxx= 332 else 333 sharedLibSupCxx=`$readlink $sharedLibSupCxx` 334 fi 335 ;; 336 2.9*) 337 # check for correct (most up-to-date) legacy compiler and complain 338 # if an older one is installed 339 if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then 340 echo "GCC version $haikuRequiredLegacyGCCVersion is required!"; 341 echo "Please download it from www.haiku-os.org..."; 342 exit 1; 343 fi 344 345 kernelLibgcc=$libgcc 346 kernelLibSupCxx= 347 targetArch=x86_gcc2 348 ;; 349 esac 350 351 local bootLibgcc 352 local bootLibSupCxx 353 local bootCxxHeaders 354 case $gccMachine in 355 x86_64-*) 356 # Boot loader is 32-bit, need the 32-bit libs and c++ config 357 bootLibgcc=`$gcc -m32 -print-libgcc-file-name` 358 bootLibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a` 359 360 local headersBase=$gccdir/../../../.. 361 local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion 362 if [ ! -d $headers ]; then 363 headers=$headersBase/include/c++/$gccRawVersion 364 fi 365 bootCxxHeaders="$headers/$gccMachine/32" 366 ;; 367 *) 368 bootLibgcc=$libgcc 369 bootLibSupCxx=$staticLibSupCxx 370 ;; 371 esac 372 373 # determine whether graphite loop optimization should/can be used 374 local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu` 375 if [ -z "$useGraphite" ]; then 376 useGraphite=$useGccGraphiteDefault 377 fi 378 379 if [ "$useGraphite" != 0 ]; then 380 UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1` 381 if [ $? != 0 ]; then 382 echo "GCC Graphite loop optimizations cannot be used on $targetArch" 383 useGraphite=0 384 fi 385 fi 386 387 set_variable HAIKU_CPU_$targetArch $targetCpu 388 389 get_build_tool_path CC_$targetArch "$gcc" 390 if [ $useClang = 1 ]; then 391 # The get_build_tool_path above is needed to get the path to the rest 392 # of the build tools 393 local path=`dirname $(get_variable HAIKU_CC_$targetArch)` 394 set_variable HAIKU_CC_$targetArch \ 395 "PATH=\\\"$path:\\\$PATH\\\" clang -target $gccMachine" 396 set_variable HAIKU_CC_IS_CLANG_$targetArch 1 397 else 398 set_variable HAIKU_CC_IS_CLANG_$targetArch 0 399 fi 400 set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion 401 set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine 402 set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir 403 set_variable HAIKU_GCC_LIBGCC_$targetArch $libgcc 404 set_variable HAIKU_GCC_HEADERS_DIR_$targetArch \ 405 "${gccdir}/include ${gccdir}/include-fixed" 406 set_variable HAIKU_STATIC_LIBSTDCXX_$targetArch "$staticLibStdCxx" 407 set_variable HAIKU_SHARED_LIBSTDCXX_$targetArch "$sharedLibStdCxx" 408 set_variable HAIKU_STATIC_LIBSUPCXX_$targetArch "$staticLibSupCxx" 409 set_variable HAIKU_SHARED_LIBSUPCXX_$targetArch "$sharedLibSupCxx" 410 set_variable HAIKU_KERNEL_LIBSUPCXX_$targetArch "$kernelLibSupCxx" 411 set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx" 412 set_variable HAIKU_KERNEL_LIBGCC_$targetArch $kernelLibgcc 413 set_variable HAIKU_CXX_HEADERS_DIR_$targetArch "$cxxHeaders" 414 set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc 415 set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders" 416 set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite 417 418 standard_gcc_settings_targetArch=$targetArch 419} 420 421# set_variable 422# 423# Set the value of a variable. 424# 425set_variable() 426{ 427 eval "$1=\"$2\"" 428} 429 430# get_variable 431# 432# Echo the value of a variable. 433# 434get_variable() 435{ 436 eval "echo \${$1}" 437} 438 439# set_default_value 440# 441# Set the value for a variable, if no value is set yet. 442# 443set_default_value() 444{ 445 eval "$1=\${$1-$2}" 446} 447 448# get_build_tool_path 449# 450# Gets a usable absolute path of a build tool. 451# 452get_build_tool_path() 453{ 454 local var="HAIKU_$1" 455 local path=$2 456 457 if [ -f "$path" ]; then 458 # get absolute path 459 local oldPwd="`pwd`" 460 cd "`dirname "$path"`" 461 path="`pwd`/`basename "$path"`" 462 cd $oldPwd 463 else 464 which "$path" > /dev/null 2>&1 || { 465 echo "Build tool \"$path\" not found." >&2 466 exit 1 467 } 468 fi 469 470 eval "$var=$path" 471} 472 473is_in_list() 474{ 475 local element 476 for element in $2; do 477 if [ "$1" = "$element" ]; then 478 return 0 479 fi 480 done 481 return 1 482} 483 484# check for no params, --help or -h and show usage immediately 485if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then 486 usage; exit 0; 487fi 488 489 490# get cwd and the source directory 491currentDir=`pwd` 492cd `dirname "$0"` 493sourceDir=`pwd` 494cd "$currentDir" 495 496# backup the passed arguments 497configureArgs="$@" 498 499# internal default parameter values 500# 501platform=`uname` 502platformMachine=`uname -m` 503targetArchs= 504buildCrossTools= 505buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 506buildCrossToolsJobs= 507useClang=0 508useGccGraphiteDefault=0 509unknownArchIndex=1 510haikuTargetArchs= 511 512if [ -z "$CC" ]; then 513 CC=gcc 514fi 515 516# exported (BuildSetup) default parameter values 517# 518HOST_GCC_RAW_VERSION=`$CC -dumpversion` 519HOST_GCC_MACHINE=`$CC -dumpmachine` 520HAIKU_INCLUDE_GPL_ADDONS=0 521HAIKU_INCLUDE_PATENTED_CODE=0 522HAIKU_INCLUDE_SOURCES=0 523HAIKU_INCLUDE_3RDPARTY=0 524HAIKU_ENABLE_MULTIUSER=0 525HAIKU_DISTRO_COMPATIBILITY=default 526TARGET_PLATFORM=haiku 527HAIKU_USE_GCC_PIPE=0 528HAIKU_HOST_USE_32BIT=0 529HAIKU_HOST_USE_XATTR=0 530HAIKU_HOST_USE_XATTR_REF=0 531HAIKU_HOST_BUILD_ONLY=0 532HOST_EXTENDED_REGEX_SED="sed -r" 533HOST_GCC_LD=`$CC -print-prog-name=ld` 534HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy` 535SFDISK_BINARY=sfdisk 536HOST_SFDISK=$SFDISK_BINARY 537HOST_SHA256= 538HOST_HAIKU_PORTER= 539HAIKU_PORTS= 540HAIKU_PORTS_CROSS= 541HAIKU_BOOT_BOARD= 542HAIKU_NO_DOWNLOADS=0 543 544HAIKU_PACKAGING_ARCHS= 545 546set_default_value HAIKU_NASM nasm 547 548if sha256sum < /dev/null > /dev/null 2>&1; then 549 HOST_SHA256=sha256sum 550elif sha256 < /dev/null > /dev/null 2>&1; then 551 HOST_SHA256="sha256 -q" 552elif shasum < /dev/null > /dev/null 2>&1; then 553 HOST_SHA256="shasum -a 256" 554else 555 echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2 556 exit 1 557fi 558 559haikuRequiredLegacyGCCVersion="2.95.3-haiku-2014_07_26" 560export haikuRequiredLegacyGCCVersion 561 # version of legacy gcc required to build haiku 562supportedTargetArchs=" 563 arm 564 m68k 565 ppc 566 x86 567 x86_64 568 x86_gcc2 569 " 570supportedTargetBoards=" 571 beagle 572 raspberry_pi 573 verdex 574 " 575 576# determine output directory 577if [ "$currentDir" = "$sourceDir" ]; then 578 outputDir=$currentDir/generated 579else 580 outputDir=$currentDir 581fi 582buildOutputDir="$outputDir/build" 583HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes" 584buildConfigFile="$buildOutputDir/BuildConfig" 585 586# check for update request 587if [ "$1" = "--update" ]; then 588 if ! [ -e "$buildConfigFile" ]; then 589 echo $0 --update: \'$buildConfigFile\' not found - updating not possible. 590 exit 1 591 fi 592 if ! type perl >/dev/null 2>&1; then 593 echo $0 --update: \'perl\' not found - updating not possible. 594 exit 1 595 fi 596 # convert BuildConfig from jam format to shell format and evaluate it 597 shellConfigFile="${buildConfigFile}.shell" 598 perl "$sourceDir/build/scripts/convert_build_config_to_shell_format.pl" \ 599 <"$buildConfigFile" >"$shellConfigFile" 600 . "$shellConfigFile" 601 rm "$shellConfigFile" 602 shift 603fi 604 605# parse parameters 606# 607while [ $# -gt 0 ] ; do 608 case "$1" in 609 --bootstrap) 610 assertparams "$1" 3 $# 611 HOST_HAIKU_PORTER="`absolute_path $2`" 612 HAIKU_PORTS_CROSS="`absolute_path $3`" 613 HAIKU_PORTS="`absolute_path $4`" 614 check_file_exists "$HOST_HAIKU_PORTER" || ( 615 echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2 616 exit 1 617 ) 618 check_dir_exists "$HAIKU_PORTS" || ( 619 echo "Non-existent directory $HAIKU_PORTS" >&2 620 exit 1 621 ) 622 check_dir_exists "$HAIKU_PORTS_CROSS" || ( 623 echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2 624 exit 1 625 ) 626 shift 4 627 ;; 628 --build-cross-tools) 629 if [ -z "$buildCrossTools" ]; then 630 assertparams "$1" 2 $# 631 targetArch=$2 632 buildCrossTools=$3 633 shift 3 634 else 635 assertparam "$1" $# 636 targetArch=$2 637 shift 2 638 fi 639 case "$targetArch" in 640 x86_gcc2) targetMachine=i586-pc-haiku;; 641 x86) targetMachine=i586-pc-haiku;; 642 x86_64) targetMachine=x86_64-unknown-haiku;; 643 ppc) targetMachine=powerpc-apple-haiku;; 644 m68k) targetMachine=m68k-unknown-haiku;; 645 arm) targetMachine=arm-unknown-haiku;; 646 *) 647 echo "Unsupported target architecture: $2" >&2 648 exit 1 649 ;; 650 esac 651 set_variable buildCrossToolsMachine_$targetArch $targetMachine 652 targetArchs="$targetArchs $targetArch" 653 HAIKU_PACKAGING_ARCHS= 654 ;; 655 --cross-tools-prefix) 656 assertparam "$1" $# 657 targetArch=unknown${unknownArchIndex} 658 set_variable crossToolsPrefix_$targetArch "$2" 659 targetArchs="$targetArchs $targetArch" 660 HAIKU_PACKAGING_ARCHS= 661 unknownArchIndex=$(($unknownArchIndex + 1)) 662 shift 2 663 ;; 664 --distro-compatibility) 665 assertparam "$1" $# 666 HAIKU_DISTRO_COMPATIBILITY=$2 667 case "$HAIKU_DISTRO_COMPATIBILITY" in 668 official) ;; 669 compatible) ;; 670 default) ;; 671 *) echo "Invalid distro compatibility" \ 672 "level: $HAIKU_DISTRO_COMPATIBILITY" 673 exit 1;; 674 esac 675 shift 2 676 ;; 677 --enable-multiuser) HAIKU_ENABLE_MULTIUSER=1; shift 1;; 678 --host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;; 679 --include-gpl-addons) HAIKU_INCLUDE_GPL_ADDONS=1; shift 1;; 680 --include-patented-code) HAIKU_INCLUDE_PATENTED_CODE=1; shift 1;; 681 --include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;; 682 --include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;; 683 -j*) buildCrossToolsJobs="$1"; shift 1;; 684 --no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;; 685 --target=*) TARGET_PLATFORM=`echo $1 | cut -d'=' -f2-`; shift 1;; 686 --target-arch) 687 assertparam "$1" $# 688 targetArch=$2 689 shift 2 690 if [ ! "$platform" = Haiku ]; then 691 echo "--target-arch can only be specified on Haiku." >&2 692 exit 1 693 fi 694 is_in_list "$targetArch" "$supportedTargetArchs" || ( 695 echo "Unsupported target architecture: \"$targetArch\"" >&2 696 exit 1 697 ) 698 haikuTargetArchs="$haikuTargetArchs $targetArch" 699 ;; 700 --target-board) 701 assertparam "$1" $# 702 HAIKU_BOOT_BOARD=$2 703 is_in_list "$HAIKU_BOOT_BOARD" "$supportedTargetBoards" || ( 704 echo "Unsupported target board: \"$HAIKU_BOOT_BOARD\"" >&2 705 exit 1 706 ) 707 shift 2 708 ;; 709 --use-clang) useClang=1; shift 1;; 710 --use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;; 711 --use-gcc-graphite) useGccGraphiteDefault=1; shift 1;; 712 --use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;; 713 --use-xattr) HAIKU_HOST_USE_XATTR=1; shift 1;; 714 --use-xattr-ref) HAIKU_HOST_USE_XATTR_REF=1; shift 1;; 715 *) echo Invalid argument: \`$1\'; exit 1;; 716 esac 717done 718 719# detect the build platform 720case "${platform}" in 721 Darwin) HOST_PLATFORM=darwin ;; 722 FreeBSD) HOST_PLATFORM=freebsd 723 SFDISK_BINARY=sfdisk-linux 724 if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then 725 echo Unsupported platform: FreeBSD ${platformMachine} 726 exit 1 727 fi ;; 728 Haiku) HOST_PLATFORM=haiku_host ;; 729 Linux) HOST_PLATFORM=linux ;; 730 OpenBSD) HOST_PLATFORM=openbsd ;; 731 SunOS) HOST_PLATFORM=sunos ;; 732 CYGWIN_NT-*) HOST_PLATFORM=cygwin ;; 733 *) echo Unsupported platform: ${platform} 734 exit 1 ;; 735esac 736 737# check common locations for sfdisk 738for sfdiskDir in /sbin /usr/sbin /usr/local/sbin ; do 739 if [ -e ${sfdiskDir}/${SFDISK_BINARY} ]; then 740 HOST_SFDISK=${sfdiskDir}/${SFDISK_BINARY} 741 fi 742done 743 744# check for case-sensitive filesystem 745mkdir haikuCaseTest 2>/dev/null 746mkdir haikucasetest 2>/dev/null 747caseInsensitive=$? 748rmdir haikuCaseTest haikucasetest 2>/dev/null 749if [ $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 and use" 753 echo "it to store the Haiku sources on." 754 fi 755 exit 1 756fi 757 758# determine how to invoke sed with extended regexp support for non-GNU sed 759if [ $HOST_PLATFORM = "darwin" ]; then 760 HOST_EXTENDED_REGEX_SED="sed -E" 761fi 762 763# create output directory 764mkdir -p "$buildOutputDir" || exit 1 765 766if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then 767 invalidCommand=$sourceDir/build/scripts/host_build_only 768 HAIKU_AR=$invalidCommand 769 HAIKU_CC=$invalidCommand 770 HAIKU_LD=$invalidCommand 771 HAIKU_OBJCOPY=$invalidCommand 772 HAIKU_RANLIB=$invalidCommand 773 HAIKU_ELFEDIT=$invalidCommand 774 HAIKU_NASM=$invalidCommand 775 HAIKU_STRIP=$invalidCommand 776else 777 if [ -n "$HAIKU_PACKAGING_ARCHS" ]; then 778 targetArchs="$HAIKU_PACKAGING_ARCHS" 779 fi 780 HAIKU_PACKAGING_ARCHS= 781 782 # On Haiku determine target architectures and tools automatically. 783 if [ -z "$targetArchs" ]; then 784 if [ $HOST_PLATFORM != haiku_host ]; then 785 echo "Please specify the build tools to use or build (via" \ 786 "--cross-tools-prefix or --build-cross-tools) or specify a" \ 787 "host-only build (--host-only)." >&2 788 exit 1 789 fi 790 791 # determine primary architecture 792 targetArch=`package list -i /system/packages/haiku-*.hpkg \ 793 | sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'` 794 is_in_list "$targetArch" "$supportedTargetArchs" || ( 795 echo "Unsupported target architecture: \"$targetArch\"" >&2 796 exit 1 797 ) 798 targetArchs=$targetArch 799 800 set_default_value HAIKU_AR_$targetArch ar 801 set_default_value HAIKU_CC_$targetArch gcc 802 set_default_value HAIKU_LD_$targetArch ld 803 set_default_value HAIKU_OBJCOPY_$targetArch objcopy 804 set_default_value HAIKU_RANLIB_$targetArch ranlib 805 set_default_value HAIKU_ELFEDIT_$targetArch elfedit 806 set_default_value HAIKU_STRIP_$targetArch strip 807 808 # determine secondary architectures 809 for targetArch in $supportedTargetArchs; do 810 if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then 811 targetArchs="$targetArchs $targetArch" 812 set_default_value HAIKU_AR_$targetArch ar-$targetArch 813 set_default_value HAIKU_CC_$targetArch gcc-$targetArch 814 set_default_value HAIKU_LD_$targetArch ld-$targetArch 815 set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch 816 set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch 817 set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch 818 set_default_value HAIKU_STRIP_$targetArch strip-$targetArch 819 fi 820 done 821 822 # The target architectures might have been specified explicitly. 823 if [ -n "$haikuTargetArchs" ]; then 824 for targetArch in $haikuTargetArchs; do 825 is_in_list "$targetArch" "$targetArchs" || ( 826 echo "Unsupported target architecture: \"$targetArch\"." \ 827 "Only native architectures of the host platform can" \ 828 "be specified." >&2 829 exit 1 830 ) 831 done 832 targetArchs="$haikuTargetArchs" 833 fi 834 fi 835 836 isPrimaryArch=1 837 for targetArch in $targetArchs; do 838 # Note: targetArch is "unknown<n>" at this point, if a cross-tools 839 # prefix was specified. The standard_gcc_settings call below will get 840 # the actual architecture. 841 842 crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch` 843 844 # build cross tools from sources 845 if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then 846 crossToolsDir="$outputDir/cross-tools-$targetArch" 847 targetMachine=`get_variable buildCrossToolsMachine_$targetArch` 848 script="$buildCrossToolsScript" 849 scriptArgs= 850 if [ $targetArch != x86_gcc2 ]; then 851 script="${script}_gcc4" 852 scriptArgs="$targetMachine" 853 set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \ 854 $useGccGraphiteDefault 855 fi 856 secondaryArch= 857 if [ -z "$isPrimaryArch" ]; then 858 secondaryArch=$targetArch 859 fi 860 861 case $HOST_PLATFORM in 862 freebsd|openbsd) MAKE=gmake;; 863 *) MAKE=make;; 864 esac 865 866 MAKE=$MAKE \ 867 SECONDARY_ARCH=$secondaryArch \ 868 HAIKU_USE_GCC_GRAPHITE=`get_variable \ 869 HAIKU_USE_GCC_GRAPHITE_$targetArch` \ 870 HAIKU_USE_GCC_PIPE=$HAIKU_USE_GCC_PIPE \ 871 "$script" $scriptArgs "$sourceDir" "$buildCrossTools" \ 872 "$crossToolsDir" $buildCrossToolsJobs || exit 1 873 crossToolsPrefix="$crossToolsDir/bin/${targetMachine}-" 874 fi 875 876 # prepare gcc settings and get the actual target architecture 877 gcc="${crossToolsPrefix}gcc" 878 if [ -z "${crossToolsPrefix}" ]; then 879 gcc=`get_variable HAIKU_CC_$targetArch` 880 fi 881 standard_gcc_settings "$gcc" 882 targetArch=$standard_gcc_settings_targetArch 883 884 # set default values for flags 885 set_default_value HAIKU_CPPFLAGS_$targetArch "" 886 set_default_value HAIKU_CCFLAGS_$targetArch "" 887 set_default_value HAIKU_CXXFLAGS_$targetArch "" 888 set_default_value HAIKU_LDFLAGS_$targetArch "" 889 set_default_value HAIKU_ARFLAGS_$targetArch cru 890 set_default_value HAIKU_UNARFLAGS_$targetArch x 891 892 # Override the cross tools variables, if the tools were built or a 893 # prefix was specified. 894 if [ -n "$crossToolsPrefix" ]; then 895 get_build_tool_path AR_$targetArch ${crossToolsPrefix}ar 896 get_build_tool_path LD_$targetArch ${crossToolsPrefix}ld 897 get_build_tool_path OBJCOPY_$targetArch ${crossToolsPrefix}objcopy 898 get_build_tool_path RANLIB_$targetArch ${crossToolsPrefix}ranlib 899 get_build_tool_path STRIP_$targetArch ${crossToolsPrefix}strip 900 901 case `get_variable HAIKU_GCC_RAW_VERSION_$targetArch` in 902 4.*) 903 get_build_tool_path ELFEDIT_$targetArch \ 904 ${crossToolsPrefix}elfedit 905 ;; 906 esac 907 fi 908 909 # Get the libgcc objects. We couldn't do that in standard_gcc_settings, 910 # since we need "ar", which may be set later. 911 ar=`get_variable HAIKU_AR_$targetArch` 912 libgcc=`get_variable HAIKU_GCC_LIBGCC_$targetArch` 913 set_variable HAIKU_GCC_LIBGCC_OBJECTS_$targetArch \ 914 "`$ar t $libgcc | grep -v eabi.o`" 915 # Note: We filter out eabi.o. It's present in gcc's libgcc for PPC 916 # and neither needed nor wanted. 917 918 # check whether the Haiku compiler really targets Haiku 919 targetMachine=`get_variable HAIKU_GCC_MACHINE_$targetArch` 920 case "$targetMachine" in 921 *-*-haiku) ;; 922 *) 923 echo The compiler specified as Haiku target compiler is not a \ 924 valid Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 925 echo compiler: $HAIKU_CC 926 echo compiler is configured for target: $targetMachine 927 exit 1 ;; 928 esac 929 930 HAIKU_PACKAGING_ARCHS="$HAIKU_PACKAGING_ARCHS $targetArch" 931 isPrimaryArch= 932 done 933fi 934 935# Generate BuildConfig 936cat << EOF > "$buildConfigFile" 937# BuildConfig 938# Note: This file has been automatically generated by configure with the 939# following arguments: 940# ${configureArgs} 941 942TARGET_PLATFORM ?= "${TARGET_PLATFORM}" ; 943HOST_PLATFORM ?= "${HOST_PLATFORM}" ; 944 945HAIKU_INCLUDE_GPL_ADDONS ?= "${HAIKU_INCLUDE_GPL_ADDONS}" ; 946HAIKU_INCLUDE_PATENTED_CODE ?= "${HAIKU_INCLUDE_PATENTED_CODE}" ; 947HAIKU_INCLUDE_SOURCES ?= "${HAIKU_INCLUDE_SOURCES}" ; 948HAIKU_INCLUDE_3RDPARTY ?= "${HAIKU_INCLUDE_3RDPARTY}" ; 949HAIKU_ENABLE_MULTIUSER ?= "${HAIKU_ENABLE_MULTIUSER}" ; 950HAIKU_DISTRO_COMPATIBILITY ?= "${HAIKU_DISTRO_COMPATIBILITY}" ; 951HAIKU_USE_GCC_PIPE ?= "${HAIKU_USE_GCC_PIPE}" ; 952HAIKU_HOST_USE_32BIT ?= "${HAIKU_HOST_USE_32BIT}" ; 953HAIKU_HOST_USE_XATTR ?= "${HAIKU_HOST_USE_XATTR}" ; 954HAIKU_HOST_USE_XATTR_REF ?= "${HAIKU_HOST_USE_XATTR_REF}" ; 955HAIKU_HOST_BUILD_ONLY ?= "${HAIKU_HOST_BUILD_ONLY}" ; 956 957HAIKU_PACKAGING_ARCHS ?= ${HAIKU_PACKAGING_ARCHS} ; 958 959HAIKU_NO_DOWNLOADS ?= "${HAIKU_NO_DOWNLOADS}" ; 960 961HAIKU_BUILD_ATTRIBUTES_DIR ?= ${HAIKU_BUILD_ATTRIBUTES_DIR} ; 962 963HAIKU_NASM ?= ${HAIKU_NASM} ; 964HAIKU_BOOT_BOARD ?= ${HAIKU_BOOT_BOARD} ; 965 966HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ; 967HOST_GCC_RAW_VERSION ?= ${HOST_GCC_RAW_VERSION} ; 968HOST_GCC_MACHINE ?= ${HOST_GCC_MACHINE} ; 969HOST_LD ?= ${HOST_GCC_LD} ; 970HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ; 971HOST_SFDISK ?= ${HOST_SFDISK} ; 972HOST_SHA256 ?= ${HOST_SHA256} ; 973 974HOST_HAIKU_PORTER ?= ${HOST_HAIKU_PORTER} ; 975HAIKU_PORTS ?= ${HAIKU_PORTS} ; 976HAIKU_PORTS_CROSS ?= ${HAIKU_PORTS_CROSS} ; 977 978EOF 979 980for targetArch in $HAIKU_PACKAGING_ARCHS; do 981 variables=" 982 HAIKU_GCC_RAW_VERSION HAIKU_GCC_RAW_VERSION 983 HAIKU_GCC_MACHINE HAIKU_GCC_MACHINE 984 HAIKU_GCC_LIB_DIR HAIKU_GCC_LIB_DIR 985 HAIKU_GCC_LIBGCC HAIKU_GCC_LIBGCC 986 HAIKU_CPU HAIKU_CPU 987 HAIKU_STATIC_LIBSTDC++ HAIKU_STATIC_LIBSTDCXX 988 HAIKU_SHARED_LIBSTDC++ HAIKU_SHARED_LIBSTDCXX 989 HAIKU_STATIC_LIBSUPC++ HAIKU_STATIC_LIBSUPCXX 990 HAIKU_SHARED_LIBSUPC++ HAIKU_SHARED_LIBSUPCXX 991 HAIKU_KERNEL_LIBGCC HAIKU_KERNEL_LIBGCC 992 HAIKU_KERNEL_LIBSUPC++ HAIKU_KERNEL_LIBSUPCXX 993 HAIKU_BOOT_LIBGCC HAIKU_BOOT_LIBGCC 994 HAIKU_BOOT_LIBSUPC++ HAIKU_BOOT_LIBSUPCXX 995 HAIKU_AR HAIKU_AR 996 HAIKU_CC HAIKU_CC 997 HAIKU_CC_IS_CLANG HAIKU_CC_IS_CLANG 998 HAIKU_LD HAIKU_LD 999 HAIKU_OBJCOPY HAIKU_OBJCOPY 1000 HAIKU_RANLIB HAIKU_RANLIB 1001 HAIKU_ELFEDIT HAIKU_ELFEDIT 1002 HAIKU_STRIP HAIKU_STRIP 1003 HAIKU_CPPFLAGS HAIKU_CPPFLAGS 1004 HAIKU_CCFLAGS HAIKU_CCFLAGS 1005 HAIKU_C++FLAGS HAIKU_CXXFLAGS 1006 HAIKU_LDFLAGS HAIKU_LDFLAGS 1007 HAIKU_ARFLAGS HAIKU_ARFLAGS 1008 HAIKU_UNARFLAGS HAIKU_UNARFLAGS 1009 HAIKU_USE_GCC_GRAPHITE HAIKU_USE_GCC_GRAPHITE 1010 " 1011 set -- $variables 1012 while [ $# -ge 2 ]; do 1013 value=`get_variable ${2}_$targetArch` 1014 echo "${1}_${targetArch} ?= $value ;" >> "$buildConfigFile" 1015 shift 2 1016 done 1017 1018 # For variables that may have long values, distribute them over multiple 1019 # lines so that jam doesn't hit the maximum line length. 1020 variables=" 1021 HAIKU_GCC_HEADERS_DIR HAIKU_GCC_HEADERS_DIR 1022 HAIKU_C++_HEADERS_DIR HAIKU_CXX_HEADERS_DIR 1023 HAIKU_BOOT_C++_HEADERS_DIR HAIKU_BOOT_CXX_HEADERS_DIR 1024 HAIKU_GCC_LIBGCC_OBJECTS HAIKU_GCC_LIBGCC_OBJECTS 1025 " 1026 set -- $variables 1027 while [ $# -ge 2 ]; do 1028 echo "${1}_${targetArch} ?= " >> "$buildConfigFile" 1029 get_variable ${2}_$targetArch | xargs -n 1 echo " " \ 1030 >> "$buildConfigFile" 1031 echo " ;" >> "$buildConfigFile" 1032 shift 2 1033 done 1034done 1035 1036 1037# Generate a boot strap Jamfile in the output directory. 1038 1039cat << EOF > $outputDir/Jamfile 1040# automatically generated Jamfile 1041 1042HAIKU_TOP = ${sourceDir} ; 1043HAIKU_OUTPUT_DIR = ${outputDir} ; 1044 1045include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 1046 1047EOF 1048