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