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 --bochs-debug Enables bochs serial debug emulation (activated 16 via kernel settings file). 17 --build-cross-tools <build tools dir> 18 Assume cross compilation. <build tools dir> 19 defines the location of the build tools sources. 20 They will be compiled and placed in the output 21 directory under "cross-tools". The HAIKU_* tools 22 variables will be set accordingly. 23 --build-cross-tools-gcc4 <arch> <build tools dir> 24 Like "--build-cross-tools" just that gcc 4 will 25 be used for cross-compilation. Note, that the 26 resulting Haiku installation built with gcc 4 27 will not be binary compatible with BeOS R5. 28 <arch> specifies the target architecture, either 29 "x86", "ppc", "m68k", "arm" or "mipsel". 30 --alternative-gcc-output-dir <dir> 31 Build a Haiku installation that supports running 32 executables built with a gcc version incompatible 33 with the primary gcc (e.g. gcc 2 executables under 34 a gcc 4 Haiku or vice versa). <dir> specifies the 35 output directory of the other gcc. The directory 36 must already be fully configured. 37 Note, that a sub-jam will be executed when 38 building Haiku. When using a jam that is not 39 simply invoked by "jam", the JAM build variable 40 needs to be set accordingly. 41 To disable building the alternative libraries 42 the variable HAIKU_ADD_ALTERNATIVE_GCC_LIBS can be 43 unset in the UserBuildConfig file. 44 --cross-tools-prefix <prefix> 45 Assume cross compilation. <prefix> should be a 46 path to the directory where the cross 47 compilation tools are located, plus the platform 48 prefix, e.g. "/path/to/tools/i586-pc-haiku-". 49 This overrides the HAIKU_* tool variables. 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 --help Prints out this help. 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-3rdparty Include 3rdparty/ in the build system. 67 --enable-multiuser Enable experimental multiuser support. 68 --target=TARGET Select build target platform. [default=${target}] 69 valid targets=r5,bone,dano,haiku 70 --use-gcc-pipe Build with GCC option -pipe. Speeds up the build 71 process, but uses more memory. 72 --use-32bit Use -m32 flag on 64bit host gcc compiler. 73 --use-xattr Use Linux xattr support for BeOS attribute 74 emulation. Warning: Make sure your file system 75 supports sufficient attribute sizes (4 KB per 76 file for all attributes won't suffice). 77 78environment variables: 79 HAIKU_AR The static library archiver. Defaults to "ar". 80 HAIKU_CC The compiler. Defaults to "gcc". 81 HAIKU_LD The linker. Defaults to "ld". 82 HAIKU_OBJCOPY The objcopy to be used. Defaults to "objcopy". 83 HAIKU_RANLIB The static library indexer. Defaults to "ranlib". 84 HAIKU_YASM The yasm assembler (x86 only). 85 HAIKU_CPPFLAGS The preprocessor flags. Defaults to "". 86 HAIKU_CCFLAGS The C flags. Defaults to "". 87 HAIKU_CXXFLAGS The C++ flags. Defaults to "". 88 HAIKU_LDFLAGS The linker flags. Defaults to "". 89 HAIKU_ARFLAGS The flags passed to HAIKU_AR for archiving. 90 Defaults to "cru". 91 HAIKU_UNARFLAGS The flags passed to HAIKU_AR for unarchiving. 92 Defaults to "x". 93 94Non-standard output directories: 95 By default all objects, build configuration, and other related files are 96 stored in /path/to/haiku_source/generated. To store objects in a non-default 97 location, run "../../relative/path/to/haiku_source/configure <options>" from 98 within your non-default location. "jam [ options ] targets" can then be run 99 directly inside your non-default location. Another option is to invoke "jam 100 [ options ] targets" from within haiku_source. This can be accomplished by 101 either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking 102 jam or by creating a symlink of haiku_source/generated pointing to your 103 non-default location and running jam. 104 105 106EOF 107} 108 109# assertparam 110# 111# Checks whether at least one parameter is left. 112# 113assertparam() 114{ 115 if [ $2 -lt 2 ]; then 116 echo $0: \`$1\': Parameter expected. 117 exit 1 118 fi 119} 120 121# assertparams 122# 123# Checks whether at least a certain number of parameters is left. 124# 125assertparams() 126{ 127 if [ $3 -le $2 ]; then 128 echo $0: \`$1\': Not enough parameters. 129 exit 1 130 fi 131} 132 133# standard_gcc_settings 134# 135# Sets the variables for a GCC platform. 136# 137standard_gcc_settings() 138{ 139 # PLATFORM_LINKLIBS 140 gcclib=`$HAIKU_CC -print-libgcc-file-name` 141 gccdir=`dirname ${gcclib}` 142 143 haikuGCCVersion=`$HAIKU_CC -dumpversion` 144 haikuGCCMachine=`$HAIKU_CC -dumpmachine` 145 146 HAIKU_GCC_LIB_DIR=${gccdir} 147 HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a 148 HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o" 149 HAIKU_GCC_HEADERS_DIR="${gccdir}/include 150 ${gccdir}/include-fixed" 151 HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o` 152 # Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and 153 # neither needed nor wanted. 154 155 case $haikuGCCVersion in 156 4.*) 157 # for gcc 4 we use the libstdc++ and libsupc++ that come with the 158 # compiler 159 haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a` 160 haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so` 161 haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a` 162 haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so` 163 164 local headers 165 if [ -d $gccdir/../../../../$haikuGCCMachine/include/c++/$haikuGCCVersion ]; then 166 headers=$gccdir/../../../../$haikuGCCMachine/include/c++/$haikuGCCVersion 167 else 168 headers=$gccdir/../../../../include/c++/$haikuGCCVersion 169 fi 170 171 haikuCxxHeadersDir=$headers 172 for d in $haikuGCCMachine backward ext; do 173 # Note: We need the line break, otherwise the line might become 174 # too long for jam (512 bytes max). 175 haikuCxxHeadersDir="$haikuCxxHeadersDir 176 $headers/$d" 177 done 178 179 180 # when not building the crosscompiler, to use cpp headers from 181 # tree first, but fallback to local C++ system headers (like <new>) 182 # if [ "$buildCrossTools" = "" ]; then 183 # haikuCxxHeadersDir="headers/cpp $haikuCxxHeadersDir" 184 # fi 185 186 if [ $haikuStaticLibStdCxx = libstdc++.a ]; then 187 haikuStaticLibStdCxx= 188 fi 189 # we build libstdc++.so ourselves, so we can leave it as is 190 # if [ $haikuSharedLibStdCxx = libstdc++.so ]; then 191 # haikuSharedLibStdCxx= 192 # fi 193 if [ $haikuStaticLibSupCxx = libsupc++.a ]; then 194 haikuStaticLibSupCxx= 195 fi 196 # we build libsupc++.so ourselves, so we can leave it as is 197 # if [ $haikuSharedLibSupCxx = libsupc++.so ]; then 198 # haikuSharedLibSupCxx= 199 # fi 200 ;; 201 2.9*) 202 # check for correct (most up-to-date) legacy compiler and complain 203 # if an older one is installed 204 if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then 205 echo "GCC version $haikuRequiredLegacyGCCVersion is required!"; 206 echo "Please download it from www.haiku-os.org..."; 207 exit 1; 208 fi 209 ;; 210 esac 211} 212 213# set_default_value 214# 215# Set the value for a variable, if no value is set yet. 216# 217set_default_value() 218{ 219 eval "$1=\${$1-$2}" 220} 221 222# get_build_tool_path 223# 224# Gets a usable absolute path of a build tool. 225# 226get_build_tool_path() 227{ 228 local var="HAIKU_$1" 229 local tool=$2 230 local path="${crossToolsPrefix}$tool" 231 232 if [ -f "$path" ]; then 233 # get absolute path 234 local oldPwd="`pwd`" 235 cd "`dirname "$path"`" 236 path="`pwd`/`basename "$path"`" 237 cd $oldPwd 238 else 239 which "$path" &> /dev/null || { 240 echo "Build tool \"$path\" not found." >&2 241 exit 1 242 } 243 fi 244 245 eval "$var=$path" 246} 247 248# get cwd and the source directory 249currentDir=`pwd` 250cd `dirname "$0"` 251sourceDir=`pwd` 252cd "$currentDir" 253 254# default parameter values 255# 256platform=`uname` 257platformMachine=`uname -m` 258haikuGCCVersion= 259haikuGCCMachine=i586-pc-haiku 260haikuStaticLibStdCxx= 261haikuSharedLibStdCxx= 262haikuStaticLibSupCxx= 263haikuSharedLibSupCxx= 264haikuCxxHeadersDir= 265hostGCCVersion=`gcc -dumpversion` 266bochsDebug=0 267includeGPLAddOns=0 268includePatentedCode=0 269include3rdParty=0 270enableMultiuser=0 271distroCompatibility=default 272target=haiku 273targetArch=x86 274useGCCPipe=0 275use32bit=0 276useXattr=0 277crossToolsPrefix= 278buildCrossTools= 279buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 280buildCrossToolsMachine= 281alternativeGCCOutputDir= 282addAlternativeGCCLibs= 283 284haikuRequiredLegacyGCCVersion="2.95.3-haiku-090629" 285export haikuRequiredLegacyGCCVersion 286 # version of legacy gcc required to build haiku 287 288set_default_value HAIKU_AR ar 289set_default_value HAIKU_CC gcc 290set_default_value HAIKU_LD ld 291set_default_value HAIKU_OBJCOPY objcopy 292set_default_value HAIKU_RANLIB ranlib 293set_default_value HAIKU_YASM yasm 294set_default_value HAIKU_CPPFLAGS "" 295set_default_value HAIKU_CCFLAGS "" 296set_default_value HAIKU_CXXFLAGS "" 297set_default_value HAIKU_LDFLAGS "" 298set_default_value HAIKU_ARFLAGS cru 299set_default_value HAIKU_UNARFLAGS x 300 301# parse parameters 302# 303while [ $# -gt 0 ] ; do 304 case "$1" in 305 --bochs-debug) bochsDebug=1; shift 1;; 306 --build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;; 307 --build-cross-tools-gcc4) 308 assertparams "$1" 2 $# 309 buildCrossTools=$3 310 buildCrossToolsScript="${buildCrossToolsScript}_gcc4" 311 case "$2" in 312 x86) haikuGCCMachine=i586-pc-haiku;; 313 ppc) haikuGCCMachine=powerpc-apple-haiku; targetArch=ppc;; 314 m68k) haikuGCCMachine=m68k-unknown-haiku; targetArch=m86k;; 315 arm) haikuGCCMachine=arm-unknown-haiku; targetArch=arm;; 316 mipsel) haikuGCCMachine=mipsel-unknown-haiku; targetArch=mips;; 317 *) echo "Unsupported target architecture: $2" 318 exit 1;; 319 esac 320 buildCrossToolsMachine=$haikuGCCMachine 321 shift 3 322 ;; 323 --alternative-gcc-output-dir) 324 assertparam "$1" $# 325 cd $2 || exit 1 326 alternativeGCCOutputDir=`pwd` 327 addAlternativeGCCLibs=1 328 cd $currentDir 329 shift 2 330 ;; 331 --cross-tools-prefix) 332 assertparam "$1" $# 333 crossToolsPrefix=$2 334 shift 2 335 ;; 336 --help | -h) usage; exit 0;; 337 --include-gpl-addons) includeGPLAddOns=1; shift 1;; 338 --include-patented-code) includePatentedCode=1; shift 1;; 339 --include-3rdparty) include3rdParty=1; shift 1;; 340 --enable-multiuser) enableMultiuser=1; shift 1;; 341 --distro-compatibility) 342 assertparam "$1" $# 343 distroCompatibility=$2 344 case "$distroCompatibility" in 345 official) ;; 346 compatible) ;; 347 default) ;; 348 *) echo "Invalid distro compatibility" \ 349 "level: $distroCompatibility" 350 exit 1;; 351 esac 352 shift 2 353 ;; 354 --target=*) target=`echo $1 | cut -d'=' -f2-`; shift 1;; 355 --use-gcc-pipe) useGCCPipe=1; shift 1;; 356 --use-32bit) use32bit=1; shift 1;; 357 --use-xattr) useXattr=1; shift 1;; 358 *) echo Invalid argument: \`$1\'; exit 1;; 359 esac 360done 361 362# detect the build platform 363case "${platform}" in 364 BeOS) revision=`uname -r` 365 case "$revision" in 366 6.*) buildPlatform=dano ;; 367 5.1) buildPlatform=dano ;; 368 5.0.4) buildPlatform=bone ;; 369 5.0*) buildPlatform=r5 ;; 370 *) echo Unknown BeOS version: $revision 371 exit 1 ;; 372 esac 373 ;; 374 Darwin) buildPlatform=darwin ;; 375 FreeBSD) buildPlatform=freebsd 376 if [ "$use32bit" = 1 ] ; then 377 echo Unsupported platform: FreeBSD ${platformMachine} 378 exit 1 379 fi ;; 380 Haiku) buildPlatform=haiku_host ;; 381 Linux) buildPlatform=linux ;; 382 OpenBSD) buildPlatform=openbsd ;; 383 SunOS) buildPlatform=sunos ;; 384 CYGWIN_NT-*) buildPlatform=cygwin ;; 385 *) echo Unsupported platform: ${platform} 386 exit 1 ;; 387esac 388 389# check yasm version 390if [ $targetArch = "x86" ]; then 391 $HAIKU_YASM --version > /dev/null || { 392 echo "The yasm assembler version 0.7.0 or later must be installed." 393 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 394 exit 1 395 } 396 397 set -- $($HAIKU_YASM --version | head -n 1) 398 versionOK=0 399 case $2 in 400 0.[0-6].*) ;; 401 *) versionOK=1 ;; 402 esac 403 404 if [ $versionOK = 0 ]; then 405 echo "The yasm assembler version 0.7.0 or later must be installed." 406 echo "The installed version is $2." 407 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 408 exit 1 409 fi 410fi 411 412# check for case-sensitive filesystem if on darwin 413if [ $buildPlatform = "darwin" ]; then 414 diskutil info . | grep -i "case-sensitive" > /dev/null 415 if [ $? != 0 ]; then 416 echo "You need a case-sensitive file-system to build Haiku." 417 echo "Please see the following guide on how to set one up:" 418 echo "http://haiku-os.org/documents/dev/how_to_build_haiku_on_mac_os_x" 419 exit 1 420 fi 421fi 422 423# create output directory 424if [ "$currentDir" = "$sourceDir" ]; then 425 outputDir=$currentDir/generated 426else 427 outputDir=$currentDir 428fi 429buildOutputDir="$outputDir/build" 430buildAttributesDir="$outputDir/attributes" 431mkdir -p "$buildOutputDir" || exit 1 432 433# build cross tools from sources 434if [ -n "$buildCrossTools" ]; then 435 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 436 "$buildCrossTools" "$outputDir" || exit 1 437 crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-" 438fi 439 440# cross tools 441if [ -n "$crossToolsPrefix" ]; then 442 get_build_tool_path AR ar 443 get_build_tool_path CC gcc 444 get_build_tool_path LD ld 445 get_build_tool_path OBJCOPY objcopy 446 get_build_tool_path RANLIB ranlib 447fi 448 449# prepare gcc settings 450standard_gcc_settings 451 452# check whether the Haiku compiler really targets Haiku or BeOS 453case "$haikuGCCMachine" in 454 *-*-haiku) ;; 455 *-*-beos) ;; 456 *) echo The compiler specified as Haiku target compiler is not a valid \ 457 Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 458 echo compiler: $HAIKU_CC 459 echo compiler is configured for target: $haikuGCCMachine 460 exit 1 ;; 461esac 462 463# Generate BuildConfig 464cat << EOF > "$buildOutputDir/BuildConfig" 465# BuildConfig 466# Note: This file has been automatically generated by configure. 467 468TARGET_PLATFORM ?= "${target}" ; 469HOST_PLATFORM ?= "${buildPlatform}" ; 470 471BOCHS_DEBUG_HACK ?= "${bochsDebug}" ; 472INCLUDE_GPL_ADDONS ?= "${includeGPLAddOns}" ; 473HAIKU_INCLUDE_PATENTED_CODE ?= "${includePatentedCode}" ; 474HAIKU_INCLUDE_3RDPARTY ?= "${include3rdParty}" ; 475HAIKU_ENABLE_MULTIUSER ?= "${enableMultiuser}" ; 476HAIKU_DISTRO_COMPATIBILITY ?= "${distroCompatibility}" ; 477HAIKU_USE_GCC_PIPE ?= "${useGCCPipe}" ; 478HAIKU_HOST_USE_32BIT ?= "${use32bit}" ; 479HAIKU_HOST_USE_XATTR ?= "${useXattr}" ; 480HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR ?= ${alternativeGCCOutputDir} ; 481HAIKU_ADD_ALTERNATIVE_GCC_LIBS ?= ${addAlternativeGCCLibs} ; 482 483HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 484HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 485HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 486HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 487HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 488 489HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 490HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 491HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 492HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 493HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 494 495HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 496 497HAIKU_AR ?= ${HAIKU_AR} ; 498HAIKU_CC ?= ${HAIKU_CC} ; 499HAIKU_LD ?= ${HAIKU_LD} ; 500HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 501HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 502HAIKU_YASM ?= ${HAIKU_YASM} ; 503HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 504HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 505HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 506HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 507HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 508HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 509 510HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 511 512EOF 513 514# Libgcc.a objects 515 516cat << EOF > "$buildOutputDir/libgccObjects" 517# libgcc.a objects to be linked against libroot.so 518# Note: This file has been automatically generated by configure. 519 520HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 521EOF 522 523# Generate Timezones binaries bindings 524 525timezoneSources="africa antarctica asia australasia europe northamerica 526 southamerica pacificnew etcetera factory backward" 527 528cat << EOF > "$buildOutputDir/Timezones" 529# Timezones used for the build 530# Note: This file has been automatically generated by configure. 531 532HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 533 534EOF 535 536for source in ${timezoneSources}; do 537 f=$sourceDir/src/data/etc/timezones/$source 538 539TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" ` 540 541cat << EOF >> "$buildOutputDir/Timezones" 542TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 543EOF 544done 545 546# Generate a boot strap Jamfile in the output directory. 547 548cat << EOF > $outputDir/Jamfile 549# automatically generated Jamfile 550 551HAIKU_TOP = ${sourceDir} ; 552HAIKU_OUTPUT_DIR = ${outputDir} ; 553 554include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 555 556EOF 557