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