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