1#!/bin/sh 2# 3# parameters <machine> <haiku sourcedir> <buildtools dir> <haiku output dir> 4 5# get and check the parameters 6if [ $# -lt 4 ]; then 7 echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir>' \ 8 '<haiku output dir>' >&2 9 exit 1 10fi 11 12haikuMachine=$1 13haikuSourceDir=$2 14buildToolsDir=$3 15haikuOutputDir=$4 16shift 4 17additionalMakeArgs=$* 18 19case `uname` in 20FreeBSD|OpenBSD) 21 MAKE=gmake 22 ;; 23*) 24 MAKE=make 25 ;; 26esac 27export MAKE 28 29case $haikuMachine in 30x86_64-*) 31 binutilsConfigureArgs="--enable-multilib" 32 gccConfigureArgs="--enable-multilib" 33 ;; 34m68k-*) 35 binutilsConfigureArgs="--enable-multilib" 36 gccConfigureArgs="--enable-multilib" 37 ;; 38arm-*) 39 binutilsConfigureArgs="--enable-multilib" 40 gccConfigureArgs="--enable-multilib" 41 ;; 42*) 43 binutilsConfigureArgs="--disable-multilib" 44 gccConfigureArgs="--disable-multilib" 45 ;; 46esac 47 48if [ ! -d $haikuSourceDir ]; then 49 echo "No such directory: \"$haikuSourceDir\"" >&2 50 exit 1 51fi 52 53if [ ! -d $buildToolsDir ]; then 54 echo "No such directory: \"$buildToolsDir\"" >&2 55 exit 1 56fi 57 58 59# create the output dir 60mkdir -p $haikuOutputDir || exit 1 61 62 63# get absolute paths 64currentDir=$(pwd) 65 66cd $haikuSourceDir 67haikuSourceDir=$(pwd) 68cd $currentDir 69 70cd $buildToolsDir 71buildToolsDir=$(pwd) 72cd $currentDir 73 74cd $haikuOutputDir 75haikuOutputDir=$(pwd) 76 77binutilsSourceDir=$buildToolsDir/binutils 78gccSourceDir=$buildToolsDir/gcc 79 80 81# get gcc version 82gccVersion=$(cat $gccSourceDir/gcc/BASE-VER) 83 84if [ -z "$gccVersion" ]; then 85 echo "Failed to find out gcc version." >&2 86 exit 1 87fi 88 89# touch all info files in order to avoid the dependency on makeinfo 90# (which apparently doesn't work reliably on all the different host 91# configurations and changes files which in turn appear as local changes 92# to the VCS). 93find $binutilsSourceDir -name \*.info -print0 | xargs -0 touch 94find $gccSourceDir -name \*.info -print0 | xargs -0 touch 95 96# create the object and installation directories for the cross compilation tools 97installDir=$haikuOutputDir/cross-tools 98objDir=$haikuOutputDir/cross-tools-build 99binutilsObjDir=$objDir/binutils 100gccObjDir=$objDir/gcc 101tmpIncludeDir=$objDir/sysincludes 102tmpLibDir=$objDir/syslibs 103 104rm -rf $installDir $objDir 105 106mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \ 107 $tmpLibDir || exit 1 108mkdir -p $installDir/lib/gcc/$haikuMachine/$gccVersion 109 110 111# build binutils 112cd $binutilsObjDir 113CFLAGS="-O2" CXXFLAGS="-O2" $binutilsSourceDir/configure \ 114 --prefix=$installDir --target=$haikuMachine --disable-nls \ 115 --disable-shared --disable-werror $binutilsConfigureArgs || exit 1 116$MAKE $additionalMakeArgs || exit 1 117$MAKE $additionalMakeArgs install || exit 1 118 119export PATH=$PATH:$installDir/bin 120 121 122# build gcc 123 124# prepare the include files 125copy_headers() 126{ 127 sourceDir=$1 128 targetDir=$2 129 130 headers="$(find $sourceDir -name \*\.h | grep -v /.svn)" 131 headers="$(echo $headers | sed -e s@$sourceDir/@@g)" 132 for f in $headers; do 133 headerTargetDir=$targetDir/$(dirname $f) 134 mkdir -p $headerTargetDir 135 cp $sourceDir/$f $headerTargetDir 136 done 137} 138 139copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config 140copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os 141copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix 142 143# configure gcc 144cd $gccObjDir 145CFLAGS="-O2" CXXFLAGS="-O2" $gccSourceDir/configure --prefix=$installDir \ 146 --target=$haikuMachine --disable-nls --disable-shared \ 147 --enable-languages=c,c++ --enable-lto --enable-frame-pointer \ 148 --with-headers=$tmpIncludeDir --with-libs=$tmpLibDir \ 149 $gccConfigureArgs || exit 1 150 151# make gcc 152$MAKE $additionalMakeArgs || { 153 echo "ERROR: Building gcc failed." >&2 154 exit 1 155} 156 157# install gcc 158$MAKE $additionalMakeArgs install || { 159 echo "ERROR: Installing the cross compiler failed." >&2 160 exit 1 161} 162 163# cleanup 164 165# remove the system headers from the installation dir 166# Only the ones from the source tree should be used. 167sysIncludeDir=$installDir/$haikuMachine/sys-include 168rm -rf $sysIncludeDir/os $sysIncludeDir/posix 169 170# remove the objects dir 171rm -rf $objDir 172 173 174echo "binutils and gcc for cross compilation have been built successfully!" 175