From cc9102248cbd5fe9d80f6eb0e6177554ee52ba21 Mon Sep 17 00:00:00 2001
From: Willi Mutschler <willi@mutschler.eu>
Date: Wed, 27 Sep 2023 12:13:26 +0200
Subject: [PATCH] macOS installer: improve sed command to get GCC version

---
 macOS/build.sh      | 2 +-
 macOS/deps/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/macOS/build.sh b/macOS/build.sh
index 3c19bb9238..10fcf8964e 100755
--- a/macOS/build.sh
+++ b/macOS/build.sh
@@ -55,7 +55,7 @@ LIB64="$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64
 ## - the macOS linker is different from GNU ld and does not have the equivalent of -Bstatic/-Bdynamic
 ## - libgfortran.spec does not include --as-needed on macOS, hence it will link the library anyways
 ## Also, it does not seem possible to override libgfortran.spec with the --specs option.
-GCC_VERSION=$(sed -n "s|c = '$(BREWDIR)/bin/gcc-\([0-9]*\)'|\1|p" "$ROOTDIR"/scripts/homebrew-native-$PKG_ARCH.ini)
+GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/scripts/homebrew-native-"$PKG_ARCH".ini)
 
 QUADMATH_DIR=$(mktemp -d)
 ln -s $BREWDIR/opt/gcc/lib/gcc/$GCC_VERSION/libquadmath.a $QUADMATH_DIR
diff --git a/macOS/deps/Makefile b/macOS/deps/Makefile
index 6786c009d9..316b2776dc 100644
--- a/macOS/deps/Makefile
+++ b/macOS/deps/Makefile
@@ -22,7 +22,7 @@ DEPS_ARCH ?= x86_64 # use x86_64 by default
 
 BREWDIR := $(if $(filter arm64,$(DEPS_ARCH)),/opt/homebrew,/usr/local)
 
-GCC_VERSION = $(shell sed -n "s|c = '$(BREWDIR)/bin/gcc-\([0-9]*\)'|\1|p" ../../scripts/homebrew-native-$(DEPS_ARCH).ini)
+GCC_VERSION = $(shell sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" ../../scripts/homebrew-native-$(DEPS_ARCH).ini)
 
 ROOT_PATH = $(realpath .)
 
-- 
GitLab