2007-02-04 13:50:11 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2013-07-26 01:52:11 +04:00
|
|
|
# parameters <machine> <haiku sourcedir> <buildtools dir> <isntall 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>' \
|
2013-07-26 01:52:11 +04:00
|
|
|
'<install 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
|
2013-07-26 01:52:11 +04:00
|
|
|
installDir=$4
|
2009-11-23 22:34:55 +03:00
|
|
|
shift 4
|
|
|
|
additionalMakeArgs=$*
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2014-02-06 02:20:59 +04:00
|
|
|
kernelCcFlags="-D_KERNEL_MODE"
|
2014-02-09 13:06:43 +04:00
|
|
|
ccFlags="-O2"
|
|
|
|
cxxFlags="-O2"
|
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=""
|
2014-02-06 02:20:59 +04:00
|
|
|
kernelCcFlags="$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"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-09-14 22:55:53 +04:00
|
|
|
if [ `uname -s` = 'Haiku' ]; then
|
2013-06-14 18:04:26 +04:00
|
|
|
# force cross-build if building on Haiku:
|
|
|
|
buildhostMachine=${haikuMachine}_buildhost
|
|
|
|
buildHostSpec="--build=$buildhostMachine --host=$buildhostMachine"
|
|
|
|
fi
|
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
if [ ! -d "$haikuSourceDir" ]; then
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "No such directory: \"$haikuSourceDir\"" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
if [ ! -d "$buildToolsDir" ]; then
|
2005-11-18 17:17:04 +03:00
|
|
|
echo "No such directory: \"$buildToolsDir\"" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# create the output dir
|
2013-11-26 00:07:20 +04:00
|
|
|
mkdir -p "$installDir" || exit 1
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
# get absolute paths
|
|
|
|
currentDir=$(pwd)
|
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$haikuSourceDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
haikuSourceDir=$(pwd)
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$currentDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$buildToolsDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
buildToolsDir=$(pwd)
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$currentDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$installDir"
|
2013-07-26 01:52:11 +04:00
|
|
|
installDir=$(pwd)
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$currentDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
binutilsSourceDir="$buildToolsDir/binutils"
|
|
|
|
gccSourceDir="$buildToolsDir/gcc"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
# get gcc version
|
2013-11-26 00:07:20 +04: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-11-26 00:07:20 +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
|
2013-11-26 00:07:20 +04:00
|
|
|
objDir="${installDir}-build"
|
|
|
|
binutilsObjDir="$objDir/binutils"
|
|
|
|
gccObjDir="$objDir/gcc"
|
|
|
|
stdcxxObjDir="$objDir/stdcxx"
|
|
|
|
sysrootDir="$installDir/sysroot"
|
|
|
|
tmpIncludeDir="$sysrootDir/boot/system/develop/headers"
|
|
|
|
tmpLibDir="$sysrootDir/boot/system/develop/lib"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
rm -rf "$installDir" "$objDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
mkdir -p "$installDir" "$objDir" "$binutilsObjDir" "$gccObjDir" "$stdcxxObjDir" \
|
|
|
|
"$tmpIncludeDir" "$tmpLibDir" || exit 1
|
|
|
|
mkdir -p "$installDir/lib/gcc/$haikuMachine/$gccVersion"
|
2005-12-07 01:45:11 +03:00
|
|
|
|
2013-04-06 16:32:12 +04:00
|
|
|
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
|
2013-11-26 00:07:20 +04:00
|
|
|
cloogSourceDir="$buildToolsDir/cloog"
|
|
|
|
gmpSourceDir="$buildToolsDir/gcc/gmp"
|
2014-01-28 20:50:01 +04:00
|
|
|
islSourceDir="$buildToolsDir/isl"
|
2013-11-26 00:07:20 +04:00
|
|
|
|
2014-01-28 20:50:01 +04:00
|
|
|
islObjDir="$objDir/isl"
|
2013-11-26 00:07:20 +04:00
|
|
|
gmpObjDir="$objDir/gmp"
|
|
|
|
cloogObjDir="$objDir/cloog"
|
2014-01-28 20:50:01 +04:00
|
|
|
mkdir -p "$islObjDir" "$gmpObjDir" "$cloogObjDir" || exit 1
|
2013-11-26 00:07:20 +04:00
|
|
|
|
2014-01-28 20:50:01 +04:00
|
|
|
gccConfigureArgs="$gccConfigureArgs --with-cloog=$installDir \
|
|
|
|
--enable-cloog-backend=isl --with-isl=$installDir \
|
|
|
|
--with-gmp=$installDir \
|
2013-04-11 19:57:42 +04:00
|
|
|
--with-host-libstdcxx=\"-lstdc++\""
|
2013-04-06 16:32:12 +04:00
|
|
|
fi
|
2014-02-09 13:06:43 +04:00
|
|
|
if [ "$HAIKU_USE_GCC_PIPE" = 1 ]; then
|
|
|
|
ccFlags="$ccFlags -pipe"
|
|
|
|
cxxFlags="$cxxFlags -pipe"
|
|
|
|
fi
|
2013-04-06 16:32:12 +04:00
|
|
|
|
2013-08-04 19:20:56 +04:00
|
|
|
if [ -n "$SECONDARY_ARCH" ]; then
|
2013-08-07 04:09:37 +04:00
|
|
|
gccConfigureArgs="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
|
2013-08-04 19:20:56 +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
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$binutilsObjDir"
|
2014-02-09 13:06:43 +04:00
|
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$binutilsSourceDir/configure" \
|
2013-11-26 00:07:20 +04:00
|
|
|
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
|
2013-08-28 21:59:56 +04:00
|
|
|
--enable-targets=$haikuMachine,i386-efi-pe,x86_64-efi-pe \
|
2013-06-14 18:04:26 +04:00
|
|
|
--disable-nls --disable-shared --disable-werror \
|
2013-11-26 00:07:20 +04:00
|
|
|
--with-sysroot="$sysrootDir" \
|
2013-06-14 18:04:26 +04:00
|
|
|
$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
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
export PATH=$PATH:"$installDir/bin"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
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
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$gmpObjDir"
|
2014-02-09 13:06:43 +04:00
|
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gmpSourceDir/configure" \
|
|
|
|
--prefix="$installDir" --disable-shared --enable-cxx || exit 1
|
2013-04-10 20:37:13 +04:00
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
2013-08-28 21:59:56 +04:00
|
|
|
|
2014-01-28 20:50:01 +04:00
|
|
|
# build isl
|
|
|
|
cd "$islObjDir"
|
2014-02-09 13:06:43 +04:00
|
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$islSourceDir/configure" \
|
2014-01-28 20:50:01 +04:00
|
|
|
--prefix="$installDir" --disable-nls --disable-shared \
|
|
|
|
--with-gmp-prefix="$installDir" || exit 1
|
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
2013-04-06 16:32:12 +04:00
|
|
|
|
|
|
|
# build cloog
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$cloogObjDir"
|
2014-02-09 13:06:43 +04:00
|
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$cloogSourceDir/configure" \
|
2013-11-26 00:07:20 +04:00
|
|
|
--prefix="$installDir" --disable-nls --disable-shared \
|
2014-01-28 20:50:01 +04:00
|
|
|
--with-gmp-prefix="$installDir" --with-isl-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
|
2013-11-26 00:07:20 +04:00
|
|
|
headerTargetDir="$targetDir/$(dirname $f)"
|
|
|
|
mkdir -p "$headerTargetDir"
|
|
|
|
cp "$sourceDir/$f" "$headerTargetDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
copy_headers "$haikuSourceDir/headers/config" "$tmpIncludeDir/config"
|
|
|
|
copy_headers "$haikuSourceDir/headers/os" "$tmpIncludeDir/os"
|
|
|
|
copy_headers "$haikuSourceDir/headers/posix" "$tmpIncludeDir/posix"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# configure gcc
|
2013-11-26 00:07:20 +04:00
|
|
|
cd "$gccObjDir"
|
2014-02-09 13:06:43 +04:00
|
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gccSourceDir/configure" \
|
2013-11-26 00:07:20 +04:00
|
|
|
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
|
2013-06-14 18:04:26 +04:00
|
|
|
--disable-nls --disable-shared --with-system-zlib \
|
2012-01-19 22:44:42 +04:00
|
|
|
--enable-languages=c,c++ --enable-lto --enable-frame-pointer \
|
2014-02-06 02:20:59 +04:00
|
|
|
--with-sysroot="$sysrootDir" --enable-threads=posix \
|
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
|
2014-02-06 02:20:59 +04:00
|
|
|
# switch threads config to single for libgcc
|
|
|
|
ln -sf "$gccSourceDir/libgcc/gthr-single.h" "$haikuMachine/libgcc/gthr-default.h"
|
2013-11-26 00:07:20 +04:00
|
|
|
$MAKE -C "$haikuMachine/libgcc" clean
|
|
|
|
$MAKE -C "$haikuMachine/libgcc" CFLAGS="-g -O2 $kernelCcFlags" || {
|
2012-08-16 20:38:01 +04:00
|
|
|
echo "Error: Building kernel libgcc failed." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
cp "$haikuMachine/libgcc/libgcc.a" \
|
|
|
|
"$installDir/$haikuMachine/lib/libgcc-kernel.a" || exit 1
|
2012-08-16 20:38:01 +04:00
|
|
|
|
2013-11-26 00:07:20 +04:00
|
|
|
$MAKE -C "$haikuMachine/libstdc++-v3/libsupc++" clean
|
2014-02-06 02:20:59 +04:00
|
|
|
|
|
|
|
# switch threads config to single for libsupc++
|
|
|
|
[ -f "$haikuMachine/32/libstdc++-v3/include/$haikuMachine/bits/gthr-default.h" ] \
|
|
|
|
&& cp -f "$haikuMachine/32/libstdc++-v3/include/$haikuMachine/bits/gthr-single.h" \
|
|
|
|
"$haikuMachine/32/libstdc++-v3/include/$haikuMachine/bits/gthr-default.h"
|
|
|
|
cp -f "$haikuMachine/libstdc++-v3/include/$haikuMachine/bits/gthr-single.h" \
|
|
|
|
"$haikuMachine/libstdc++-v3/include/$haikuMachine/bits/gthr-default.h"
|
|
|
|
[ -f "$haikuMachine/32/libstdc++-v3/config.h" ] \
|
|
|
|
&& sed -i '/.*_GLIBCXX_HAS_GTHREADS.*/c\#undef _GLIBCXX_HAS_GTHREADS' \
|
|
|
|
"$haikuMachine/32/libstdc++-v3/config.h"
|
|
|
|
sed -i '/.*_GLIBCXX_HAS_GTHREADS.*/c\#undef _GLIBCXX_HAS_GTHREADS' \
|
|
|
|
"$haikuMachine/libstdc++-v3/config.h"
|
2013-11-26 00:07:20 +04:00
|
|
|
$MAKE -C "$haikuMachine/libstdc++-v3/libsupc++" CFLAGS="-g -O2 $kernelCcFlags" \
|
2012-08-16 20:38:01 +04:00
|
|
|
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
|
|
|
|
2013-11-26 00:07:20 +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-11-26 00:07:20 +04:00
|
|
|
rm -rf "$installDir/$haikuMachine/sys-include"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2013-08-03 07:29:15 +04:00
|
|
|
# remove the sysroot dir
|
2013-11-26 00:07:20 +04:00
|
|
|
rm -rf "$sysrootDir"
|
2013-08-03 07:29:15 +04:00
|
|
|
|
2005-11-18 17:17:04 +03:00
|
|
|
# remove the objects dir
|
2013-11-26 00:07:20 +04:00
|
|
|
rm -rf "$objDir"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
echo "binutils and gcc for cross compilation have been built successfully!"
|