summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olender <john.olender@gmail.com>2014-06-08 03:43:50 -0400
committerNeil Moore <neil@s-z.org>2014-06-08 17:11:50 -0400
commit87d8b17cc478658f2d14f8c55d65b9fb7c0ea167 (patch)
tree1b1cf74f9c7c2c91033fe5c6afcb0002ac3f44ce
parent93c65a706663ace1d21d71fa2d87abffd7122dac (diff)
downloadcrawl-ref-87d8b17cc478658f2d14f8c55d65b9fb7c0ea167.tar.gz
crawl-ref-87d8b17cc478658f2d14f8c55d65b9fb7c0ea167.zip
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."]
-rw-r--r--crawl-ref/source/AppHdr.h20
-rw-r--r--crawl-ref/source/Makefile2
2 files changed, 21 insertions, 1 deletions
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 <cstdio>
+#else
+#include <stdio.h>
+#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