From c9d3df08b3d2824e4f2b3b1e901fee08447f5b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 7 Feb 2020 23:06:16 +0200 Subject: functions.sh: exclusively use apk --print-arch to detect build arch Originally "gcc -dumpmachine" was used to detect build gcc triplet. However, abuild does not depend on gcc or build-base (but installs it if needed to build) so gcc might not be there. Additionally abuild-sign can be used standalone, and does not have gcc dependency. Using ${CC:-gcc} is problematic in cross-compile, as CC might be already set for the cross-compiler and would result giving the target host triplet. It was deemed simplest to use "apk --print-arch" exclusively to detect the builder host type, or specify CBUILD manually. If there is need to use abuild/abuild-sign on non-Alpine hosts withou apk, we can later add fallback that uses "uname -m" to detect the architecture and guess Alpine CBUILD from it. Fixes #9974 Fixes: 5adf47c1 "functions.sh: use apk --print-arch for CARCH if gcc is missing" Fixes: 95cd15c0 "functions.sh: dont die if gcc is missing" --- functions.sh.in | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/functions.sh.in b/functions.sh.in index 82ac114..5fef9b0 100644 --- a/functions.sh.in +++ b/functions.sh.in @@ -117,21 +117,18 @@ readconfig() { USE_COLORS=${_USE_COLORS-$USE_COLORS} USE_CCACHE=${_USE_CCACHE-$USE_CCACHE} - [ -z "$CBUILD" ] && CBUILD="$(${CC:-gcc} -dumpmachine 2>/dev/null || true)" + [ -z "$CBUILD" ] && CBUILD="$(${APK:-apk} --print-arch 2>/dev/null)" [ -z "$CHOST" ] && CHOST="$CBUILD" [ -z "$CTARGET" ] && CTARGET="$CHOST" [ "$(arch_to_hostspec $CBUILD)" != "unknown" ] && CBUILD="$(arch_to_hostspec $CBUILD)" [ "$(arch_to_hostspec $CHOST)" != "unknown" ] && CHOST="$(arch_to_hostspec $CHOST)" [ "$(arch_to_hostspec $CTARGET)" != "unknown" ] && CTARGET="$(arch_to_hostspec $CTARGET)" - - [ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)" - - # use apk --print-arch for CARCH if gcc is missing - if [ "$CARCH" = "unknown" ]; then - local apk_arch="$(${APK:-apk} --print-arch 2>/dev/null)" - CARCH=${apk_arch:-unknown} + if [ -z "$CBUILD" ]; then + echo "Unable to deduce build architecture. Install apk-tools, or set CBUILD." + exit 1 fi + [ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)" [ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)" [ -z "$CBUILD_ARCH" ] && CBUILD_ARCH="$(hostspec_to_arch $CBUILD)" [ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)" -- cgit v1.2.3