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 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 50 51# create the object and installation directories for the cross compilation tools 52installDir=$haikuOutputDir/cross-tools 53objDir=$haikuOutputDir/cross-tools-build 54binutilsObjDir=$objDir/binutils 55gccObjDir=$objDir/gcc 56tmpIncludeDir=$objDir/sysincludes 57tmpLibDir=$objDir/syslibs 58 59rm -rf $installDir $objDir 60 61mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \ 62 $tmpLibDir || exit 1 63mkdir -p $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion 64 65# build binutils 66cd $binutilsObjDir 67CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/binutils/configure \ 68 --prefix=$installDir --target=i586-pc-haiku --disable-nls \ 69 --enable-shared=yes --disable-werror || exit 1 70make $additionalMakeArgs || exit 1 71make $additionalMakeArgs install || exit 1 72 73PATH=$PATH:$installDir/bin 74export PATH 75 76 77# build gcc 78 79# prepare the include files 80copy_headers() 81{ 82 sourceDir=$1 83 targetDir=$2 84 85 headers="`find $sourceDir -name \*\.h | grep -v /.svn`" 86 headers="`echo $headers | sed -e s@$sourceDir/@@g`" 87 for f in $headers; do 88 headerTargetDir=$targetDir/`dirname $f` 89 mkdir -p $headerTargetDir 90 cp $sourceDir/$f $headerTargetDir 91 done 92} 93 94copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config 95copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os 96copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix 97 98# configure gcc 99cd $gccObjDir 100CFLAGS="-O2 -U_FORTIFY_SOURCE" CXXFLAGS="-O2" $buildToolsDir/gcc/configure \ 101 --prefix=$installDir \ 102 --target=i586-pc-haiku --disable-nls --enable-shared=yes \ 103 --enable-languages=c,c++ --with-headers=$tmpIncludeDir \ 104 --with-libs=$tmpLibDir || exit 1 105 106# hack the Makefile to avoid trouble with stuff we don't need anyway 107sedExpr= 108for toRemove in libiberty libio libjava libobjc libstdc++; do 109 sedExpr="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'" 110done 111echo sedExpr: $sedExpr 112mv Makefile Makefile.bak || exit 1 113eval "sed $sedExpr Makefile.bak > Makefile" || exit 1 114rm Makefile.bak 115 116# make gcc 117make cross || { 118 echo "ERROR: Building gcc failed." >&2 119 exit 1 120} 121 122# install gcc 123make install-gcc-cross || { 124 echo "ERROR: Installing the cross compiler failed." >&2 125 exit 1 126} 127 128# Remove the math.h gcc header. It has been generated by fixincludes 129# (unconditional hack: math_huge_val_ifndef) from ours and it is semantically 130# equivalent. 131rm $installDir/lib/gcc-lib/i586-pc-haiku/$haikuRequiredLegacyGCCVersion/include/math.h 132 133 134# cleanup 135 136# remove the system headers from the installation dir 137# Only the ones from the source tree should be used. 138sysIncludeDir=$installDir/i586-pc-haiku/sys-include 139rm -rf $sysIncludeDir/be $sysIncludeDir/posix 140 141# remove the objects dir 142rm -rf $objDir 143 144 145echo "binutils and gcc for cross compilation have been built successfully!" 146 147