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 "ru". 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 if [ $haikuSharedLibStdCxx = libstdc++.so ]; then 184 haikuSharedLibStdCxx= 185 fi 186 if [ $haikuStaticLibSupCxx = libsupc++.a ]; then 187 haikuStaticLibSupCxx= 188 fi 189 if [ $haikuSharedLibSupCxx = libsupc++.so ]; then 190 haikuSharedLibSupCxx= 191 fi 192 ;; 193 2.9*) 194 # check for correct (most up-to-date) legacy compiler and complain 195 # if an older one is installed 196 if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then 197 echo "GCC version $haikuRequiredLegacyGCCVersion is required!"; 198 echo "Please download it from www.haiku-os.org..."; 199 exit 1; 200 fi 201 ;; 202 esac 203} 204 205# set_default_value 206# 207# Set the value for a variable, if no value is set yet. 208# 209set_default_value() 210{ 211 eval "$1=\${$1-$2}" 212} 213 214# get_build_tool_path 215# 216# Gets a usable absolute path of a build tool. 217# 218get_build_tool_path() 219{ 220 local var="HAIKU_$1" 221 local tool=$2 222 local path="${crossToolsPrefix}$tool" 223 224 if [ -f "$path" ]; then 225 # get absolute path 226 local oldPwd="`pwd`" 227 cd "`dirname "$path"`" 228 path="`pwd`/`basename "$path"`" 229 cd $oldPwd 230 else 231 which "$path" &> /dev/null || { 232 echo "Build tool \"$path\" not found." >&2 233 exit 1 234 } 235 fi 236 237 eval "$var=$path" 238} 239 240# get cwd and the source directory 241currentDir=`pwd` 242cd `dirname "$0"` 243sourceDir=`pwd` 244cd "$currentDir" 245 246# default parameter values 247# 248platform=`uname` 249platformMachine=`uname -m` 250haikuGCCVersion= 251haikuGCCMachine=i586-pc-haiku 252haikuStaticLibStdCxx= 253haikuSharedLibStdCxx= 254haikuStaticLibSupCxx= 255haikuSharedLibSupCxx= 256haikuCxxHeadersDir= 257hostGCCVersion=`gcc -dumpversion` 258bochsDebug=0 259includeGPLAddOns=0 260include3rdParty=0 261enableMultiuser=0 262distroCompatibility=default 263target=haiku 264targetArch=x86 265useGCCPipe=0 266use32bit=0 267useXattr=0 268crossToolsPrefix= 269buildCrossTools= 270buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 271buildCrossToolsMachine= 272alternativeGCCOutputDir= 273addAlternativeGCCLibs= 274 275haikuRequiredLegacyGCCVersion="2.95.3-haiku-081024" 276export haikuRequiredLegacyGCCVersion 277 # version of legacy gcc required to build haiku 278 279set_default_value HAIKU_AR ar 280set_default_value HAIKU_CC gcc 281set_default_value HAIKU_LD ld 282set_default_value HAIKU_OBJCOPY objcopy 283set_default_value HAIKU_RANLIB ranlib 284set_default_value HAIKU_YASM yasm 285set_default_value HAIKU_CPPFLAGS "" 286set_default_value HAIKU_CCFLAGS "" 287set_default_value HAIKU_CXXFLAGS "" 288set_default_value HAIKU_LDFLAGS "" 289set_default_value HAIKU_ARFLAGS ru 290set_default_value HAIKU_UNARFLAGS x 291 292# parse parameters 293# 294while [ $# -gt 0 ] ; do 295 case "$1" in 296 --bochs-debug) bochsDebug=1; shift 1;; 297 --build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;; 298 --build-cross-tools-gcc4) 299 assertparams "$1" 2 $# 300 buildCrossTools=$3 301 buildCrossToolsScript="${buildCrossToolsScript}_gcc4" 302 case "$2" in 303 x86) haikuGCCMachine=i586-pc-haiku;; 304 ppc) haikuGCCMachine=powerpc-apple-haiku; targetArch=ppc;; 305 m68k) haikuGCCMachine=m68k-unknown-haiku; targetArch=m86k;; 306 arm) haikuGCCMachine=arm-unknown-haiku; targetArch=arm;; 307 mipsel) haikuGCCMachine=mipsel-unknown-haiku; targetArch=mips;; 308 *) echo "Unsupported target architecture: $2" 309 exit 1;; 310 esac 311 buildCrossToolsMachine=$haikuGCCMachine 312 shift 3 313 ;; 314 --alternative-gcc-output-dir) 315 assertparam "$1" $# 316 cd $2 || exit 1 317 alternativeGCCOutputDir=`pwd` 318 addAlternativeGCCLibs=1 319 cd $currentDir 320 shift 2 321 ;; 322 --cross-tools-prefix) 323 assertparam "$1" $# 324 crossToolsPrefix=$2 325 shift 2 326 ;; 327 --help | -h) usage; exit 0;; 328 --include-gpl-addons) includeGPLAddOns=1; shift 1;; 329 --include-3rdparty) include3rdParty=1; shift 1;; 330 --enable-multiuser) enableMultiuser=1; shift 1;; 331 --distro-compatibility) 332 assertparam "$1" $# 333 distroCompatibility=$2 334 case "$distroCompatibility" in 335 official) ;; 336 compatible) ;; 337 default) ;; 338 *) echo "Invalid distro compatibility" \ 339 "level: $distroCompatibility" 340 exit 1;; 341 esac 342 shift 2 343 ;; 344 --target=*) target=`echo $1 | cut -d'=' -f2-`; shift 1;; 345 --use-gcc-pipe) useGCCPipe=1; shift 1;; 346 --use-32bit) use32bit=1; shift 1;; 347 --use-xattr) useXattr=1; shift 1;; 348 *) echo Invalid argument: \`$1\'; exit 1;; 349 esac 350done 351 352# detect the build platform 353case "${platform}" in 354 BeOS) revision=`uname -r` 355 case "$revision" in 356 6.*) buildPlatform=dano ;; 357 5.1) buildPlatform=dano ;; 358 5.0.4) buildPlatform=bone ;; 359 5.0*) buildPlatform=r5 ;; 360 *) echo Unknown BeOS version: $revision 361 exit 1 ;; 362 esac 363 ;; 364 Darwin) buildPlatform=darwin ;; 365 FreeBSD) buildPlatform=freebsd 366 if [ "$use32bit" = 1 ] ; then 367 echo Unsupported platform: FreeBSD ${platformMachine} 368 exit 1 369 fi ;; 370 Haiku) buildPlatform=haiku_host ;; 371 Linux) buildPlatform=linux ;; 372 OpenBSD) buildPlatform=openbsd ;; 373 SunOS) buildPlatform=sunos ;; 374 CYGWIN_NT-*) buildPlatform=cygwin ;; 375 *) echo Unsupported platform: ${platform} 376 exit 1 ;; 377esac 378 379# check yasm version 380if [ $targetArch = "x86" ]; then 381 $HAIKU_YASM --version > /dev/null || { 382 echo "The yasm assembler version 0.7.0 or later must be installed." 383 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 384 exit 1 385 } 386 387 set -- $($HAIKU_YASM --version | head -n 1) 388 versionOK=0 389 case $2 in 390 0.[0-6].*) ;; 391 *) versionOK=1 ;; 392 esac 393 394 if [ $versionOK = 0 ]; then 395 echo "The yasm assembler version 0.7.0 or later must be installed." 396 echo "The installed version is $2." 397 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 398 exit 1 399 fi 400fi 401 402# check for case-sensitive filesystem if on darwin 403if [ $buildPlatform = "darwin" ]; then 404 diskutil info . | grep -i "case-sensitive" > /dev/null 405 if [ $? != 0 ]; then 406 echo "You need a case-sensitive file-system to build Haiku." 407 echo "Please see the following guide on how to set one up:" 408 echo "http://haiku-os.org/documents/dev/how_to_build_haiku_on_mac_os_x" 409 exit 1 410 fi 411fi 412 413# create output directory 414if [ "$currentDir" = "$sourceDir" ]; then 415 outputDir=$currentDir/generated 416else 417 outputDir=$currentDir 418fi 419buildOutputDir="$outputDir/build" 420buildAttributesDir="$outputDir/attributes" 421mkdir -p "$buildOutputDir" || exit 1 422 423# build cross tools from sources 424if [ -n "$buildCrossTools" ]; then 425 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 426 "$buildCrossTools" "$outputDir" || exit 1 427 crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-" 428fi 429 430# cross tools 431if [ -n "$crossToolsPrefix" ]; then 432 get_build_tool_path AR ar 433 get_build_tool_path CC gcc 434 get_build_tool_path LD ld 435 get_build_tool_path OBJCOPY objcopy 436 get_build_tool_path RANLIB ranlib 437fi 438 439# prepare gcc settings 440standard_gcc_settings 441 442# check whether the Haiku compiler really targets Haiku or BeOS 443case "$haikuGCCMachine" in 444 *-*-haiku) ;; 445 *-*-beos) ;; 446 *) echo The compiler specified as Haiku target compiler is not a valid \ 447 Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 448 echo compiler: $HAIKU_CC 449 echo compiler is configured for target: $haikuGCCMachine 450 exit 1 ;; 451esac 452 453# Generate BuildConfig 454cat << EOF > "$buildOutputDir/BuildConfig" 455# BuildConfig 456# Note: This file has been automatically generated by configure. 457 458TARGET_PLATFORM ?= "${target}" ; 459HOST_PLATFORM ?= "${buildPlatform}" ; 460 461BOCHS_DEBUG_HACK ?= "${bochsDebug}" ; 462INCLUDE_GPL_ADDONS ?= "${includeGPLAddOns}" ; 463HAIKU_INCLUDE_3RDPARTY ?= "${include3rdParty}" ; 464HAIKU_ENABLE_MULTIUSER ?= "${enableMultiuser}" ; 465HAIKU_DISTRO_COMPATIBILITY ?= "${distroCompatibility}" ; 466HAIKU_USE_GCC_PIPE ?= "${useGCCPipe}" ; 467HAIKU_HOST_USE_32BIT ?= "${use32bit}" ; 468HAIKU_HOST_USE_XATTR ?= "${useXattr}" ; 469HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR ?= ${alternativeGCCOutputDir} ; 470HAIKU_ADD_ALTERNATIVE_GCC_LIBS ?= ${addAlternativeGCCLibs} ; 471 472HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 473HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 474HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 475HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 476HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 477 478HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 479HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 480HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 481HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 482HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 483 484HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 485 486HAIKU_AR ?= ${HAIKU_AR} ; 487HAIKU_CC ?= ${HAIKU_CC} ; 488HAIKU_LD ?= ${HAIKU_LD} ; 489HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 490HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 491HAIKU_YASM ?= ${HAIKU_YASM} ; 492HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 493HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 494HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 495HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 496HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 497HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 498 499HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 500 501EOF 502 503# Libgcc.a objects 504 505cat << EOF > "$buildOutputDir/libgccObjects" 506# libgcc.a objects to be linked against libroot.so 507# Note: This file has been automatically generated by configure. 508 509HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 510EOF 511 512# Generate Timezones binaries bindings 513 514timezoneSources="africa antarctica asia australasia europe northamerica 515 southamerica pacificnew etcetera factory backward" 516 517cat << EOF > "$buildOutputDir/Timezones" 518# Timezones used for the build 519# Note: This file has been automatically generated by configure. 520 521HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 522 523EOF 524 525for source in ${timezoneSources}; do 526 f=$sourceDir/src/data/etc/timezones/$source 527 528TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" ` 529 530cat << EOF >> "$buildOutputDir/Timezones" 531TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 532EOF 533done 534 535# Generate a boot strap Jamfile in the output directory. 536 537cat << EOF > $outputDir/Jamfile 538# automatically generated Jamfile 539 540HAIKU_TOP = ${sourceDir} ; 541HAIKU_OUTPUT_DIR = ${outputDir} ; 542 543include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 544 545EOF 546