2007-02-04 13:50:11 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2016-10-20 02:43:52 +03:00
|
|
|
# parameters <machine> <haiku sourcedir> <buildtools dir> <install 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>' \
|
2020-03-24 21:17:30 +03:00
|
|
|
'<install dir> [extra make flags]' >&2
|
2005-11-18 17:17:04 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-19 21:54:10 +03:00
|
|
|
set -e
|
|
|
|
|
2020-03-24 21:17:30 +03:00
|
|
|
if [ -z "$MAKE" ]; then
|
|
|
|
echo "MAKE undefined. Assuming make."
|
|
|
|
export MAKE=make
|
|
|
|
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=$*
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbSourceDir="$HAIKU_USE_GDB"
|
2005-11-18 17:17:04 +03:00
|
|
|
|
2014-02-09 13:06:43 +04:00
|
|
|
ccFlags="-O2"
|
2021-02-01 21:58:07 +03:00
|
|
|
#CLang needs c++14 to build ISL: https://dev.haiku-os.org/ticket/16434
|
|
|
|
cxxFlags="-O2 -std=c++14"
|
2015-04-18 16:11:32 +03:00
|
|
|
binutilsTargets="$haikuMachine"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbTarget="$haikuMachine"
|
2009-08-09 19:38:41 +04:00
|
|
|
case $haikuMachine in
|
2015-04-18 16:11:32 +03:00
|
|
|
i586-*)
|
|
|
|
binutilsConfigureArgs="--disable-multilib"
|
|
|
|
gccConfigureArgs="--disable-multilib"
|
|
|
|
binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib"
|
2015-04-18 16:11:32 +03:00
|
|
|
;;
|
2010-07-15 03:03:59 +04:00
|
|
|
x86_64-*)
|
2020-10-14 01:09:40 +03:00
|
|
|
binutilsConfigureArgs="--enable-multilib"
|
|
|
|
gccConfigureArgs="--enable-multilib"
|
2015-04-18 16:11:32 +03:00
|
|
|
binutilsTargets="$binutilsTargets,i386-efi-pe,x86_64-efi-pe"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib"
|
2010-07-15 03:03:59 +04:00
|
|
|
;;
|
2009-08-09 19:38:41 +04:00
|
|
|
m68k-*)
|
|
|
|
binutilsConfigureArgs="--enable-multilib"
|
|
|
|
gccConfigureArgs="--enable-multilib"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib"
|
2016-10-20 14:30:33 +03:00
|
|
|
gdbTarget="m68k-unknown-elf"
|
2009-08-09 19:38:41 +04:00
|
|
|
;;
|
|
|
|
arm-*)
|
2014-04-21 23:17:19 +04:00
|
|
|
# Multilib creates a lot of confusion as the wrong libs end up being linked.
|
2014-04-22 11:49:32 +04:00
|
|
|
# For now, target Cortex-A8 devices.
|
|
|
|
binutilsConfigureArgs="--disable-multilib --with-float=hard
|
2016-03-04 22:04:41 +03:00
|
|
|
--with-cpu=cortex-a8 --with-fpu=vfpv3"
|
2014-04-22 11:49:32 +04:00
|
|
|
gccConfigureArgs="--disable-multilib --with-float=hard
|
2016-03-04 22:04:41 +03:00
|
|
|
--with-cpu=cortex-a8 --with-fpu=vfpv3"
|
2014-07-21 17:28:28 +04:00
|
|
|
|
|
|
|
# TODO: Disable building with TLS support for ARM until implemented.
|
2014-07-21 19:18:51 +04:00
|
|
|
binutilsConfigureArgs="$binutilsConfigureArgs --disable-tls"
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --disable-tls"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib --disable-werror -enable-interwork"
|
|
|
|
gdbTarget="arm-unknown-elf"
|
2009-08-09 19:38:41 +04:00
|
|
|
;;
|
2019-07-01 23:25:55 +03:00
|
|
|
riscv*-*)
|
2021-01-15 17:51:17 +03:00
|
|
|
binutilsConfigureArgs=" --with-arch=rv64gc"
|
|
|
|
gccConfigureArgs=" --with-arch=rv64gc"
|
|
|
|
gdbConfigureArgs=""
|
2019-07-01 23:25:55 +03:00
|
|
|
|
2021-01-15 17:51:17 +03:00
|
|
|
binutilsConfigureArgs="$binutilsConfigureArgs --disable-multilib"
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --disable-multilib"
|
|
|
|
gdbConfigureArgs="$gdbConfigureArgs --disable-multilib"
|
2019-07-01 23:25:55 +03:00
|
|
|
;;
|
2015-04-18 16:11:32 +03:00
|
|
|
powerpc-*)
|
|
|
|
binutilsConfigureArgs="--disable-multilib"
|
|
|
|
gccConfigureArgs="--disable-multilib"
|
|
|
|
binutilsTargets="$binutilsTargets,powerpc-apple-linux,powerpc-apple-freebsd,powerpc-apple-vxworks"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib --disable-werror"
|
|
|
|
gdbTarget="powerpc-unknown-elf"
|
2018-03-01 06:46:24 +03:00
|
|
|
|
|
|
|
# TODO: Disable building with TLS support for PPC until implemented.
|
|
|
|
binutilsConfigureArgs="$binutilsConfigureArgs --disable-tls"
|
|
|
|
gccConfigureArgs="$gccConfigureArgs --disable-tls"
|
2015-04-18 16:11:32 +03:00
|
|
|
;;
|
2009-08-09 19:38:41 +04:00
|
|
|
*)
|
|
|
|
binutilsConfigureArgs="--disable-multilib"
|
|
|
|
gccConfigureArgs="--disable-multilib"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbConfigureArgs="--disable-multilib"
|
2009-08-09 19:38:41 +04:00
|
|
|
;;
|
|
|
|
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
|
|
|
|
|
2016-10-20 03:35:23 +03:00
|
|
|
if [ -n "$gdbSourceDir" -a ! -d "$gdbSourceDir" ]; then
|
|
|
|
echo "No such directory: \"$gdbSourceDir\"" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-11-18 17:17:04 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2016-10-20 03:35:23 +03:00
|
|
|
if [ -n "$gdbSourceDir" ]; then
|
|
|
|
cd "$gdbSourceDir"
|
|
|
|
gdbSourceDir=$(pwd)
|
|
|
|
cd "$currentDir"
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2019-02-21 22:01:40 +03:00
|
|
|
# clear out the "missing" scripts so that they don't cause errors on tools
|
|
|
|
# that are not installed, as we will have committed any files generated by
|
|
|
|
# them to the buildtools repo already.
|
|
|
|
echo "#!/bin/sh" >"$binutilsSourceDir"/missing
|
|
|
|
echo "#!/bin/sh" >"$gccSourceDir"/missing
|
|
|
|
echo "#!/bin/sh" >"$gccSourceDir"/isl/missing
|
2018-11-10 22:41:55 +03:00
|
|
|
|
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"
|
2016-10-20 03:35:23 +03:00
|
|
|
gdbObjDir="$objDir/gdb"
|
2013-11-26 00:07:20 +04:00
|
|
|
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
|
|
|
|
2016-10-20 03:35:23 +03:00
|
|
|
mkdir -p "$installDir" "$objDir" "$binutilsObjDir" "$gccObjDir" "$gdbObjDir" \
|
|
|
|
"$stdcxxObjDir" "$tmpIncludeDir" "$tmpLibDir" || exit 1
|
2013-11-26 00:07:20 +04:00
|
|
|
mkdir -p "$installDir/lib/gcc/$haikuMachine/$gccVersion"
|
2005-12-07 01:45:11 +03:00
|
|
|
|
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
|
|
|
|
2016-10-20 03:35:23 +03:00
|
|
|
# build gdb
|
|
|
|
if [ -n "$HAIKU_USE_GDB" ]; then
|
|
|
|
cd "$gdbObjDir"
|
|
|
|
"$gdbSourceDir/configure" \
|
|
|
|
--prefix="$installDir" --target=$gdbTarget \
|
|
|
|
$gdbConfigureArgs \
|
|
|
|
|| exit 1
|
|
|
|
$MAKE $additionalMakeArgs || exit 1
|
|
|
|
$MAKE $additionalMakeArgs install || exit 1
|
|
|
|
fi
|
|
|
|
|
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 \
|
2015-04-18 16:11:32 +03:00
|
|
|
--enable-targets=$binutilsTargets \
|
2013-06-14 18:04:26 +04:00
|
|
|
--disable-nls --disable-shared --disable-werror \
|
2019-01-27 03:52:55 +03:00
|
|
|
--with-sysroot="$sysrootDir" \
|
2018-08-27 05:24:45 +03:00
|
|
|
--disable-maintainer-mode \
|
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
|
|
|
|
2019-02-21 22:02:13 +03:00
|
|
|
export PATH="$PATH:$installDir/bin"
|
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 \
|
2017-09-06 00:41:39 +03:00
|
|
|
--enable-__cxa-atexit --enable-threads=posix \
|
|
|
|
--with-default-libstdcxx-abi=gcc4-compatible \
|
|
|
|
--with-sysroot="$sysrootDir" \
|
2018-08-27 05:24:45 +03:00
|
|
|
--disable-maintainer-mode \
|
2021-05-02 15:37:20 +03:00
|
|
|
--disable-libgomp \
|
|
|
|
--disable-libatomic \
|
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
|
|
|
|
}
|
|
|
|
|
2014-08-01 16:53:45 +04:00
|
|
|
case $haikuMachine in
|
|
|
|
x86_64-*)
|
|
|
|
# pick up the 32-bit libraries for the bootloader
|
|
|
|
bootLibgcc=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libgcc.a`
|
|
|
|
$installDir/bin/$haikuMachine-strip --strip-debug $bootLibgcc
|
|
|
|
bootLibsupcxx=`$installDir/bin/$haikuMachine-gcc -m32 -print-file-name=libsupc++.a`
|
|
|
|
$installDir/bin/$haikuMachine-strip --strip-debug $bootLibsupcxx
|
|
|
|
;;
|
|
|
|
esac
|
2012-08-16 16:47:49 +04:00
|
|
|
|
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
|
|
|
|
2019-06-17 03:30:53 +03:00
|
|
|
# rename the static libstdc++ to prevent accidental usage
|
|
|
|
# (it should be used by the bootstrap process only)
|
|
|
|
mv "$installDir/$haikuMachine/lib/libstdc++.a" \
|
|
|
|
"$installDir/$haikuMachine/lib/libstdc++-static.a"
|
2019-06-15 22:42:13 +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!"
|