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