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 235haikuRequiredLegacyGCCVersion="2.95.3-haiku-080323" 236export haikuRequiredLegacyGCCVersion 237 # version of legacy gcc required to build haiku 238 239set_default_value HAIKU_AR ar 240set_default_value HAIKU_CC gcc 241set_default_value HAIKU_LD ld 242set_default_value HAIKU_OBJCOPY objcopy 243set_default_value HAIKU_RANLIB ranlib 244set_default_value HAIKU_CPPFLAGS "" 245set_default_value HAIKU_CCFLAGS "" 246set_default_value HAIKU_CXXFLAGS "" 247set_default_value HAIKU_LDFLAGS "" 248set_default_value HAIKU_ARFLAGS ru 249set_default_value HAIKU_UNARFLAGS x 250 251# parse parameters 252# 253while [ $# -gt 0 ] ; do 254 case "$1" in 255 --bochs-debug) bochs_debug=1; shift 1;; 256 --build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;; 257 --build-cross-tools-gcc4) assertparams "$1" 2 $#; buildCrossTools=$3; 258 buildCrossToolsScript="${buildCrossToolsScript}_gcc4"; 259 case "$2" in 260 x86) haikuGCCMachine=i586-pc-haiku;; 261 ppc) haikuGCCMachine=powerpc-apple-haiku;; 262 m68k) haikuGCCMachine=m68k-unknown-haiku;; 263 *) echo "Unsupported target architecture: $2" 264 exit 1;; 265 esac 266 buildCrossToolsMachine=$haikuGCCMachine 267 shift 3;; 268 --cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;; 269 --help | -h) usage; exit 0;; 270 --include-gpl-addons) include_gpl_addons=1; shift 1;; 271 --include-3rdparty) include_3rdparty=1; shift 1;; 272 --enable-multiuser) enable_multiuser=1; shift 1;; 273 --distro-compatibility) 274 assertparam "$1" $#; distroCompatibility=$2; 275 case "$distroCompatibility" in 276 official) ;; 277 compatible) ;; 278 default) ;; 279 *) echo "Invalid distro compatibility" \ 280 "level: $distroCompatibility" 281 exit 1;; 282 esac 283 shift 2;; 284 --target=*) target=`echo $1 | cut -d'=' -f2-`; shift 1;; 285 --use-gcc-pipe) use_gcc_pipe=1; shift 1;; 286 --use-32bit) use_32bit=1; shift 1;; 287 --use-xattr) use_xattr=1; shift 1;; 288 *) echo Invalid argument: \`$1\'; exit 1;; 289 esac 290done 291 292# detect the build platform 293case "${platform}" in 294 BeOS) revision=`uname -r` 295 case "$revision" in 296 6.*) buildPlatform=dano ;; 297 5.1) buildPlatform=dano ;; 298 5.0.4) buildPlatform=bone ;; 299 5.0*) buildPlatform=r5 ;; 300 *) echo Unknown BeOS version: $revision 301 exit 1 ;; 302 esac 303 ;; 304 Darwin) buildPlatform=darwin ;; 305 FreeBSD) buildPlatform=freebsd ;; 306 Haiku) buildPlatform=haiku_host ;; 307 Linux) buildPlatform=linux ;; 308 SunOS) buildPlatform=sunos ;; 309 *) echo Unsupported platform: ${platform} 310 exit 1 ;; 311esac 312 313# create output directory 314if [ "$currentDir" = "$sourceDir" ]; then 315 outputDir=$currentDir/generated 316else 317 outputDir=$currentDir 318fi 319buildOutputDir="$outputDir/build" 320buildAttributesDir="$outputDir/attributes" 321mkdir -p "$buildOutputDir" || exit 1 322 323# build cross tools from sources 324if [ -n "$buildCrossTools" ]; then 325 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 326 "$buildCrossTools" "$outputDir" || exit 1 327 crossToolsPrefix="$outputDir/cross-tools/bin/${haikuGCCMachine}-" 328fi 329 330# cross tools 331if [ -n "$crossToolsPrefix" ]; then 332 get_build_tool_path AR ar 333 get_build_tool_path CC gcc 334 get_build_tool_path LD ld 335 get_build_tool_path OBJCOPY objcopy 336 get_build_tool_path RANLIB ranlib 337fi 338 339# prepare gcc settings 340standard_gcc_settings 341 342# check whether the Haiku compiler really targets Haiku or BeOS 343case "$haikuGCCMachine" in 344 *-*-haiku) ;; 345 *-*-beos) ;; 346 *) echo The compiler specified as Haiku target compiler is not a valid \ 347 Haiku cross-compiler. Please see ReadMe.cross-compile. >&2 348 echo compiler: $HAIKU_CC 349 echo compiler is configured for target: $haikuGCCMachine 350 exit 1 ;; 351esac 352 353# Generate BuildConfig 354cat << EOF > "$buildOutputDir/BuildConfig" 355# BuildConfig 356# Note: This file has been automatically generated by configure. 357 358TARGET_PLATFORM ?= "${target}" ; 359HOST_PLATFORM ?= "${buildPlatform}" ; 360 361BOCHS_DEBUG_HACK ?= "${bochs_debug}" ; 362INCLUDE_GPL_ADDONS ?= "${include_gpl_addons}" ; 363HAIKU_INCLUDE_3RDPARTY ?= "${include_3rdparty}" ; 364HAIKU_ENABLE_MULTIUSER ?= "${enable_multiuser}" ; 365HAIKU_DISTRO_COMPATIBILITY ?= "${distroCompatibility}" ; 366HAIKU_USE_GCC_PIPE ?= "${use_gcc_pipe}" ; 367HAIKU_HOST_USE_32BIT ?= "${use_32bit}" ; 368HAIKU_HOST_USE_XATTR ?= "${use_xattr}" ; 369 370HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 371HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 372HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 373HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 374HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 375 376HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 377HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 378HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 379HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 380HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 381 382HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 383 384HAIKU_AR ?= ${HAIKU_AR} ; 385HAIKU_CC ?= ${HAIKU_CC} ; 386HAIKU_LD ?= ${HAIKU_LD} ; 387HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 388HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 389HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 390HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 391HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 392HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 393HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 394HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 395 396HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 397 398EOF 399 400# Libgcc.a objects 401 402cat << EOF > "$buildOutputDir/libgccObjects" 403# libgcc.a objects to be linked against libroot.so 404# Note: This file has been automatically generated by configure. 405 406HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 407EOF 408 409# Generate Timezones binaries bindings 410 411timezoneSources="africa antarctica asia australasia europe northamerica 412 southamerica pacificnew etcetera factory backward" 413 414cat << EOF > "$buildOutputDir/Timezones" 415# Timezones used for the build 416# Note: This file has been automatically generated by configure. 417 418HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 419 420EOF 421 422for source in ${timezoneSources}; do 423 f=$sourceDir/src/data/etc/timezones/$source 424 425TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' "$f" ` 426 427cat << EOF >> "$buildOutputDir/Timezones" 428TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 429EOF 430done 431 432# Generate a boot strap Jamfile in the output directory, if it is not in 433# the source dir. 434 435if [ "$currentDir" != "$sourceDir" ]; then 436 437cat << EOF > $outputDir/Jamfile 438# automatically generated Jamfile 439 440HAIKU_TOP = ${sourceDir} ; 441HAIKU_OUTPUT_DIR = ${outputDir} ; 442 443include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 444 445EOF 446 447fi 448 449