diff --git a/configure.ac b/configure.ac index ec9e03a23b..4a8326b5e2 100644 --- a/configure.ac +++ b/configure.ac @@ -85,6 +85,14 @@ if test x"$enable_cocoa" = xyes ; then AC_DEFINE(VERSION_STRING, "3.0.0", [Version string to use for var directory]) fi +dnl Set minimum targeted version of macOS. +AC_ARG_VAR([MACOS_MIN], [minimum version number of macOS to target; default is 10.15 which is the oldest version that the source code can handle]) +if test x"$MACOS_MIN" = x ; then + AC_SUBST(MACOS_MIN_INTERNAL, 10.15) +else + AC_SUBST(MACOS_MIN_INTERNAL, $MACOS_MIN) +fi + dnl Checks for libraries. dnl Replace `main' with a function in -lncurses: if test x"$enable_cocoa" != xyes ; then diff --git a/src/Makefile.am b/src/Makefile.am index b4e5972518..e0b80af0cb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1143,11 +1143,11 @@ hengband_SOURCES += \ cocoa/AngbandAudio.mm \ cocoa/SoundAndMusic.h \ cocoa/SoundAndMusic.mm -AM_CFLAGS = -mmacosx-version-min=10.15 -Wunguarded-availability -AM_OBJCXXFLAGS = -std=c++20 -fobjc-arc -mmacosx-version-min=10.15 -Wunguarded-availability -stdlib=libc++ -AM_CXXFLAGS = -mmacosx-version-min=10.15 -Wunguarded-availability -stdlib=libc++ +AM_CFLAGS = -mmacosx-version-min=${MACOS_MIN_INTERNAL} -Wunguarded-availability +AM_OBJCXXFLAGS = -std=c++20 -fobjc-arc -mmacosx-version-min=${MACOS_MIN_INTERNAL} -Wunguarded-availability -stdlib=libc++ +AM_CXXFLAGS = -mmacosx-version-min=${MACOS_MIN_INTERNAL} -Wunguarded-availability -stdlib=libc++ hengband_LDFLAGS = -framework cocoa -framework AVFoundation $(AM_LDFLAGS) -hengband_LINK = MACOSX_DEPLOYMENT_TARGET=10.15 $(OBJCXXLINK) $(hengband_LDFLAGS) $(LDFLAGS) -o $@ +hengband_LINK = MACOSX_DEPLOYMENT_TARGET=${MACOS_MIN_INTERNAL} $(OBJCXXLINK) $(hengband_LDFLAGS) $(LDFLAGS) -o $@ APPNAME = $(PACKAGE_NAME) APPEXE = hengband APPDIR = $(APPNAME).app diff --git a/src/main-cocoa.mm b/src/main-cocoa.mm index 8eac70592d..15fc8376d8 100644 --- a/src/main-cocoa.mm +++ b/src/main-cocoa.mm @@ -1917,8 +1917,8 @@ static BOOL graphics_will_be_enabled(void) #pragma mark Prototypes static void wakeup_event_loop(void); -static void hook_plog(const char *str); -static void hook_quit(const char * str); +static void hook_plog(std::string_view str); +static void hook_quit(std::string_view str); static NSString* get_lib_directory(void); static NSString* get_doc_directory(void); static NSString* AngbandCorrectedDirectoryPath(NSString *originalPath); @@ -5182,14 +5182,15 @@ static BOOL check_events(int wait) /** * Hook to tell the user something important */ -static void hook_plog(const char * str) +static void hook_plog(std::string_view str) { - if (str) + if (str.size() > 0) { NSString *msg = NSLocalizedStringWithDefaultValue( @"Warning", AngbandMessageCatalog, [NSBundle mainBundle], @"Warning", @"Alert text for generic warning"); - NSString *info = [NSString stringWithCString:str + NSString *info = [[NSString alloc] initWithBytes:str.data() + length:str.size() #ifdef JP encoding:NSJapaneseEUCStringEncoding #else @@ -5208,7 +5209,7 @@ static void hook_plog(const char * str) /** * Hook to tell the user something, and then quit */ -static void hook_quit(const char * str) +static void hook_quit(std::string_view str) { for (int i = ANGBAND_TERM_MAX - 1; i >= 0; --i) { if (angband_terms[i]) { diff --git a/src/util/angband-files.cpp b/src/util/angband-files.cpp index 5645319e78..9e9ee2c9e6 100644 --- a/src/util/angband-files.cpp +++ b/src/util/angband-files.cpp @@ -284,6 +284,9 @@ static std::optional read_line(FILE *fp) int c = fgetc(fp); if (c == EOF) { + buf[i] = '\0'; + std::string_view sv(buf); + line_buf.append(sv.begin(), sv.end()); break; } /*