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