Detect and report errors when cross-building gcc

This commit is contained in:
Pierre Pronchery 2020-12-27 02:07:04 +01:00
parent ec6724b544
commit 2fbeb0608a

View File

@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh
#$Id$
#Copyright (c) 2019 Pierre Pronchery <khorben@defora.org>
#This file is part of DeforaOS uKernel
@ -34,6 +34,7 @@ GCC_TARGETS="all-gcc all-target-libgcc install-gcc install-target-libgcc"
GCC_VERSION="8.3.0"
GZEXT="gz"
MIRROR="https://ftpmirror.gnu.org"
PROGNAME="cross-gcc.sh"
TARGET="i686-elf"
#executables
MAKE="make"
@ -43,6 +44,14 @@ WGET="wget"
#functions
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#main
#Modify the environment to reflect the port chosen
@ -50,32 +59,57 @@ PREFIX="$HOME/opt/cross-gcc-$TARGET"
PATH="$PREFIX/bin:$PATH"
#Download binutils
[ -f "binutils-$BINUTILS_VERSION.tar.$GZEXT" ] ||
if [ ! -f "binutils-$BINUTILS_VERSION.tar.$GZEXT" ]; then
$WGET "$MIRROR/binutils/binutils-$BINUTILS_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not download binutils"
exit $?
fi
fi
#Extract, configure, and build binutils in a dedicated tree
[ -d "binutils-$BINUTILS_VERSION" ] ||
if [ ! -d "binutils-$BINUTILS_VERSION" ]; then
$TAR xzvf "binutils-$BINUTILS_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not extract binutils"
exit $?
fi
fi
case "$TARGET" in
aarch64-elf|amd64-elf|sparc64-elf)
BINUTILS_FLAGS="$BINUTILS_FLAGS --enable-multilib"
;;
esac
$MKDIR "binutils-$TARGET"
(cd "binutils-$TARGET" && "../binutils-$BINUTILS_VERSION/configure" \
($MKDIR "binutils-$TARGET" &&
cd "binutils-$TARGET" &&
"../binutils-$BINUTILS_VERSION/configure" \
--target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls \
--disable-werror $BINUTILS_FLAGS)
if [ $? -ne 0 ]; then
_error "Could not configure binutils"
exit $?
fi
for target in $BINUTILS_TARGETS; do
(cd "binutils-$TARGET" && $MAKE "$target")
done
#Download GCC
[ -f "gcc-$GCC_VERSION.tar.$GZEXT" ] ||
if [ ! -f "gcc-$GCC_VERSION.tar.$GZEXT" ]; then
$WGET "$MIRROR/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not download gcc"
exit $?
fi
fi
#Extract, configure, and build GCC in a dedicated tree
[ -d "gcc-$GCC_VERSION" ] ||
if [ ! -d "gcc-$GCC_VERSION" ]; then
$TAR xzvf "gcc-$GCC_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not extract gcc"
exit $?
fi
fi
case "$TARGET" in
aarch64-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=lp64,ilp32"
@ -84,10 +118,19 @@ case "$TARGET" in
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=m64,m32"
;;
esac
$MKDIR "gcc-$TARGET"
(cd "gcc-$TARGET" && "../gcc-$GCC_VERSION/configure" --target="$TARGET" \
($MKDIR "gcc-$TARGET" &&
cd "gcc-$TARGET" &&
"../gcc-$GCC_VERSION/configure" --target="$TARGET" \
--prefix="$PREFIX" --disable-nls --enable-languages=c,c++ \
--without-headers $GCC_FLAGS)
if [ $? -ne 0 ]; then
_error "Could not configure gcc"
exit $?
fi
for target in $GCC_TARGETS; do
(cd "gcc-$TARGET" && $MAKE "$target")
if [ $? -ne 0 ]; then
_error "$target: Could not build gcc target"
exit $?
fi
done