From 2fbeb0608aac4c7113f6fbf04032ef51b11c3442 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 27 Dec 2020 02:07:04 +0100 Subject: [PATCH] Detect and report errors when cross-building gcc --- doc/cross-gcc.sh | 61 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/doc/cross-gcc.sh b/doc/cross-gcc.sh index 6ecf79d..e932d8b 100644 --- a/doc/cross-gcc.sh +++ b/doc/cross-gcc.sh @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh #$Id$ #Copyright (c) 2019 Pierre Pronchery #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