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" or "ppc". 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# check for a 64bit platform 353case "${platformMachine}" in 354 x86_64) use32bit=1 ;; 355 *) echo Assuming 32-bit machine: "$platformMachine" 356 use32bit=0 ;; 357esac 358 359# detect the build platform 360case "${platform}" in 361 BeOS) revision=`uname -r` 362 case "$revision" in 363 6.*) buildPlatform=dano ;; 364 5.1) buildPlatform=dano ;; 365 5.0.4) buildPlatform=bone ;; 366 5.0*) buildPlatform=r5 ;; 367 *) echo Unknown BeOS version: $revision 368 exit 1 ;; 369 esac 370 ;; 371 Darwin) buildPlatform=darwin ;; 372 FreeBSD) buildPlatform=freebsd 373 if [ "$use32bit" = 1 ] ; then 374 echo Unsupported platform: FreeBSD ${platformMachine} 375 exit 1 376 fi ;; 377 Haiku) buildPlatform=haiku_host ;; 378 Linux) buildPlatform=linux ;; 379 OpenBSD) buildPlatform=openbsd ;; 380 SunOS) buildPlatform=sunos ;; 381 CYGWIN_NT-*) buildPlatform=cygwin ;; 382 *) echo Unsupported platform: ${platform} 383 exit 1 ;; 384esac 385 386# check yasm version 387if [ $targetArch = "x86" ]; then 388 $HAIKU_YASM --version > /dev/null || { 389 echo "The yasm assembler version 0.7.2 or later must be installed." 390 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 391 exit 1 392 } 393 394 set -- $($HAIKU_YASM --version | head -n 1) 395 versionOK=0 396 case $2 in 397 0.[0-6].*) echo match1;; 398 0.7.[0-1].*) echo match2;; 399 *) versionOK=1 ;; 400 esac 401 402 if [ $versionOK = 0 ]; then 403 echo "The yasm assembler version 0.7.2 or later must be installed." 404 echo "The installed version is $2." 405 echo "Download from: http://www.tortall.net/projects/yasm/wiki/Download" 406 exit 1 407 fi 408fi 409 410# create output directory 411if [ "$currentDir" = "$sourceDir" ]; then 412 outputDir=$currentDir/generated 413else 414 outputDir=$currentDir 415fi 416buildOutputDir="$outputDir/build" 417buildAttributesDir="$outputDir/attributes" 418mkdir -p "$buildOutputDir" || exit 1 419 420# build cross tools from sources 421if [ -n "$buildCrossTools" ]; then 422 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 423 "$buildCrossTools" "$outputDir" || exit 1 424 crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-" 425fi 426 427# cross tools 428if [ -n "$crossToolsPrefix" ]; then 429 get_build_tool_path AR ar 430 get_build_tool_path CC gcc 431 get_build_tool_path LD ld 432 get_build_tool_path OBJCOPY objcopy 433 get_build_tool_path RANLIB ranlib 434fi 435 436# prepare gcc settings 437standard_gcc_settings 438 439# check whether the Haiku compiler really targets Haiku or BeOS 440case "$haikuGCCMachine" in 441 *-*-haiku) ;; 442 *-*-beos) ;; 443 *) echo The compiler specified as Haiku target compiler is not a valid \ 444 Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 445 echo compiler: $HAIKU_CC 446 echo compiler is configured for target: $haikuGCCMachine 447 exit 1 ;; 448esac 449 450# Generate BuildConfig 451cat << EOF > "$buildOutputDir/BuildConfig" 452# BuildConfig 453# Note: This file has been automatically generated by configure. 454 455TARGET_PLATFORM ?= "${target}" ; 456HOST_PLATFORM ?= "${buildPlatform}" ; 457 458BOCHS_DEBUG_HACK ?= "${bochsDebug}" ; 459INCLUDE_GPL_ADDONS ?= "${includeGPLAddOns}" ; 460HAIKU_INCLUDE_3RDPARTY ?= "${include3rdParty}" ; 461HAIKU_ENABLE_MULTIUSER ?= "${enableMultiuser}" ; 462HAIKU_DISTRO_COMPATIBILITY ?= "${distroCompatibility}" ; 463HAIKU_USE_GCC_PIPE ?= "${useGCCPipe}" ; 464HAIKU_HOST_USE_32BIT ?= "${use32bit}" ; 465HAIKU_HOST_USE_XATTR ?= "${useXattr}" ; 466HAIKU_ALTERNATIVE_GCC_OUTPUT_DIR ?= ${alternativeGCCOutputDir} ; 467HAIKU_ADD_ALTERNATIVE_GCC_LIBS ?= ${addAlternativeGCCLibs} ; 468 469HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 470HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 471HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 472HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 473HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 474 475HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 476HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 477HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 478HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 479HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 480 481HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 482 483HAIKU_AR ?= ${HAIKU_AR} ; 484HAIKU_CC ?= ${HAIKU_CC} ; 485HAIKU_LD ?= ${HAIKU_LD} ; 486HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 487HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 488HAIKU_YASM ?= ${HAIKU_YASM} ; 489HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 490HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 491HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 492HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 493HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 494HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 495 496HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 497 498EOF 499 500# Libgcc.a objects 501 502cat << EOF > "$buildOutputDir/libgccObjects" 503# libgcc.a objects to be linked against libroot.so 504# Note: This file has been automatically generated by configure. 505 506HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 507EOF 508 509# Generate Timezones binaries bindings 510 511timezoneSources="africa antarctica asia australasia europe northamerica 512 southamerica pacificnew etcetera factory backward" 513 514cat << EOF > "$buildOutputDir/Timezones" 515# Timezones used for the build 516# Note: This file has been automatically generated by configure. 517 518HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 519 520EOF 521 522for source in ${timezoneSources}; do 523 f=$sourceDir/src/data/etc/timezones/$source 524 525TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" ` 526 527cat << EOF >> "$buildOutputDir/Timezones" 528TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 529EOF 530done 531 532# Generate a boot strap Jamfile in the output directory. 533 534cat << EOF > $outputDir/Jamfile 535# automatically generated Jamfile 536 537HAIKU_TOP = ${sourceDir} ; 538HAIKU_OUTPUT_DIR = ${outputDir} ; 539 540include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 541 542EOF 543