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