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