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