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 haikuGCCVersion=`$HAIKU_CC -dumpversion` 94 haikuGCCMachine=`$HAIKU_CC -dumpmachine` 95 96 HAIKU_GCC_LIB_DIR=${gccdir} 97 HAIKU_GCC_LIBGCC=${gccdir}/libgcc.a 98 HAIKU_GCC_GLUE_CODE="crtbegin.o crtend.o" 99 HAIKU_GCC_HEADERS_DIR=${gccdir}/include 100 HAIKU_GCC_LIBGCC_OBJECTS=`$HAIKU_AR t ${HAIKU_GCC_LIBGCC} | grep -v eabi.o` 101 # Note: We filter out eabi.o. It's present in gcc's libgcc for PPC and 102 # neither needed nor wanted. 103 104 # for gcc 4 we use the libstdc++ and libsupc++ that come with the compiler 105 case $haikuGCCVersion in 106 4.*) 107 haikuStaticLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.a` 108 haikuSharedLibStdCxx=`$HAIKU_CC -print-file-name=libstdc++.so` 109 haikuStaticLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.a` 110 haikuSharedLibSupCxx=`$HAIKU_CC -print-file-name=libsupc++.so` 111 local headers=$gccdir/../../../../include/c++/$haikuGCCVersion 112 haikuCxxHeadersDir=$headers 113 for d in $haikuGCCMachine backward ext; do 114 # Note: We need the line break, otherwise the line might become 115 # too long for jam (512 bytes max). 116 haikuCxxHeadersDir="$haikuCxxHeadersDir 117 $headers/$d" 118 done 119 120 if [ $haikuStaticLibStdCxx = libstdc++.a ]; then 121 haikuStaticLibStdCxx= 122 fi 123 if [ $haikuSharedLibStdCxx = libstdc++.so ]; then 124 haikuSharedLibStdCxx= 125 fi 126 if [ $haikuStaticLibSupCxx = libsupc++.a ]; then 127 haikuStaticLibSupCxx= 128 fi 129 if [ $haikuSharedLibSupCxx = libsupc++.so ]; then 130 haikuSharedLibSupCxx= 131 fi 132 ;; 133 esac 134} 135 136# set_default_value 137# 138# Set the value for a variable, if no value is set yet. 139# 140set_default_value() 141{ 142 eval "$1=\${$1-$2}" 143} 144 145# get_build_tool_path 146# 147# Gets a usable absolute path of a build tool. 148# 149get_build_tool_path() 150{ 151 local var="HAIKU_$1" 152 local tool=$2 153 local path="${crossToolsPrefix}$tool" 154 155 if [ -f "$path" ]; then 156 # get absolute path 157 local oldPwd=$(pwd) 158 cd $(dirname "$path") 159 path="$(pwd)/$(basename "$path")" 160 cd $oldPwd 161 else 162 which "$path" &> /dev/null || { 163 echo "Build tool \"$path\" not found." >&2 164 exit 1 165 } 166 fi 167 168 eval "$var=$path" 169} 170 171# get cwd and the source directory 172currentDir=`pwd` 173cd `dirname $0` 174sourceDir=`pwd` 175cd $currentDir 176 177# default parameter values 178# 179platform=`uname` 180haikuGCCVersion= 181haikuGCCMachine=i586-pc-beos 182haikuStaticLibStdCxx= 183haikuSharedLibStdCxx= 184haikuStaticLibSupCxx= 185haikuSharedLibSupCxx= 186haikuCxxHeadersDir= 187hostGCCVersion=`gcc -dumpversion` 188floppy= 189bochs_debug=0 190include_gpl_addons=0 191target=haiku 192crossToolsPrefix= 193buildCrossTools= 194buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools" 195buildCrossToolsMachine= 196 197set_default_value HAIKU_AR ar 198set_default_value HAIKU_CC gcc 199set_default_value HAIKU_LD ld 200set_default_value HAIKU_OBJCOPY objcopy 201set_default_value HAIKU_RANLIB ranlib 202set_default_value HAIKU_CPPFLAGS "" 203set_default_value HAIKU_CCFLAGS "" 204set_default_value HAIKU_CXXFLAGS "" 205set_default_value HAIKU_LDFLAGS "" 206set_default_value HAIKU_ARFLAGS ru 207set_default_value HAIKU_UNARFLAGS x 208 209# parse parameters 210# 211while [ $# -gt 0 ] ; do 212 case "$1" in 213 --include-gpl-addons) include_gpl_addons=1; shift 1;; 214 --floppy) assertparam "$1" $#; floppy=$2; shift 2;; 215 --bochs-debug) bochs_debug=1; shift 1;; 216 --target=*) target=`echo $1 | cut -d'=' -f2-`; shift 1;; 217 --cross-tools-prefix) assertparam "$1" $#; crossToolsPrefix=$2; shift 2;; 218 --build-cross-tools) assertparam "$1" $#; buildCrossTools=$2; shift 2;; 219 --build-cross-tools-gcc4) assertparams "$1" 2 $#; buildCrossTools=$3; 220 buildCrossToolsScript="${buildCrossToolsScript}_gcc4"; 221 case "$2" in 222 x86) haikuGCCMachine=i586-pc-haiku;; 223 ppc) haikuGCCMachine=powerpc-apple-haiku;; 224 *) echo "Unsupported target architecture: $2" 225 exit 1;; 226 esac 227 buildCrossToolsMachine=$haikuGCCMachine 228 shift 3;; 229 --help | -h) usage; exit 0;; 230 *) echo Invalid argument: \`$1\'; exit 1;; 231 esac 232done 233 234# check parameters 235# 236if [ -n "$floppy" ]; then 237 case "$floppy" in 238 /*) ;; 239 *) echo "Warning: non-absolute floppy path. Parameter ignored."; 240 floppy=;; 241 esac 242fi 243 244# detect the build platform 245case "${platform}" in 246 BeOS) revision=`uname -r` 247 case "$revision" in 248 6.*) buildPlatform=dano ;; 249 5.1) buildPlatform=dano ;; 250 5.0.4) buildPlatform=bone ;; 251 5.0*) buildPlatform=r5 ;; 252 *) echo Unknown BeOS version: $revision 253 exit 1 ;; 254 esac 255 ;; 256 Linux) buildPlatform=linux ;; 257 FreeBSD) buildPlatform=freebsd ;; 258 *) echo Unsupported platform: ${platform} 259 exit 1 ;; 260esac 261 262# create output directory 263if [ "$currentDir" = "$sourceDir" ]; then 264 outputDir=$currentDir/generated 265else 266 outputDir=$currentDir 267fi 268buildOutputDir=$outputDir/build 269buildAttributesDir=$outputDir/attributes 270mkdir -p $buildOutputDir || exit 1 271 272# build cross tools from sources 273if [ -n "$buildCrossTools" ]; then 274 "$buildCrossToolsScript" $buildCrossToolsMachine "$sourceDir" \ 275 "$buildCrossTools" $outputDir || exit 1 276 crossToolsPrefix=$outputDir/cross-tools/bin/${haikuGCCMachine}- 277fi 278 279# cross tools 280if [ -n "$crossToolsPrefix" ]; then 281 get_build_tool_path AR ar 282 get_build_tool_path CC gcc 283 get_build_tool_path LD ld 284 get_build_tool_path OBJCOPY objcopy 285 get_build_tool_path RANLIB ranlib 286fi 287 288# prepare gcc settings 289standard_gcc_settings 290 291# Generate BuildConfig 292cat << EOF > $buildOutputDir/BuildConfig 293# BuildConfig 294# Note: This file has been automatically generated by configure. 295 296FLOPPY_PATH ?= "${floppy}" ; 297BOCHS_DEBUG_HACK ?= ${bochs_debug} ; 298INCLUDE_GPL_ADDONS ?= ${include_gpl_addons} ; 299TARGET_PLATFORM ?= ${target} ; 300HOST_PLATFORM ?= ${buildPlatform} ; 301 302HAIKU_GCC_RAW_VERSION ?= ${haikuGCCVersion} ; 303HAIKU_GCC_MACHINE ?= ${haikuGCCMachine} ; 304HAIKU_GCC_LIB_DIR ?= ${HAIKU_GCC_LIB_DIR} ; 305HAIKU_GCC_HEADERS_DIR ?= ${HAIKU_GCC_HEADERS_DIR} ; 306HAIKU_GCC_LIBGCC ?= ${HAIKU_GCC_LIBGCC} ; 307 308HAIKU_STATIC_LIBSTDC++ ?= ${haikuStaticLibStdCxx} ; 309HAIKU_SHARED_LIBSTDC++ ?= ${haikuSharedLibStdCxx} ; 310HAIKU_STATIC_LIBSUPC++ ?= ${haikuStaticLibSupCxx} ; 311HAIKU_SHARED_LIBSUPC++ ?= ${haikuSharedLibSupCxx} ; 312HAIKU_C++_HEADERS_DIR ?= ${haikuCxxHeadersDir} ; 313 314HAIKU_BUILD_ATTRIBUTES_DIR ?= ${buildAttributesDir} ; 315 316HAIKU_AR ?= ${HAIKU_AR} ; 317HAIKU_CC ?= ${HAIKU_CC} ; 318HAIKU_LD ?= ${HAIKU_LD} ; 319HAIKU_OBJCOPY ?= ${HAIKU_OBJCOPY} ; 320HAIKU_RANLIB ?= ${HAIKU_RANLIB} ; 321HAIKU_CPPFLAGS ?= ${HAIKU_CPPFLAGS} ; 322HAIKU_CCFLAGS ?= ${HAIKU_CCFLAGS} ; 323HAIKU_CXXFLAGS ?= ${HAIKU_CXXFLAGS} ; 324HAIKU_LDFLAGS ?= ${HAIKU_LDFLAGS} ; 325HAIKU_ARFLAGS ?= ${HAIKU_ARFLAGS} ; 326HAIKU_UNARFLAGS ?= ${HAIKU_UNARFLAGS} ; 327 328HOST_GCC_RAW_VERSION ?= ${hostGCCVersion} ; 329 330EOF 331 332# Libgcc.a objects 333 334cat << EOF > $buildOutputDir/libgccObjects 335# libgcc.a objects to be linked against libroot.so 336# Note: This file has been automatically generated by configure. 337 338HAIKU_GCC_LIBGCC_OBJECTS ?= ${HAIKU_GCC_LIBGCC_OBJECTS} ; 339EOF 340 341# Generate Timezones binaries bindings 342 343timezoneSources="africa antarctica asia australasia europe northamerica 344 southamerica pacificnew etcetera factory backward" 345 346cat << EOF > $buildOutputDir/Timezones 347# Timezones used for the build 348# Note: This file has been automatically generated by configure. 349 350HAIKU_TIME_ZONE_SOURCES = ${timezoneSources} ; 351 352EOF 353 354for source in ${timezoneSources}; do 355 f=$sourceDir/src/data/etc/timezones/$source 356 357TZOBJECTS=`gawk '/^Zone/ { print $2 } /^Link/ { print $3 } ' $f ` 358 359cat << EOF >> $buildOutputDir/Timezones 360TZ_OBJECTS on <timezone-source>${source} ?= $TZOBJECTS ; 361EOF 362done 363 364# Generate a boot strap Jamfile in the output directory, if it is not in 365# the source dir. 366 367if [ "$currentDir" != "$sourceDir" ]; then 368 369cat << EOF > $outputDir/Jamfile 370# automatically generated Jamfile 371 372HAIKU_TOP = ${sourceDir} ; 373HAIKU_OUTPUT_DIR = ${outputDir} ; 374 375include [ FDirName \$(HAIKU_TOP) Jamfile ] ; 376 377EOF 378 379fi 380 381