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