1#!/bin/sh 2# 3# parameters <machine> <haiku sourcedir> <buildtools dir> [ <haiku output dir> ] 4 5# get and check the parameters 6if [ $# -lt 3 ]; then 7 echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir> [ <haiku output dir> ]' >&2 8 exit 1 9fi 10 11haikuMachine=$1 12haikuSourceDir=$2 13buildToolsDir=$3 14 15if [ $(uname) = "FreeBSD" ]; then make="gmake"; else make="make"; fi 16 17if [ $# -lt 4 ]; then 18 haikuOutputDir=$haikuSourceDir/generated 19else 20 haikuOutputDir=$4 21fi 22 23if [ ! -d $haikuSourceDir ]; then 24 echo "No such directory: \"$haikuSourceDir\"" >&2 25 exit 1 26fi 27 28if [ ! -d $buildToolsDir ]; then 29 echo "No such directory: \"$buildToolsDir\"" >&2 30 exit 1 31fi 32 33 34# create the output dir 35mkdir -p $haikuOutputDir || exit 1 36 37 38# get absolute paths 39currentDir=$(pwd) 40 41cd $haikuSourceDir 42haikuSourceDir=$(pwd) 43cd $currentDir 44 45cd $buildToolsDir 46buildToolsDir=$(pwd) 47cd $currentDir 48 49cd $haikuOutputDir 50haikuOutputDir=$(pwd) 51 52binutilsSourceDir=$buildToolsDir/binutils 53gccSourceDir=$buildToolsDir/gcc 54 55 56# get gcc version 57gccVersion=$(cat $gccSourceDir/gcc/BASE-VER) 58 59if [ -z "$gccVersion" ]; then 60 echo "Failed to find out gcc version." >&2 61 exit 1 62fi 63 64 65# create the object and installation directories for the cross compilation tools 66installDir=$haikuOutputDir/cross-tools 67objDir=$haikuOutputDir/cross-tools-build 68binutilsObjDir=$objDir/binutils 69gccObjDir=$objDir/gcc 70tmpIncludeDir=$objDir/sysincludes 71tmpLibDir=$objDir/syslibs 72 73rm -rf $installDir $objDir 74 75mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \ 76 $tmpLibDir || exit 1 77mkdir -p $installDir/lib/gcc/$haikuMachine/$gccVersion 78 79 80# build binutils 81cd $binutilsObjDir 82CFLAGS="-O2" CXXFLAGS="-O2" $binutilsSourceDir/configure \ 83 --prefix=$installDir --target=$haikuMachine --disable-nls \ 84 --disable-shared || exit 1 85$make || exit 1 86$make install || exit 1 87 88export PATH=$PATH:$installDir/bin 89 90 91# build gcc 92 93# prepare the include files 94copy_headers() 95{ 96 sourceDir=$1 97 targetDir=$2 98 99 headers="$(find $sourceDir -name \*\.h | grep -v /.svn)" 100 headers="$(echo $headers | sed -e s@$sourceDir/@@g)" 101 for f in $headers; do 102 headerTargetDir=$targetDir/$(dirname $f) 103 mkdir -p $headerTargetDir 104 cp $sourceDir/$f $headerTargetDir 105 done 106} 107 108copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/be 109copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix 110 111# configure gcc 112cd $gccObjDir 113CFLAGS="-O2" CXXFLAGS="-O2" $gccSourceDir/configure --prefix=$installDir \ 114 --target=$haikuMachine --disable-nls --disable-shared \ 115 --enable-languages=c,c++ --with-headers=$tmpIncludeDir \ 116 --with-libs=$tmpLibDir || exit 1 117 118# make gcc 119$make || { 120 echo "ERROR: Building gcc failed." >&2 121 exit 1 122} 123 124# install gcc 125$make install || { 126 echo "ERROR: Installing the cross compiler failed." >&2 127 exit 1 128} 129 130# cleanup 131 132# remove the system headers from the installation dir 133# Only the ones from the source tree should be used. 134sysIncludeDir=$installDir/$haikuMachine/sys-include 135rm -rf $sysIncludeDir/be $sysIncludeDir/posix 136 137# remove the objects dir 138rm -rf $objDir 139 140 141echo "binutils and gcc for cross compilation have been built successfully!" 142