From 0ead68b7047675f5c61bed6fcbbcbf06f70c1e4a Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 21 Dec 2021 06:10:18 +0000 Subject: [PATCH] bin/package: fix 64-bit detection on systems without 'cc' If the compiler is called gcc but not cc, the 64-bit detection didn't work and $HOSTTYPE (and the arch/ subdirectory) did not get the -64 suffix. bin/package, src/cmd/INIT/package.sh: - Run checkcc() before attempting to compile the program. This will set $cc to the path to gcc if there is no 'cc' command. - trap: use 'rm -rf' to also delete .dSYM directories (macOS). - checkcc(): Since we're here, find clang as well. --- bin/package | 13 ++++++++----- src/cmd/INIT/package.sh | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/package b/bin/package index 06a00bcba..405975154 100755 --- a/bin/package +++ b/bin/package @@ -1724,12 +1724,12 @@ int b() { return 0; } esac ;; *) case $bits in - '') bits=$( cd "$TMPDIR" - LC_ALL=C - export LC_ALL + '') bits=$( set -e + cd "$TMPDIR" tmp=hi$$ - trap 'rm -f $tmp.*' 0 1 2 + trap 'rm -rf "$tmp".*' 0 1 2 echo 'int main() { return 0; }' > $tmp.a.c + checkcc $cc $CCFLAGS -o $tmp.a.exe $tmp.a.c /dev/null 2>&1 file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" ) case $bits in @@ -1805,7 +1805,10 @@ checkcc() if onpath $CC then cc=$_onpath_ else case $CC in - cc) if onpath gcc + cc) if onpath clang + then CC=clang + cc=$_onpath_ + elif onpath gcc then CC=gcc cc=$_onpath_ fi diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 06a00bcba..405975154 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -1724,12 +1724,12 @@ int b() { return 0; } esac ;; *) case $bits in - '') bits=$( cd "$TMPDIR" - LC_ALL=C - export LC_ALL + '') bits=$( set -e + cd "$TMPDIR" tmp=hi$$ - trap 'rm -f $tmp.*' 0 1 2 + trap 'rm -rf "$tmp".*' 0 1 2 echo 'int main() { return 0; }' > $tmp.a.c + checkcc $cc $CCFLAGS -o $tmp.a.exe $tmp.a.c /dev/null 2>&1 file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" ) case $bits in @@ -1805,7 +1805,10 @@ checkcc() if onpath $CC then cc=$_onpath_ else case $CC in - cc) if onpath gcc + cc) if onpath clang + then CC=clang + cc=$_onpath_ + elif onpath gcc then CC=gcc cc=$_onpath_ fi