2007-02-04 13:50:11 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2009-11-23 22:34:55 +03:00
|
|
|
# parameters <machine> <haiku sourcedir> <buildtools dir> <haiku output dir>
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# get and check the parameters
|
2009-11-23 22:34:55 +03:00
|
|
|
if [ $# -lt 4 ]; 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
|
2009-11-23 22:34:55 +03:00
|
|
|
haikuOutputDir=$4
|
|
|
|
shift 4
|
|
|
|
additionalMakeArgs=$*
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2011-05-25 01:14:41 +04:00
|
|
|
case `uname` in
|
2008-10-20 23:40:36 +04:00
|
|
|
FreeBSD|OpenBSD)
|
|
|
|
MAKE=gmake
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
MAKE=make
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
export MAKE
|
2005-11-18 19:35:32 +03:00
|
|
|
|
2009-08-09 19:38:41 +04:00
|
|
|
case $haikuMachine in
|
2010-07-15 03:03:59 +04:00
|
|
|
x86_64-*)
|
2012-04-04 23:51:10 +04:00
|
|
|
# GCC's default is to enable multilib, but there is a bug when
|
|
|
|
# explicitly using --enable-multilib that causes a build
|
|
|
|
# failure
|
|
|
|
binutilsConfigureArgs=""
|
|
|
|
gccConfigureArgs=""
|
2012-08-16 20:38:01 +04:00
|
|
|
kernelCcFlags="-mno-red-zone"
|
2010-07-15 03:03:59 +04:00
|
|
|
;;
|
2009-08-09 19:38:41 +04:00
|
|
|
m68k-*)
|
|
|
|
binutilsConfigureArgs="--enable-multilib"
|
|
|
|
gccConfigureArgs="--enable-multilib"
|
|
|
|
;;
|
|
|
|
arm-*)
|
|
|
|
binutilsConfigureArgs="--enable-multilib"
|
|
|
|
gccConfigureArgs="--enable-multilib"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
binutilsConfigureArgs="--disable-multilib"
|
|
|
|
gccConfigureArgs="--disable-multilib"
|
2012-08-16 20:38:01 +04:00
|
|
|
kernelCcFlags=
|
2009-08-09 19:38:41 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-06-14 18:04:26 +04:00
|
|
|
if [ `uname -o` = 'Haiku' ]; then
|
|
|
|
# force cross-build if building on Haiku:
|
|
|
|
buildhostMachine=${haikuMachine}_buildhost
|
|
|
|
buildHostSpec="--build=$buildhostMachine --host=$buildhostMachine"
|
|
|
|
fi
|
|
|
|
|
2005-11-18 17:17:04 +03:00
|
|
|
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
|
|
|
|
|
2011-10-30 23:39:12 +04:00
|
|
|
# touch all info files in order to avoid the dependency on makeinfo
|
|
|
|
# (which apparently doesn't work reliably on all the different host
|
|
|
|
# configurations and changes files which in turn appear as local changes
|
|
|
|
# to the VCS).
|
2013-04-06 16:32:12 +04:00
|
|
|
find $binutilsSourceDir $gccSourceDir -name \*.info -print0 | xargs -0 touch
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# 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
|
2012-08-16 16:47:49 +04:00
|
|
|
stdcxxObjDir=$objDir/stdcxx
|
2005-11-18 17:17:04 +03:00
|
|
|
tmpIncludeDir=$objDir/sysincludes
|
|
|
|
tmpLibDir=$objDir/syslibs
|
|
|
|
|
|
|
|
rm -rf $installDir $objDir
|
|
|
|
|
2012-08-16 16:47:49 +04:00
|
|
|
mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $stdcxxObjDir \
|
|
|
|
$tmpIncludeDir $tmpLibDir || exit 1
|
2005-12-07 01:45:11 +03:00
|
|
|
mkdir -p $installDir/lib/gcc/$haikuMachine/$gccVersion
|
|
|
|
|
2013-04-06 16:32:12 +04:00
|
|
|
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
|
|
|
|
cloogSourceDir=$buildToolsDir/cloog
|
2013-04-10 20:37:13 +04:00
|
|
|
gmpSourceDir=$buildToolsDir/gcc/gmp
|
2013-04-06 16:32:12 +04:00
|
|
|
pplSourceDir=$buildToolsDir/ppl
|
2013-04-09 23:47:34 +04:00
|
|
|
|
2013-04-06 16:32:12 +04:00
|
|
|
pplObjDir=$objDir/ppl
|
2013-04-10 20:37:13 +04:00
|
|
|
gmpObjDir=$objDir/gmp
|
2013-04-06 16:32:12 +04:00
|
|
|
cloogObjDir=$objDir/cloog
|
2013-04-10 20:37:13 +04:00
|
|
|
mkdir -p $pplObjDir $gmpObjDir $cloogObjDir || exit 1
|
2013-04-06 16:32:12 +04:00
|
|
|
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --with-cloog=$installDir \
|
|
|
|
--enable-cloog-backend=isl --with-ppl=$installDir \
|
2013-04-11 01:22:40 +04:00
|
|
|
--disable-cloog-version-check --with-gmp=$installDir \
|
2013-04-11 19:57:42 +04:00
|
|
|
--with-host-libstdcxx=\"-lstdc++\""
|
2013-04-06 16:32:12 +04:00
|
|
|
fi
|
|
|
|
|
2012-11-08 00:38:03 +04:00
|
|
|
# force the POSIX locale, as the build (makeinfo) might choke otherwise
|
|
|
|
export LC_ALL=POSIX
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# build binutils
|
|
|
|
cd $binutilsObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $binutilsSourceDir/configure \
|
2013-06-14 18:04:26 +04:00
|
|
|
--prefix=$installDir $buildHostSpec --target=$haikuMachine \
|
|
|
|
--disable-nls --disable-shared --disable-werror $binutilsConfigureArgs \
|
|
|
|
|| exit 1
|
2009-11-23 22:34:55 +03:00
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
export PATH=$PATH:$installDir/bin
|
|
|
|
|
2013-04-06 16:32:12 +04:00
|
|
|
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
|
2013-04-10 20:37:13 +04:00
|
|
|
# build gmp
|
|
|
|
cd $gmpObjDir
|
|
|
|
$gmpSourceDir/configure --prefix=$installDir \
|
|
|
|
--disable-shared --enable-cxx || exit 1
|
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
|
2013-04-06 16:32:12 +04:00
|
|
|
# build ppl
|
|
|
|
cd $pplObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $pplSourceDir/configure --prefix=$installDir \
|
|
|
|
--disable-nls --disable-shared --disable-watchdog \
|
2013-04-09 23:47:34 +04:00
|
|
|
--disable-maintainer-mode || exit 1
|
2013-04-11 20:09:35 +04:00
|
|
|
$MAKE $additionalMakeArgs AUTOCONF:=true AUTOHEADER:=true ACLOCAL:=true \
|
|
|
|
AUTOMAKE:=true || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install AUTOCONF:=true AUTOHEADER:=true \
|
|
|
|
ACLOCAL:=true AUTOMAKE:=true || exit 1
|
2013-04-06 16:32:12 +04:00
|
|
|
|
|
|
|
# build cloog
|
|
|
|
cd $cloogObjDir
|
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $cloogSourceDir/configure \
|
2013-04-10 20:37:13 +04:00
|
|
|
--prefix=$installDir --disable-nls --disable-shared \
|
|
|
|
--with-gmp-prefix=$installDir || exit 1
|
2013-04-06 16:32:12 +04:00
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
fi
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# build gcc
|
|
|
|
|
|
|
|
# prepare the include files
|
|
|
|
copy_headers()
|
|
|
|
{
|
|
|
|
sourceDir=$1
|
|
|
|
targetDir=$2
|
|
|
|
|
2012-10-31 01:29:10 +04:00
|
|
|
headers="$(find $sourceDir -name \*\.h)"
|
2005-11-18 17:17:04 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-11-24 22:44:07 +03:00
|
|
|
copy_headers $haikuSourceDir/headers/config $tmpIncludeDir/config
|
2009-01-27 02:57:59 +03:00
|
|
|
copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/os
|
2005-11-18 17:17:04 +03:00
|
|
|
copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
|
|
|
|
|
|
|
|
# configure gcc
|
|
|
|
cd $gccObjDir
|
2013-06-14 18:04:26 +04:00
|
|
|
CFLAGS="-O2" CXXFLAGS="-O2" $gccSourceDir/configure \
|
|
|
|
--prefix=$installDir $buildHostSpec --target=$haikuMachine \
|
|
|
|
--disable-nls --disable-shared --with-system-zlib \
|
2012-01-19 22:44:42 +04:00
|
|
|
--enable-languages=c,c++ --enable-lto --enable-frame-pointer \
|
2009-08-09 19:38:41 +04:00
|
|
|
--with-headers=$tmpIncludeDir --with-libs=$tmpLibDir \
|
2013-06-14 18:04:26 +04:00
|
|
|
$gccConfigureArgs \
|
|
|
|
|| exit 1
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# make gcc
|
2009-11-23 22:34:55 +03:00
|
|
|
$MAKE $additionalMakeArgs || {
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "ERROR: Building gcc failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# install gcc
|
2009-11-23 22:34:55 +03:00
|
|
|
$MAKE $additionalMakeArgs install || {
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "ERROR: Installing the cross compiler failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-08-16 20:38:01 +04:00
|
|
|
# build libraries for the kernel if the target arch requires it
|
|
|
|
if [ -n "$kernelCcFlags" ]; then
|
|
|
|
$MAKE -C $haikuMachine/libgcc clean
|
|
|
|
$MAKE -C $haikuMachine/libgcc CFLAGS="-g -O2 $kernelCcFlags" || {
|
|
|
|
echo "Error: Building kernel libgcc failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
cp $haikuMachine/libgcc/libgcc.a \
|
|
|
|
$installDir/$haikuMachine/lib/libgcc-kernel.a || exit 1
|
|
|
|
|
|
|
|
$MAKE -C $haikuMachine/libstdc++-v3/libsupc++ clean
|
|
|
|
$MAKE -C $haikuMachine/libstdc++-v3/libsupc++ CFLAGS="-g -O2 $kernelCcFlags" \
|
|
|
|
CXXFLAGS="-g -O2 $kernelCcFlags" || {
|
2012-08-16 16:47:49 +04:00
|
|
|
echo "Error: Building kernel libsupc++ failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2012-08-16 20:38:01 +04:00
|
|
|
|
|
|
|
cp $haikuMachine/libstdc++-v3/libsupc++/.libs/libsupc++.a \
|
|
|
|
$installDir/$haikuMachine/lib/libsupc++-kernel.a || exit 1
|
2012-08-16 16:47:49 +04:00
|
|
|
fi
|
|
|
|
|
2005-11-18 17:17:04 +03:00
|
|
|
# cleanup
|
|
|
|
|
|
|
|
# remove the system headers from the installation dir
|
|
|
|
# Only the ones from the source tree should be used.
|
2013-06-14 18:07:06 +04:00
|
|
|
rm -rf $installDir/$haikuMachine/sys-include
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# remove the objects dir
|
|
|
|
rm -rf $objDir
|
|
|
|
|
|
|
|
|
|
|
|
echo "binutils and gcc for cross compilation have been built successfully!"
|