Skip to content

Commit 9bbed80

Browse files
Mac OS Clang 17+ compile fix
1 parent 13932bb commit 9bbed80

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

scripts/001-binutils.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,26 @@ TARGET_ALIAS="ee"
3636
TARG_XTRA_OPTS=""
3737
OSVER=$(uname)
3838

39-
## If using MacOS Apple, set gmp and mpfr paths using TARG_XTRA_OPTS
39+
## If using MacOS Apple, set gmp and mpfr paths using TARG_XTRA_OPTS
4040
## (this is needed for Apple Silicon but we will do it for all MacOS systems)
4141
if [ "$(uname -s)" = "Darwin" ]; then
42+
## Determine if we should add --with-system-zlib (for Clang ≥ 17)
43+
if clang --version 2>&1 | head -n1 | grep -qE 'clang.*version ([1-9][7-9]|[2-9][0-9])'; then
44+
macos_zlib_flag="--with-system-zlib"
45+
else
46+
macos_zlib_flag=""
47+
fi
48+
4249
## Check if using brew
4350
if command -v brew &> /dev/null; then
44-
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) --with-mpfr=$(brew --prefix mpfr)"
51+
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) \
52+
--with-mpfr=$(brew --prefix mpfr) \
53+
$macos_zlib_flag"
4554
elif command -v port &> /dev/null; then
46-
## Check if using MacPorts
47-
TARG_XTRA_OPTS="--with-gmp=$(port -q prefix gmp) --with-mpfr=$(port -q prefix mpfr)"
55+
## Check if using MacPorts
56+
TARG_XTRA_OPTS="--with-gmp=$(port -q prefix gmp) \
57+
--with-mpfr=$(port -q prefix mpfr) \
58+
$macos_zlib_flag"
4859
fi
4960
fi
5061

scripts/002-gcc-stage1.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ TARG_XTRA_OPTS=""
3737
TARGET_CFLAGS="-O2 -gdwarf-2 -gz"
3838
OSVER=$(uname)
3939

40-
## If using MacOS Apple, set gmp, mpfr and mpc paths using TARG_XTRA_OPTS
40+
## If using MacOS Apple, set gmp, mpfr and mpc paths using TARG_XTRA_OPTS
4141
## (this is needed for Apple Silicon but we will do it for all MacOS systems)
4242
if [ "$(uname -s)" = "Darwin" ]; then
43+
## Determine if we should add --with-system-zlib (for Clang ≥ 17)
44+
if clang --version 2>&1 | head -n1 | grep -qE 'clang.*version ([1-9][7-9]|[2-9][0-9])'; then
45+
macos_zlib_flag="--with-system-zlib"
46+
else
47+
macos_zlib_flag=""
48+
fi
49+
4350
## Check if using brew
4451
if command -v brew &> /dev/null; then
45-
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) --with-mpfr=$(brew --prefix mpfr) --with-mpc=$(brew --prefix libmpc)"
52+
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) \
53+
--with-mpfr=$(brew --prefix mpfr) \
54+
--with-mpc=$(brew --prefix libmpc) \
55+
$macos_zlib_flag"
4656
elif command -v port &> /dev/null; then
4757
## Check if using MacPorts
4858
MACPORT_BASE=$(dirname `port -q contents gmp|grep gmp.h`|sed s#/include##g)
4959
echo Macport base is $MACPORT_BASE
50-
TARG_XTRA_OPTS="--with-gmp=$MACPORT_BASE --with-mpfr=$MACPORT_BASE --with-mpc=$MACPORT_BASE"
60+
TARG_XTRA_OPTS="--with-gmp=$MACPORT_BASE \
61+
--with-mpfr=$MACPORT_BASE \
62+
--with-mpc=$MACPORT_BASE \
63+
$macos_zlib_flag"
5164
fi
5265
fi
5366

scripts/006-gcc-stage2.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ TARG_XTRA_OPTS=""
3737
TARGET_CFLAGS="-O2 -gdwarf-2 -gz"
3838
OSVER=$(uname)
3939

40-
## If using MacOS Apple, set gmp, mpfr and mpc paths using TARG_XTRA_OPTS
40+
## If using MacOS Apple, set gmp, mpfr and mpc paths using TARG_XTRA_OPTS
4141
## (this is needed for Apple Silicon but we will do it for all MacOS systems)
4242
if [ "$(uname -s)" = "Darwin" ]; then
43+
## Determine if we should add --with-system-zlib (for Clang ≥ 17)
44+
if clang --version 2>&1 | head -n1 | grep -qE 'clang.*version ([1-9][7-9]|[2-9][0-9])'; then
45+
macos_zlib_flag="--with-system-zlib"
46+
else
47+
macos_zlib_flag=""
48+
fi
49+
4350
## Check if using brew
4451
if command -v brew &> /dev/null; then
45-
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) --with-mpfr=$(brew --prefix mpfr) --with-mpc=$(brew --prefix libmpc)"
52+
TARG_XTRA_OPTS="--with-gmp=$(brew --prefix gmp) \
53+
--with-mpfr=$(brew --prefix mpfr) \
54+
--with-mpc=$(brew --prefix libmpc) \
55+
$macos_zlib_flag"
4656
elif command -v port &> /dev/null; then
4757
## Check if using MacPorts
4858
MACPORT_BASE=$(dirname `port -q contents gmp|grep gmp.h`|sed s#/include##g)
49-
echo Macport base is $MACPORT_BASE
50-
TARG_XTRA_OPTS="--with-gmp=$MACPORT_BASE --with-mpfr=$MACPORT_BASE --with-mpc=$MACPORT_BASE"
59+
echo "MacPort base is $MACPORT_BASE"
60+
TARG_XTRA_OPTS="--with-gmp=$MACPORT_BASE \
61+
--with-mpfr=$MACPORT_BASE \
62+
--with-mpc=$MACPORT_BASE \
63+
$macos_zlib_flag"
5164
fi
5265
fi
5366

0 commit comments

Comments
 (0)