1From 45ef4455a60929932d1499cf718c1c9f59af9f26 Mon Sep 17 00:00:00 2001 2From: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 3Date: Tue, 26 May 2020 22:57:05 +0200 4Subject: [PATCH] build: Always use EXTERN_UNLESS_MAIN_MODULE pattern 5 6This patch is loosely based on upstream commit 76aff8a132815a84bab69401c1e7de96ec549fbf2 ("build: Always use 8EXTERN_UNLESS_MAIN_MODULE pattern."). However, this upstream commit 9applies to gnupg2, and the code base has changed quite significantly 10compared to gnupg 1.x, so upstream's patch cannot be applied 11as-is. The goal of the patch is to make sure each variable is only 12defined once, ass gcc 10 now default to -fno-common. 13 14Essentially, this patch mainly fixes the EXTERN_UNLESS_MAIN_MODULE 15define so that it really expands to "extern" when 16INCLUDED_BY_MAIN_MODULE is not defined, even on non-RiscOS 17systems. Contrary to upstream's patch we however do not factorize the 18multiple EXTERN_UNLESS_MAIN_MODULE definitions into a single place as 19it requires too many changes: instead we simply fix the few 20definitions of this macro. 21 22Once the macro is fixed, two places need to define 23INCLUDED_BY_MAIN_MODULE: tools/bftest.c and tools/mpicalc.c so that 24when they include the common headers, their variables are at least 25defined once. 26 27The iobuf.{c,h} case is handled differently: iobuf.h gains an 28unconditional "extern", with the variable being added to iobuf.c. This 29is identical to what upstream's 306aff8a132815a84bab69401c1e7de96ec549fbf2 is doing. 31 32Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 33--- 34 g10/options.h | 3 +-- 35 include/cipher.h | 2 +- 36 include/iobuf.h | 9 +-------- 37 include/memory.h | 2 +- 38 include/mpi.h | 2 +- 39 tools/bftest.c | 1 + 40 tools/mpicalc.c | 1 + 41 util/iobuf.c | 2 ++ 42 8 files changed, 9 insertions(+), 13 deletions(-) 43 44diff --git a/g10/options.h b/g10/options.h 45index 0ac6e7755..bae19e9e3 100644 46--- a/g10/options.h 47+++ b/g10/options.h 48@@ -26,8 +26,7 @@ 49 #include "packet.h" 50 51 #ifndef EXTERN_UNLESS_MAIN_MODULE 52-/* Norcraft can't cope with common symbols */ 53-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) 54+#if !defined (INCLUDED_BY_MAIN_MODULE) 55 #define EXTERN_UNLESS_MAIN_MODULE extern 56 #else 57 #define EXTERN_UNLESS_MAIN_MODULE 58diff --git a/include/cipher.h b/include/cipher.h 59index dd4af18cb..6ef6e6829 100644 60--- a/include/cipher.h 61+++ b/include/cipher.h 62@@ -115,7 +115,7 @@ struct gcry_md_context { 63 typedef struct gcry_md_context *MD_HANDLE; 64 65 #ifndef EXTERN_UNLESS_MAIN_MODULE 66-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) 67+#if !defined (INCLUDED_BY_MAIN_MODULE) 68 #define EXTERN_UNLESS_MAIN_MODULE extern 69 #else 70 #define EXTERN_UNLESS_MAIN_MODULE 71diff --git a/include/iobuf.h b/include/iobuf.h 72index 030f8c8e9..b4d26b7e1 100644 73--- a/include/iobuf.h 74+++ b/include/iobuf.h 75@@ -69,14 +69,7 @@ struct iobuf_struct { 76 } unget; 77 }; 78 79-#ifndef EXTERN_UNLESS_MAIN_MODULE 80-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) 81-#define EXTERN_UNLESS_MAIN_MODULE extern 82-#else 83-#define EXTERN_UNLESS_MAIN_MODULE 84-#endif 85-#endif 86-EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode; 87+extern int iobuf_debug_mode; 88 89 void iobuf_enable_special_filenames ( int yes ); 90 int iobuf_is_pipe_filename (const char *fname); 91diff --git a/include/memory.h b/include/memory.h 92index d414a9b2e..6698337e3 100644 93--- a/include/memory.h 94+++ b/include/memory.h 95@@ -91,7 +91,7 @@ unsigned secmem_get_flags(void); 96 #define DBG_MEMSTAT memory_stat_debug_mode 97 98 #ifndef EXTERN_UNLESS_MAIN_MODULE 99-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) 100+#if !defined (INCLUDED_BY_MAIN_MODULE) 101 #define EXTERN_UNLESS_MAIN_MODULE extern 102 #else 103 #define EXTERN_UNLESS_MAIN_MODULE 104diff --git a/include/mpi.h b/include/mpi.h 105index a4c16f5af..7a45ff805 100644 106--- a/include/mpi.h 107+++ b/include/mpi.h 108@@ -36,7 +36,7 @@ 109 #include "memory.h" 110 111 #ifndef EXTERN_UNLESS_MAIN_MODULE 112-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) 113+#if !defined (INCLUDED_BY_MAIN_MODULE) 114 #define EXTERN_UNLESS_MAIN_MODULE extern 115 #else 116 #define EXTERN_UNLESS_MAIN_MODULE 117diff --git a/tools/bftest.c b/tools/bftest.c 118index 8a1572c2b..5afd7e125 100644 119--- a/tools/bftest.c 120+++ b/tools/bftest.c 121@@ -26,6 +26,7 @@ 122 #include <fcntl.h> 123 #endif 124 125+#define INCLUDED_BY_MAIN_MODULE 126 #include "util.h" 127 #include "cipher.h" 128 #include "i18n.h" 129diff --git a/tools/mpicalc.c b/tools/mpicalc.c 130index 46e5fc824..31acd82a4 100644 131--- a/tools/mpicalc.c 132+++ b/tools/mpicalc.c 133@@ -31,6 +31,7 @@ 134 #include <stdlib.h> 135 #include <ctype.h> 136 137+#define INCLUDED_BY_MAIN_MODULE 138 #include "util.h" 139 #include "mpi.h" 140 #include "i18n.h" 141diff --git a/util/iobuf.c b/util/iobuf.c 142index c8442929a..0d9ee4cec 100644 143--- a/util/iobuf.c 144+++ b/util/iobuf.c 145@@ -113,6 +113,8 @@ typedef struct { 146 static CLOSE_CACHE close_cache; 147 #endif 148 149+int iobuf_debug_mode; 150+ 151 #ifdef _WIN32 152 typedef struct { 153 int sock; 154-- 1552.26.2 156 157