Description |
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.
Note: This patch is against git b0c9e7892796b91383c174755e9888fc75e8857d. Tested against i686-w64-mingw32 (cross-build) and x86_64-linux-gnu.
|
Attached Files |
0001-AppHdr.h-Adjust-PRINTF-macro-for-use-with-mingw-w64.patch [^] (2,732 bytes) 2014-06-08 10:08 [Show Content] [Hide Content]From 638c049ef10a6c884b3a33b58e460c9074f556a9 Mon Sep 17 00:00:00 2001
From: John Olender <john.olender@gmail.com>
Date: Sun, 8 Jun 2014 03:43:50 -0400
Subject: [PATCH] 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.
---
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 ae7ff97..7497d80 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 286110a..379f7a6 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__MINGW_PRINTF_FORMAT
EXTRA_LIBS += -lwinmm
ifdef TILES
EXTRA_LIBS += -lmingw32 -lgdi32 -lwinmm contrib/install/$(ARCH)/lib/libSDLmain.a -mwindows
--
2.0.0.rc2
0002-Makefile-Pass-the-correct-mingw-C99-stdio-define.patch [^] (875 bytes) 2014-06-08 22:35 [Show Content] [Hide Content]From ed580ca6f12c407467f25989cbaf0d685e4f3d07 Mon Sep 17 00:00:00 2001
From: John Olender <john.olender@gmail.com>
Date: Sun, 8 Jun 2014 16:32:40 -0400
Subject: [PATCH 2/2] Makefile: Pass the correct mingw C99 stdio define.
---
crawl-ref/source/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crawl-ref/source/Makefile b/crawl-ref/source/Makefile
index 379f7a6..e92d1b9 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 -D__MINGW_PRINTF_FORMAT
+ 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
--
2.0.0.rc2
0001-AppHdr.h-Remove-PRINTF-define-duplication-in-mingw-c.patch [^] (2,338 bytes) 2014-06-09 01:15 [Show Content] [Hide Content]From 7847b906f8e350714b8f6b45b9fa1317663678e8 Mon Sep 17 00:00:00 2001
From: John Olender <john.olender@gmail.com>
Date: Sun, 8 Jun 2014 18:27:31 -0400
Subject: [PATCH] AppHdr.h: Remove PRINTF #define duplication in mingw check.
Fix indentation, remove PRINTF #define duplication, and correct
a comment about which macro must be defined for enabling
mingw-w64's C99 printf.
---
crawl-ref/source/AppHdr.h | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h
index 7497d80..56d139c 100644
--- a/crawl-ref/source/AppHdr.h
+++ b/crawl-ref/source/AppHdr.h
@@ -418,28 +418,29 @@ 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
+# ifdef TARGET_COMPILER_MINGW
+// Configure mingw32 / mingw-w64 printf format
+//
+// If __USE_MINGW_ANSI_STDIO 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
+# ifdef __cplusplus
+# include <cstdio>
+# else
+# include <stdio.h>
+# endif
+// If mingw defined a special format function to use, use this over 'printf'.
+# ifdef __MINGW_PRINTF_FORMAT
+# define CRAWL_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+# else
+# define CRAWL_PRINTF_FORMAT printf
+# endif
+# else
// standard GNU-compatible compiler (i.e., not mingw32/mingw-w64)
+# define CRAWL_PRINTF_FORMAT printf
+# endif
# define PRINTF(x, dfmt) const char *format dfmt, ...) \
- __attribute__((format (printf, x+1, x+2))
-#endif
+ __attribute__((format (CRAWL_PRINTF_FORMAT, x+1, x+2))
#else
# define PRINTF(x, dfmt) const char *format dfmt, ...
#endif
--
2.0.0.rc2
|