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