2007-02-04 13:50:11 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2005-12-07 01:45:11 +03:00
|
|
|
# parameters <machine> <haiku sourcedir> <buildtools dir> [ <haiku output dir> ]
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# get and check the parameters
|
2005-12-07 01:45:11 +03:00
|
|
|
if [ $# -lt 3 ]; then
|
|
|
|
echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir> [ <haiku output dir> ]' >&2
|
2005-11-18 17:17:04 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-12-07 01:45:11 +03:00
|
|
|
haikuMachine=$1
|
|
|
|
haikuSourceDir=$2
|
|
|
|
buildToolsDir=$3
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2005-11-18 19:35:32 +03:00
|
|
|
if [ $(uname) = "FreeBSD" ]; then make="gmake"; else make="make"; fi
|
|
|
|
|
2005-12-07 01:45:11 +03:00
|
|
|
if [ $# -lt 4 ]; then
|
2005-11-18 17:17:04 +03:00
|
|
|
haikuOutputDir=$haikuSourceDir/generated
|
|
|
|
else
|
2005-12-07 01:45:11 +03:00
|
|
|
haikuOutputDir=$4
|
2005-11-18 17:17:04 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $haikuSourceDir ]; then
|
|
|
|
echo "No such directory: \"$haikuSourceDir\"" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $buildToolsDir ]; then
|
|
|
|
echo "No such directory: \"$buildToolsDir\"" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# create the output dir
|
|
|
|
mkdir -p $haikuOutputDir || exit 1
|
|
|
|
|
|
|
|
|
|
|
|
# get absolute paths
|
|
|
|
currentDir=$(pwd)
|
|
|
|
|
|
|
|
cd $haikuSourceDir
|
|
|
|
haikuSourceDir=$(pwd)
|
|
|
|
cd $currentDir
|
|
|
|
|
|
|
|
cd $buildToolsDir
|
|
|
|
buildToolsDir=$(pwd)
|
|
|
|
cd $currentDir
|
|
|
|
|
|
|
|
cd $haikuOutputDir
|
|
|
|
haikuOutputDir=$(pwd)
|
|
|
|
|
|
|
|
binutilsSourceDir=$buildToolsDir/binutils
|
2005-11-23 02:34:51 +03:00
|
|
|
gccSourceDir=$buildToolsDir/gcc
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
# get gcc version
|
2007-03-04 07:47:55 +03:00
|
|
|
gccVersion=$(cat $gccSourceDir/gcc/BASE-VER)
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
if [ -z "$gccVersion" ]; then
|
|
|
|
echo "Failed to find out gcc version." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# create the object and installation directories for the cross compilation tools
|
2006-10-04 03:41:59 +04:00
|
|
|
installDir=$haikuOutputDir/cross-tools
|
|
|
|
objDir=$haikuOutputDir/cross-tools-build
|
2005-11-18 17:17:04 +03:00
|
|
|
binutilsObjDir=$objDir/binutils
|
|
|
|
gccObjDir=$objDir/gcc
|
|
|
|
tmpIncludeDir=$objDir/sysincludes
|
|
|
|
tmpLibDir=$objDir/syslibs
|
|
|
|
|
|
|
|
rm -rf $installDir $objDir
|
|
|
|
|
|
|
|
mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
|
|
|
|
$tmpLibDir || exit 1
|
2005-12-07 01:45:11 +03:00
|
|
|
mkdir -p $installDir/lib/gcc/$haikuMachine/$gccVersion
|
|
|
|
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# build binutils
|
|
|
|
cd $binutilsObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $binutilsSourceDir/configure \
|
2005-12-07 01:45:11 +03:00
|
|
|
--prefix=$installDir --target=$haikuMachine --disable-nls \
|
2005-12-05 18:01:20 +03:00
|
|
|
--disable-shared || exit 1
|
2005-11-18 19:35:32 +03:00
|
|
|
$make || exit 1
|
|
|
|
$make install || exit 1
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
export PATH=$PATH:$installDir/bin
|
|
|
|
|
|
|
|
|
|
|
|
# build gcc
|
|
|
|
|
|
|
|
# prepare the include files
|
|
|
|
copy_headers()
|
|
|
|
{
|
|
|
|
sourceDir=$1
|
|
|
|
targetDir=$2
|
|
|
|
|
|
|
|
headers="$(find $sourceDir -name \*\.h | grep -v /.svn)"
|
|
|
|
headers="$(echo $headers | sed -e s@$sourceDir/@@g)"
|
|
|
|
for f in $headers; do
|
|
|
|
headerTargetDir=$targetDir/$(dirname $f)
|
|
|
|
mkdir -p $headerTargetDir
|
|
|
|
cp $sourceDir/$f $headerTargetDir
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/be
|
|
|
|
copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
|
|
|
|
|
|
|
|
# configure gcc
|
|
|
|
cd $gccObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $gccSourceDir/configure --prefix=$installDir \
|
2005-12-07 01:45:11 +03:00
|
|
|
--target=$haikuMachine --disable-nls --disable-shared \
|
2005-11-18 17:17:04 +03:00
|
|
|
--enable-languages=c,c++ --with-headers=$tmpIncludeDir \
|
|
|
|
--with-libs=$tmpLibDir || exit 1
|
|
|
|
|
|
|
|
# make gcc
|
2005-11-18 19:35:32 +03:00
|
|
|
$make || {
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "ERROR: Building gcc failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# install gcc
|
2005-11-18 19:35:32 +03:00
|
|
|
$make install || {
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "ERROR: Installing the cross compiler failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
|
|
|
|
# remove the system headers from the installation dir
|
|
|
|
# Only the ones from the source tree should be used.
|
2005-12-07 01:45:11 +03:00
|
|
|
sysIncludeDir=$installDir/$haikuMachine/sys-include
|
2005-11-18 17:17:04 +03:00
|
|
|
rm -rf $sysIncludeDir/be $sysIncludeDir/posix
|
|
|
|
|
|
|
|
# remove the objects dir
|
|
|
|
rm -rf $objDir
|
|
|
|
|
|
|
|
|
|
|
|
echo "binutils and gcc for cross compilation have been built successfully!"
|