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