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