diff options
author | Gavin D. Howard <gavin@gavinhoward.com> | 2023-03-30 19:34:18 -0600 |
---|---|---|
committer | Gavin D. Howard <gavin@gavinhoward.com> | 2023-03-30 19:34:18 -0600 |
commit | 29b4b6a4f27b07c4a176258aaf831a5208d4e116 (patch) | |
tree | 20f033f0dd73ab18263777fa82f0e1f5df3369d6 | |
parent | b061283878548784ee0fa88a2fa8db7104976a6c (diff) | |
download | bc-29b4b6a4f27b07c4a176258aaf831a5208d4e116.tar.gz |
Fix the build on Mac OSX
This is an attempt to fix #67 on GitHub, where _DARWIN_C_SOURCE is
necessary when building on Mac OSX.
Signed-off-by: Gavin D. Howard <gavin@gavinhoward.com>
-rw-r--r-- | Makefile.in | 2 | ||||
-rwxr-xr-x | configure.sh | 19 | ||||
-rw-r--r-- | include/status.h | 7 |
3 files changed, 27 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in index f936fc2c..55e2e4a6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -205,7 +205,7 @@ DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3) $(DC_DEFS4) $(DC_DEFS5) CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED) CPPFLAGS2 = $(CPPFLAGS1) -I$(INCDIR)/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%% CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC) -CPPFLAGS4 = $(CPPFLAGS3) %%BSD%% +CPPFLAGS4 = $(CPPFLAGS3) %%BSD%% %%APPLE%% CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN) CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS) CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH) diff --git a/configure.sh b/configure.sh index 9cea15d9..8ffc6ab5 100755 --- a/configure.sh +++ b/configure.sh @@ -1682,6 +1682,24 @@ else CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" fi +# Test Mac OSX. This is not in an if statement because regardless of whatever +# the user says, we need to know if we are on Mac OSX. If we are, we have to set +# _DARWIN_C_SOURCE. +printf 'Testing for Mac OSX...\n' + +flags="-DBC_TEST_APPLE -DBC_ENABLE_AFL=0" +"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1 + +err="$?" + +if [ "$err" -ne 0 ]; then + printf 'On Mac OSX. Using _DARWIN_C_SOURCE.\n\n' + apple="-D_DARWIN_C_SOURCE" +else + printf 'Not on Mac OSX.\n\n' + apple="" +fi + # Test OpenBSD. This is not in an if statement because regardless of whatever # the user says, we need to know if we are on OpenBSD to activate _BSD_SOURCE. # No, I cannot `#define _BSD_SOURCE` in a header because OpenBSD's patched GCC @@ -2073,6 +2091,7 @@ contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS") contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU") contents=$(replace "$contents" "BSD" "$bsd") +contents=$(replace "$contents" "APPLE" "$apple") contents=$(replace "$contents" "BC_DEFAULT_BANNER" "$bc_default_banner") contents=$(replace "$contents" "BC_DEFAULT_SIGINT_RESET" "$bc_default_sigint_reset") diff --git a/include/status.h b/include/status.h index 198cf570..242514ed 100644 --- a/include/status.h +++ b/include/status.h @@ -60,6 +60,13 @@ #endif // __FreeBSD__ #endif // BC_TEST_FREEBSD +// This is used by configure.sh to test for Mac OSX. +#ifdef BC_TEST_APPLE +#ifdef __APPLE__ +#error On Mac OSX without _DARWIN_C_SOURCE +#endif // __APPLE__ +#endif // BC_TEST_APPLE + // Windows has deprecated isatty() and the rest of these. Or doesn't have them. // So these are just fixes for Windows. #ifdef _WIN32 |