From 87d8b17cc478658f2d14f8c55d65b9fb7c0ea167 Mon Sep 17 00:00:00 2001 From: John Olender Date: Sun, 8 Jun 2014 03:43:50 -0400 Subject: AppHdr.h: Adjust PRINTF macro for use with mingw-w64 When __attribute__((format(printf...)) is used, as is the case with AppHdr.h's PRINTF macro, mingw-w64 uses the standard windows printf implementation by default. The stdio library provided by windows is typically *not* C99-compliant. Since crawl uses C99-style PRINTF calls, many warnings are printed during compilation. This patch guarantees that, if available, a C99-style printf will be used for both format checking and actual compiled calls under mingw-w64. If the C99-specific printf macro is not set by including stdio.h (e.g., mingw32 is being used), the standard printf call for format is used. [Committer's note: also included the fix-up patch "Makefile: Pass the correct mingw C99 stdio define."] --- crawl-ref/source/AppHdr.h | 20 ++++++++++++++++++++ crawl-ref/source/Makefile | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h index ae7ff97eb2..7497d8022b 100644 --- a/crawl-ref/source/AppHdr.h +++ b/crawl-ref/source/AppHdr.h @@ -418,8 +418,28 @@ static inline void UNUSED(const volatile T &) #ifdef __GNUC__ // show warnings about the format string +#ifdef TARGET_COMPILER_MINGW +// mingw32 / mingw-w64 compiler +// If __MINGW_PRINTF_FORMAT is defined, mingw-w64 will try to use a C99 printf +// However, stdio.h must be included to have a C99 printf for use with +// __attribute__((format(...)). +#ifdef __cplusplus +#include +#else +#include +#endif +// Fall back to standard printf if necessary +#ifndef __MINGW_PRINTF_FORMAT +#define __MINGW_PRINTF_FORMAT printf +#endif +// Use the mingw32/mingw-w64 C99-specific printf function to check format +# define PRINTF(x, dfmt) const char *format dfmt, ...) \ + __attribute__((format (__MINGW_PRINTF_FORMAT, x+1, x+2)) +#else +// standard GNU-compatible compiler (i.e., not mingw32/mingw-w64) # define PRINTF(x, dfmt) const char *format dfmt, ...) \ __attribute__((format (printf, x+1, x+2)) +#endif #else # define PRINTF(x, dfmt) const char *format dfmt, ... #endif diff --git a/crawl-ref/source/Makefile b/crawl-ref/source/Makefile index 286110a5b4..e92d1b9b81 100644 --- a/crawl-ref/source/Makefile +++ b/crawl-ref/source/Makefile @@ -192,7 +192,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NEED_LIBW32C = YesPlease BUILD_PCRE = YesPlease BUILD_ZLIB = YesPlease - DEFINES_L += -DWINMM_PLAY_SOUNDS + DEFINES_L += -DWINMM_PLAY_SOUNDS -D__USE_MINGW_ANSI_STDIO EXTRA_LIBS += -lwinmm ifdef TILES EXTRA_LIBS += -lmingw32 -lgdi32 -lwinmm contrib/install/$(ARCH)/lib/libSDLmain.a -mwindows -- cgit v1.2.3-54-g00ecf