1#!/bin/sh 2 3# parameters <haiku sourcedir> <buildtools dir> <haiku output dir> 4 5# get and check the parameters 6if [ $# -lt 3 ]; then 7 echo Usage: $0 '<haiku sourcedir> <buildtools dir> <haiku output dir>' >&2 8 exit 1 9fi 10 11haikuSourceDir=$1 12buildToolsDir=$2/legacy 13haikuOutputDir=$3 14shift 3 15additionalMakeArgs=$* 16 # Note: The gcc 2 build has trouble with -jN N > 1, hence we only use the 17 # additional flags for the binutils build. Should there ever be any other 18 # flags than -jN, we need to handle this differently. 19 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 31if ! grep "$haikuRequiredLegacyGCCVersion" \ 32 $buildToolsDir/gcc/gcc/version.c >/dev/null 2>&1 ; then 33 echo "*** Mismatching compiler versions between configure script and" >&2 34 echo "*** $buildToolsDir/gcc/gcc/version.c" >&2 35 echo "*** Did you perhaps update only one of haiku & buildtools?" >&2 36 exit 1 37fi 38 39 40# create the output dir 41mkdir -p $haikuOutputDir || exit 1 42 43 44# get absolute paths 45currentDir=`pwd` 46 47cd $haikuSourceDir 48haikuSourceDir=`pwd` 49cd $currentDir 50 51cd $buildToolsDir 52buildToolsDir=`pwd` 53cd $currentDir 54 55cd $haikuOutputDir 56haikuOutputDir=`pwd` 57 58 59# create the object and installation directories for the cross compilation tools 60installDir=$haikuOutputDir/cross-tools 61objDir=$haikuOutputDir/cross-tools-build 62binutilsObjDir=$objDir/binutils 63gccObjDir=$objDir/gcc 64tmpIncludeDir=$objDir/sysincludes 65tmpLibDir=$objDir/syslibs 66 67rm -rf $installDir $objDir 68 69mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \ 70 $tmpLibDir || exit 1 71mkdir -p $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion 72 73# build binutils 74cd $binutilsObjDir 75CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/binutils/configure \ 76 --prefix=$installDir --target=i586-pc-haiku --disable-nls \ 77 --enable-shared=yes --disable-werror || exit 1 78make $additionalMakeArgs || exit 1 79make $additionalMakeArgs install || exit 1 80 81PATH=$PATH:$installDir/bin 82export PATH 83 84 85# build gcc 86 87# prepare the include files 88copy_headers() 89{ 90 sourceDir=$1 91 targetDir=$2 92 93 headers="`find $sourceDir -name \*\.h | grep -v /.svn`" 94 headers="`echo $headers | sed -e s@$sourceDir/@@g`" 95 for f in $headers; do 96 headerTargetDir=$targetDir/`dirname $f` 97 mkdir -p $headerTargetDir 98 cp $sourceDir/$f $headerTargetDir 99 done 100} 101 102copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config 103copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os 104copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix 105 106# configure gcc 107cd $gccObjDir 108CFLAGS="-O2 -U_FORTIFY_SOURCE" CXXFLAGS="-O2" $buildToolsDir/gcc/configure \ 109 --prefix=$installDir \ 110 --target=i586-pc-haiku --disable-nls --enable-shared=yes \ 111 --enable-languages=c,c++ --with-headers=$tmpIncludeDir \ 112 --with-libs=$tmpLibDir || exit 1 113 114# hack the Makefile to avoid trouble with stuff we don't need anyway 115sedExpr= 116for toRemove in libiberty libio libjava libobjc libstdc++; do 117 sedExpr="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'" 118done 119echo sedExpr: $sedExpr 120mv Makefile Makefile.bak || exit 1 121eval "sed $sedExpr Makefile.bak > Makefile" || exit 1 122rm Makefile.bak 123 124# make gcc 125make cross || { 126 echo "ERROR: Building gcc failed." >&2 127 exit 1 128} 129 130# install gcc 131make install-gcc-cross || { 132 echo "ERROR: Installing the cross compiler failed." >&2 133 exit 1 134} 135 136# Remove the math.h gcc header. It has been generated by fixincludes 137# (unconditional hack: math_huge_val_ifndef) from ours and it is semantically 138# equivalent. 139rm $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion/include/math.h 140 141 142# cleanup 143 144# remove the system headers from the installation dir 145# Only the ones from the source tree should be used. 146sysIncludeDir=$installDir/i586-pc-haiku/sys-include 147rm -rf $sysIncludeDir/be $sysIncludeDir/posix 148 149# remove the objects dir 150rm -rf $objDir 151 152 153echo "binutils and gcc for cross compilation have been built successfully!" 154 155