aboutsummaryrefslogtreecommitdiffstats
path: root/main/abuild/0001-functions.sh-exclusively-use-apk-print-arch-to-detec.patch
blob: ca2678fe8207097b346ef06426401c5e767cb601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From c9d3df08b3d2824e4f2b3b1e901fee08447f5b61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Fri, 7 Feb 2020 23:06:16 +0200
Subject: [PATCH] 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)"
-- 
2.27.0