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