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