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 --cross-tools-prefix <prefix> 31 Assume cross compilation. <prefix> should be a 32 path to the directory where the cross 33 compilation tools are located, plus the platform 34 prefix, e.g. "/path/to/tools/i586-pc-haiku-". 35 This overrides the HAIKU_* tool variables. 36 --distro-compatibility <level> 37 The distribution's level of compatibility with 38 the official Haiku distribution. The generated 39 files will contain the respective trademarks 40 accordingly. 41 official -- the official Haiku distribution. 42 compatible -- a Haiku Compatible (tm) distro. 43 default -- any other distro (default value). 44 --help Prints out this help. 45 --include-gpl-addons Include GPL licensed add-ons. 46 --include-3rdparty Include 3rdparty/ in the build system. 47 --enable-multiuser Enable experimental multiuser support. 48 --target=TARGET Select build target platform. [default=${target}] 49 valid targets=r5,bone,dano,haiku 50 --use-gcc-pipe Build with GCC option -pipe. Speeds up the build 51 process, but uses more memory. 52 --use-32bit Use -m32 flag on 64bit host gcc compiler. 53 --use-xattr Use Linux xattr support for BeOS attribute 54 emulation. Warning: Make sure your file system 55 supports sufficient attribute sizes (4 KB per 56 file for all attributes won't suffice). 57 58environment variables: 59 HAIKU_AR The static library archiver. Defaults to "ar". 60 HAIKU_CC The compiler. Defaults to "gcc". 61 HAIKU_LD The linker. Defaults to "ld". 62 HAIKU_OBJCOPY The objcopy to be used. Defaults to "objcopy". 63 HAIKU_RANLIB The static library indexer. Defaults to "ranlib". 64 HAIKU_CPPFLAGS The preprocessor flags. Defaults to "". 65 HAIKU_CCFLAGS The C flags. Defaults to "". 66 HAIKU_CXXFLAGS The C++ flags. Defaults to "". 67 HAIKU_LDFLAGS The linker flags. Defaults to "". 68 HAIKU_ARFLAGS The flags passed to HAIKU_AR for archiving. 69 Defaults to "ru". 70 HAIKU_UNARFLAGS The flags passed to HAIKU_AR for unarchiving. 71 Defaults to "x". 72EOF 73} 74 75# assertparam 76# 77# Checks whether at least one parameter is left. 78# 79assertparam() 80{ 81 if [ $2 -lt 2 ]; then 82 echo $0: \`$1\': Parameter expected. 83 exit 1 84 fi 85} 86 87# assertparams 88# 89# Checks whether at least a certain number of parameters is left. 90# 91assertparams() 92{ 93 if [ $3 -le $2 ]; then 94 echo $0: \`$1\': Not enough parameters. 95 exit 1 96 fi 97} 98 99# standard_gcc_settings 100# 101# Sets the variables for a GCC platform. 102# 103standard_gcc_settings() 104{ 105 # PLATFORM_LINKLIBS 106 gcclib=`$HAIKU_CC -print-libgcc-file-name` 107 gccdir=`dirname ${gcclib}` 108 109 haikuGCCVersion=`$HAIKU_CC -dumpversion` 110 haikuGCCMachine=`$HAIKU_CC -dumpmachine` 111 112 HAIKU_GCC_LIB_DIR=${gccdir} 113 HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a 114 HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o" 115 HAIKU_GCC_HEADERS_DIR=${gccdir}/include 116 HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o` 117 # Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and 118 # neither needed nor wanted. 119 120 case $haikuGCCVersion in 121 4.*) 122 # for gcc 4 we use the libstdc++ and libsupc++ that come with the 123 # compiler 124 haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a` 125 haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so` 126 haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a` 127 haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so` 128 local headers=$gccdir/../../../../include/c++/$haikuGCCVersion 129 haikuCxxHeadersDir=$headers 130 for d in $haikuGCCMachine backward ext; do 131 # Note: We need the line break, otherwise the line might become 132 # too long for jam (512 bytes max). 133 haikuCxxHeadersDir="$haikuCxxHeadersDir 134 $headers/$d" 135 done 136 137 138 # when not building the crosscompiler, to use cpp headers from 139 # tree first, but fallback to local C++ system headers (like <new>) 140 # if [ "$buildCrossTools" = "" ]; then 141 # haikuCxxHeadersDir="headers/cpp $haikuCxxHeadersDir" 142 # fi 143 144 if [ $haikuStaticLibStdCxx = libstdc++.a ]; then 145 haikuStaticLibStdCxx= 146 fi 147 if [ $haikuSharedLibStdCxx = libstdc++.so ]; then 148 haikuSharedLibStdCxx= 149 fi 150 if [ $haikuStaticLibSupCxx = libsupc++.a ]; then 151 haikuStaticLibSupCxx= 152 fi 153 if [ $haikuSharedLibSupCxx = libsupc++.so ]; then 154 haikuSharedLibSupCxx= 155 fi 156 ;; 157 2.9*) 158 # check for correct (most up-to-date) legacy compiler and complain 159 # if an older one is installed 160 if [ $haikuGCCVersion != $haikuRequiredLegacyGCCVersion ]; then 161 echo "GCC version $haikuRequiredLegacyGCCVersion is required!"; 162 echo "Please download it from www.haiku-os.org..."; 163 exit 1; 164 fi 165 ;; 166 esac 167} 168 169# set_default_value 170# 171# Set the value for a variable, if no value is set yet. 172# 173set_default_value() 174{ 175 eval "$1=\${$1-$2}" 176} 177 178# get_build_tool_path 179# 180# Gets a usable absolute path of a build tool. 181# 182get_build_tool_path() 183{ 184 local var="HAIKU_$1" 185 local tool=$2 186 local path="${crossToolsPrefix}$tool" 187 188 if [ -f "$path" ]; then 189 # get absolute path 190 local oldPwd=$(pwd) 191 cd $(dirname "$path") 192 path="$(pwd)/$(basename "$path")" 193 cd $oldPwd 194 else 195 which "$path" &> /dev/null || { 196 echo "Build tool \"$path\" not found." >&2 197 exit 1 198 } 199 fi 200 201 eval "$var=$path" 202} 203 204# get cwd and the source directory 205currentDir=`pwd` 206cd `dirname "$0"` 207sourceDir=`pwd` 208cd "$currentDir" 209 210# default parameter values 211# 212platform=`uname` 213haikuGCCVersion= 214haikuGCCMachine=i586-pc-haiku 215haikuStaticLibStdCxx= 216haikuSharedLibStdCxx= 217haikuStaticLibSupCxx= 218haikuSharedLibSupCxx= 219haikuCxxHeadersDir= 220hostGCCVersion=`gcc -dumpversion` 221bochs_debug=0 222include_gpl_addons=0 223include_3rdparty=0 224enable_multiuser=0 225distroCompatibility=default 226target=haiku 227use_gcc_pipe=0 228use_32bit=0 229use_xattr=0 230crossToolsPrefix= 231buildCrossTools= 232buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 233buildCrossToolsMachine= 234 235export haikuRequiredLegacyGCCVersion="2.95.3-haiku-080323" 236 # version of legacy gcc required to build haiku 237 238set_default_value HAIKU_AR ar 239set_default_value HAIKU_CC gcc 240set_default_value HAIKU_LD ld 241set_default_value HAIKU_OBJCOPY objcopy 242set_default_value HAIKU_RANLIB ranlib 243set_default_value HAIKU_CPPFLAGS "" 244set_default_value HAIKU_CCFLAGS "" 245set_default_value HAIKU_CXXFLAGS "" 246set_default_value HAIKU_LDFLAGS "" 247set_default_value HAIKU_ARFLAGS ru 248set_default_value HAIKU_UNARFLAGS x 249 250# parse parameters 251# 252while [ $# -gt 0 ] ; do 253 case "$1" in 254 --bochs-debug) bochs_debug=1; shift 1;; 255 --build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;; 256 --build-cross-tools-gcc4) assertparams "$1" 2 $#; buildCrossTools=$3; 257 buildCrossToolsScript="${buildCrossToolsScript}_gcc4"; 258 case "$2" in 259 x86) haikuGCCMachine=i586-pc-haiku;; 260 ppc) haikuGCCMachine=powerpc-apple-haiku;; 261 m68k) haikuGCCMachine=m68k-unknown-haiku;; 262 *) echo "Unsupported target architecture: $2" 263 exit 1;; 264 esac 265 buildCrossToolsMachine=$haikuGCCMachine 266 shift 3;; 267 --cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;; 268 --help | -h) usage; exit 0;; 269 --include-gpl-addons) include_gpl_addons=1; shift 1;; 270 --include-3rdparty) include_3rdparty=1; shift 1;; 271 --enable-multiuser) enable_multiuser=1; shift 1;; 272 --distro-compatibility) 273 assertparam "$1" $#; distroCompatibility=$2; 274 case "$distroCompatibility" in 275 official) ;; 276 compatible) ;; 277 default) ;; 278 *) echo "Invalid distro compatibility" \ 279 "level: $distroCompatibility" 280 exit 1;; 281 esac 282 shift 2;; 283 --target=*) target=`echo $1 | cut -d'=' -f2-`; shift 1;; 284 --use-gcc-pipe) use_gcc_pipe=1; shift 1;; 285 --use-32bit) use_32bit=1; shift 1;; 286 --use-xattr) use_xattr=1; shift 1;; 287 *) echo Invalid argument: \`$1\'; exit 1;; 288 esac 289done 290 291# detect the build platform 292case "${platform}" in 293 BeOS) revision=`uname -r` 294 case "$revision" in 295 6.*) buildPlatform=dano ;; 296 5.1) buildPlatform=dano ;; 297 5.0.4) buildPlatform=bone ;; 298 5.0*) buildPlatform=r5 ;; 299 *) echo Unknown BeOS version: $revision 300 exit 1 ;; 301 esac 302 ;; 303 Darwin) buildPlatform=darwin ;; 304 FreeBSD) buildPlatform=freebsd ;; 305 Haiku) buildPlatform=haiku_host ;; 306 Linux) buildPlatform=linux ;; 307 *) echo Unsupported platform: ${platform} 308 exit 1 ;; 309esac 310 311# create output directory 312if [ "$currentDir" = "$sourceDir" ]; then 313 outputDir=$currentDir/generated 314else 315 outputDir=$currentDir 316fi 317buildOutputDir="$outputDir/build" 318buildAttributesDir="$outputDir/attributes" 319mkdir -p "$buildOutputDir" || exit 1 320 321# build cross tools from sources 322if [ -n "$buildCrossTools" ]; then 323 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 324 "$buildCrossTools" "$outputDir" || exit 1 325 crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-" 326fi 327 328# cross tools 329if [ -n "$crossToolsPrefix" ]; then 330 get_build_tool_path AR ar 331 get_build_tool_path CC gcc 332 get_build_tool_path LD ld 333 get_build_tool_path OBJCOPY objcopy 334 get_build_tool_path RANLIB ranlib 335fi 336 337# prepare gcc settings 338standard_gcc_settings 339 340# check whether the Haiku compiler really targets Haiku or BeOS 341case "$haikuGCCMachine" in 342 *-*-haiku) ;; 343 *-*-beos) ;; 344 *) echo The compiler specified as Haiku target compiler is not a valid \ 345 Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 346 echo compiler: $HAIKU_CC 347 echo compiler is configured for target: $haikuGCCMachine 348 exit 1 ;; 349esac 350 351# Generate BuildConfig 352cat << EOF > "$buildOutputDir/BuildConfig" 353# BuildConfig 354# Note: This file has been automatically generated by configure. 355 356TARGET_PLATFORM ?= "${target}" ; 357HOST_PLATFORM ?= "${buildPlatform}" ; 358 359BOCHS_DEBUG_HACK ?= "${bochs_debug}" ; 360INCLUDE_GPL_ADDONS ?= "${include_gpl_addons}" ; 361HAIKU_INCLUDE_3RDPARTY ?= "${include_3rdparty}" ; 362HAIKU_ENABLE_MULTIUSER ?= "${enable_multiuser}" ; 363HAIKU_DISTRO_COMPATIBILITY ?= "${distroCompatibility}" ; 364HAIKU_USE_GCC_PIPE ?= "${use_gcc_pipe}" ; 365HAIKU_HOST_USE_32BIT ?= "${use_32bit}" ; 366HAIKU_HOST_USE_XATTR ?= "${use_xattr}" ; 367 368HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 369HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 370HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 371HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 372HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 373 374HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 375HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 376HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 377HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 378HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 379 380HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 381 382HAIKU_AR ?= ${HAIKU_AR} ; 383HAIKU_CC ?= ${HAIKU_CC} ; 384HAIKU_LD ?= ${HAIKU_LD} ; 385HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 386HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 387HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 388HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 389HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 390HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 391HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 392HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 393 394HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 395 396EOF 397 398# Libgcc.a objects 399 400cat << EOF > "$buildOutputDir/libgccObjects" 401# libgcc.a objects to be linked against libroot.so 402# Note: This file has been automatically generated by configure. 403 404HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 405EOF 406 407# Generate Timezones binaries bindings 408 409timezoneSources="africa antarctica asia australasia europe northamerica 410 southamerica pacificnew etcetera factory backward" 411 412cat << EOF > "$buildOutputDir/Timezones" 413# Timezones used for the build 414# Note: This file has been automatically generated by configure. 415 416HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 417 418EOF 419 420for source in ${timezoneSources}; do 421 f=$sourceDir/src/data/etc/timezones/$source 422 423TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" ` 424 425cat << EOF >> "$buildOutputDir/Timezones" 426TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 427EOF 428done 429 430# Generate a boot strap Jamfile in the output directory, if it is not in 431# the source dir. 432 433if [ "$currentDir" != "$sourceDir" ]; then 434 435cat << EOF > $outputDir/Jamfile 436# automatically generated Jamfile 437 438HAIKU_TOP = ${sourceDir} ; 439HAIKU_OUTPUT_DIR = ${outputDir} ; 440 441include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 442 443EOF 444 445fi 446 447