2b103ca8be
Since hrev47198 we have ELF-based TLS support in Haiku. When building gcc with haikuporter, this is detected by the configure script, but when cross compiling gcc we need to manually enable it, as no runtime check can be performed to detect the feature. This should fix #10938 by avoiding the mix of TLS and non-TLS libstdc++.
278 lines
8.0 KiB
Bash
Executable File
278 lines
8.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# parameters <machine> <haiku sourcedir> <buildtools dir> <isntall dir>
|
|
|
|
# get and check the parameters
|
|
if [ $# -lt 4 ]; then
|
|
echo Usage: $0 '<machine> <haiku sourcedir> <buildtools dir>' \
|
|
'<install dir>' >&2
|
|
exit 1
|
|
fi
|
|
|
|
haikuMachine=$1
|
|
haikuSourceDir=$2
|
|
buildToolsDir=$3
|
|
installDir=$4
|
|
shift 4
|
|
additionalMakeArgs=$*
|
|
|
|
kernelCcFlags="-D_KERNEL_MODE"
|
|
ccFlags="-O2"
|
|
cxxFlags="-O2"
|
|
case $haikuMachine in
|
|
x86_64-*)
|
|
# GCC's default is to enable multilib, but there is a bug when
|
|
# explicitly using --enable-multilib that causes a build
|
|
# failure
|
|
binutilsConfigureArgs=""
|
|
gccConfigureArgs=""
|
|
kernelCcFlags="$kernelCcFlags -mno-red-zone"
|
|
;;
|
|
m68k-*)
|
|
binutilsConfigureArgs="--enable-multilib"
|
|
gccConfigureArgs="--enable-multilib"
|
|
;;
|
|
arm-*)
|
|
# Multilib creates a lot of confusion as the wrong libs end up being linked.
|
|
# For now, target Cortex-A8 devices.
|
|
binutilsConfigureArgs="--disable-multilib --with-float=hard
|
|
--with-cpu=cortex-a8 --with-arch=armv7-a --with-fpu=vfpv3"
|
|
gccConfigureArgs="--disable-multilib --with-float=hard
|
|
--with-cpu=cortex-a8 --with-arch=armv7-a --with-fpu=vfpv3"
|
|
;;
|
|
*)
|
|
binutilsConfigureArgs="--disable-multilib"
|
|
gccConfigureArgs="--disable-multilib"
|
|
;;
|
|
esac
|
|
|
|
if [ `uname -s` = 'Haiku' ]; then
|
|
# force cross-build if building on Haiku:
|
|
buildhostMachine=${haikuMachine}_buildhost
|
|
buildHostSpec="--build=$buildhostMachine --host=$buildhostMachine"
|
|
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 "$installDir" || exit 1
|
|
|
|
|
|
# get absolute paths
|
|
currentDir=$(pwd)
|
|
|
|
cd "$haikuSourceDir"
|
|
haikuSourceDir=$(pwd)
|
|
cd "$currentDir"
|
|
|
|
cd "$buildToolsDir"
|
|
buildToolsDir=$(pwd)
|
|
cd "$currentDir"
|
|
|
|
cd "$installDir"
|
|
installDir=$(pwd)
|
|
cd "$currentDir"
|
|
|
|
binutilsSourceDir="$buildToolsDir/binutils"
|
|
gccSourceDir="$buildToolsDir/gcc"
|
|
|
|
|
|
# get gcc version
|
|
gccVersion=$(cat "$gccSourceDir/gcc/BASE-VER")
|
|
|
|
if [ -z "$gccVersion" ]; then
|
|
echo "Failed to find out gcc version." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# 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).
|
|
find "$binutilsSourceDir" "$gccSourceDir" -name \*.info -print0 | xargs -0 touch
|
|
|
|
# create the object and installation directories for the cross compilation tools
|
|
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"
|
|
|
|
rm -rf "$installDir" "$objDir"
|
|
|
|
mkdir -p "$installDir" "$objDir" "$binutilsObjDir" "$gccObjDir" "$stdcxxObjDir" \
|
|
"$tmpIncludeDir" "$tmpLibDir" || exit 1
|
|
mkdir -p "$installDir/lib/gcc/$haikuMachine/$gccVersion"
|
|
|
|
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
|
|
cloogSourceDir="$buildToolsDir/cloog"
|
|
gmpSourceDir="$buildToolsDir/gcc/gmp"
|
|
islSourceDir="$buildToolsDir/isl"
|
|
|
|
islObjDir="$objDir/isl"
|
|
gmpObjDir="$objDir/gmp"
|
|
cloogObjDir="$objDir/cloog"
|
|
mkdir -p "$islObjDir" "$gmpObjDir" "$cloogObjDir" || exit 1
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --with-cloog=$installDir \
|
|
--enable-cloog-backend=isl --with-isl=$installDir \
|
|
--with-gmp=$installDir \
|
|
--with-host-libstdcxx=\"-lstdc++\""
|
|
fi
|
|
if [ "$HAIKU_USE_GCC_PIPE" = 1 ]; then
|
|
ccFlags="$ccFlags -pipe"
|
|
cxxFlags="$cxxFlags -pipe"
|
|
fi
|
|
|
|
if [ -n "$SECONDARY_ARCH" ]; then
|
|
gccConfigureArgs="$gccConfigureArgs --with-hybrid-secondary=$SECONDARY_ARCH"
|
|
fi
|
|
|
|
# force the POSIX locale, as the build (makeinfo) might choke otherwise
|
|
export LC_ALL=POSIX
|
|
|
|
# build binutils
|
|
cd "$binutilsObjDir"
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$binutilsSourceDir/configure" \
|
|
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
|
|
--enable-targets=$haikuMachine,i386-efi-pe,x86_64-efi-pe \
|
|
--disable-nls --disable-shared --disable-werror \
|
|
--with-sysroot="$sysrootDir" \
|
|
$binutilsConfigureArgs \
|
|
|| exit 1
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
export PATH=$PATH:"$installDir/bin"
|
|
|
|
if [ "$HAIKU_USE_GCC_GRAPHITE" = 1 ]; then
|
|
# build gmp
|
|
cd "$gmpObjDir"
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gmpSourceDir/configure" \
|
|
--prefix="$installDir" --disable-shared --enable-cxx || exit 1
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
# build isl
|
|
cd "$islObjDir"
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$islSourceDir/configure" \
|
|
--prefix="$installDir" --disable-nls --disable-shared \
|
|
--with-gmp-prefix="$installDir" || exit 1
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
# build cloog
|
|
cd "$cloogObjDir"
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$cloogSourceDir/configure" \
|
|
--prefix="$installDir" --disable-nls --disable-shared \
|
|
--with-gmp-prefix="$installDir" --with-isl-prefix=="$installDir" \
|
|
|| exit 1
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
fi
|
|
|
|
# build gcc
|
|
|
|
# prepare the include files
|
|
copy_headers()
|
|
{
|
|
sourceDir=$1
|
|
targetDir=$2
|
|
|
|
headers="$(find $sourceDir -name \*\.h)"
|
|
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/config" "$tmpIncludeDir/config"
|
|
copy_headers "$haikuSourceDir/headers/os" "$tmpIncludeDir/os"
|
|
copy_headers "$haikuSourceDir/headers/posix" "$tmpIncludeDir/posix"
|
|
|
|
# configure gcc
|
|
cd "$gccObjDir"
|
|
CFLAGS="$ccFlags" CXXFLAGS="$cxxFlags" "$gccSourceDir/configure" \
|
|
--prefix="$installDir" $buildHostSpec --target=$haikuMachine \
|
|
--disable-nls --disable-shared --with-system-zlib \
|
|
--enable-languages=c,c++ --enable-lto --enable-frame-pointer \
|
|
--with-sysroot="$sysrootDir" --enable-threads=posix --enable-tls \
|
|
$gccConfigureArgs \
|
|
|| exit 1
|
|
|
|
# make gcc
|
|
$MAKE $additionalMakeArgs || {
|
|
echo "ERROR: Building gcc failed." >&2
|
|
exit 1
|
|
}
|
|
|
|
# install gcc
|
|
$MAKE $additionalMakeArgs install || {
|
|
echo "ERROR: Installing the cross compiler failed." >&2
|
|
exit 1
|
|
}
|
|
|
|
# build libraries for the kernel if the target arch requires it
|
|
if [ -n "$kernelCcFlags" ]; then
|
|
# switch threads config to single for libgcc
|
|
ln -sf "$gccSourceDir/libgcc/gthr-single.h" "$haikuMachine/libgcc/gthr-default.h"
|
|
$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
|
|
|
|
# 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"
|
|
$MAKE -C "$haikuMachine/libstdc++-v3/libsupc++" CFLAGS="-g -O2 $kernelCcFlags" \
|
|
CXXFLAGS="-g -O2 $kernelCcFlags" || {
|
|
echo "Error: Building kernel libsupc++ failed." >&2
|
|
exit 1
|
|
}
|
|
|
|
cp "$haikuMachine/libstdc++-v3/libsupc++/.libs/libsupc++.a" \
|
|
"$installDir/$haikuMachine/lib/libsupc++-kernel.a" || exit 1
|
|
fi
|
|
|
|
# cleanup
|
|
|
|
# remove the system headers from the installation dir
|
|
# Only the ones from the source tree should be used.
|
|
rm -rf "$installDir/$haikuMachine/sys-include"
|
|
|
|
# remove the sysroot dir
|
|
rm -rf "$sysrootDir"
|
|
|
|
# remove the objects dir
|
|
rm -rf "$objDir"
|
|
|
|
|
|
echo "binutils and gcc for cross compilation have been built successfully!"
|