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