aboutsummaryrefslogtreecommitdiff
blob: 9f0ba1b01e9285fabb9eef1fe9a9c8809adf2b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
From 45ef4455a60929932d1499cf718c1c9f59af9f26 Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Date: Tue, 26 May 2020 22:57:05 +0200
Subject: [PATCH] build: Always use EXTERN_UNLESS_MAIN_MODULE pattern

This patch is loosely based on upstream commit
6aff8a132815a84bab69401c1e7de96ec549fbf2 ("build: Always use
EXTERN_UNLESS_MAIN_MODULE pattern."). However, this upstream commit
applies to gnupg2, and the code base has changed quite significantly
compared to gnupg 1.x, so upstream's patch cannot be applied
as-is. The goal of the patch is to make sure each variable is only
defined once, ass gcc 10 now default to -fno-common.

Essentially, this patch mainly fixes the EXTERN_UNLESS_MAIN_MODULE
define so that it really expands to "extern" when
INCLUDED_BY_MAIN_MODULE is not defined, even on non-RiscOS
systems. Contrary to upstream's patch we however do not factorize the
multiple EXTERN_UNLESS_MAIN_MODULE definitions into a single place as
it requires too many changes: instead we simply fix the few
definitions of this macro.

Once the macro is fixed, two places need to define
INCLUDED_BY_MAIN_MODULE: tools/bftest.c and tools/mpicalc.c so that
when they include the common headers, their variables are at least
defined once.

The iobuf.{c,h} case is handled differently: iobuf.h gains an
unconditional "extern", with the variable being added to iobuf.c. This
is identical to what upstream's
6aff8a132815a84bab69401c1e7de96ec549fbf2 is doing.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 g10/options.h    | 3 +--
 include/cipher.h | 2 +-
 include/iobuf.h  | 9 +--------
 include/memory.h | 2 +-
 include/mpi.h    | 2 +-
 tools/bftest.c   | 1 +
 tools/mpicalc.c  | 1 +
 util/iobuf.c     | 2 ++
 8 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/g10/options.h b/g10/options.h
index 0ac6e7755..bae19e9e3 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -26,8 +26,7 @@
 #include "packet.h"
 
 #ifndef EXTERN_UNLESS_MAIN_MODULE
-/* Norcraft can't cope with common symbols */
-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
+#if !defined (INCLUDED_BY_MAIN_MODULE)
 #define EXTERN_UNLESS_MAIN_MODULE extern
 #else
 #define EXTERN_UNLESS_MAIN_MODULE
diff --git a/include/cipher.h b/include/cipher.h
index dd4af18cb..6ef6e6829 100644
--- a/include/cipher.h
+++ b/include/cipher.h
@@ -115,7 +115,7 @@ struct gcry_md_context {
 typedef struct gcry_md_context *MD_HANDLE;
 
 #ifndef EXTERN_UNLESS_MAIN_MODULE
-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
+#if !defined (INCLUDED_BY_MAIN_MODULE)
 #define EXTERN_UNLESS_MAIN_MODULE extern
 #else
 #define EXTERN_UNLESS_MAIN_MODULE
diff --git a/include/iobuf.h b/include/iobuf.h
index 030f8c8e9..b4d26b7e1 100644
--- a/include/iobuf.h
+++ b/include/iobuf.h
@@ -69,14 +69,7 @@ struct iobuf_struct {
     } unget;
 };
 
-#ifndef EXTERN_UNLESS_MAIN_MODULE
-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
-#define EXTERN_UNLESS_MAIN_MODULE extern
-#else
-#define EXTERN_UNLESS_MAIN_MODULE 
-#endif
-#endif
-EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
+extern int iobuf_debug_mode;
 
 void  iobuf_enable_special_filenames ( int yes );
 int   iobuf_is_pipe_filename (const char *fname);
diff --git a/include/memory.h b/include/memory.h
index d414a9b2e..6698337e3 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -91,7 +91,7 @@ unsigned secmem_get_flags(void);
 #define DBG_MEMSTAT   memory_stat_debug_mode
 
 #ifndef EXTERN_UNLESS_MAIN_MODULE
-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
+#if !defined (INCLUDED_BY_MAIN_MODULE)
 #define EXTERN_UNLESS_MAIN_MODULE extern
 #else
 #define EXTERN_UNLESS_MAIN_MODULE 
diff --git a/include/mpi.h b/include/mpi.h
index a4c16f5af..7a45ff805 100644
--- a/include/mpi.h
+++ b/include/mpi.h
@@ -36,7 +36,7 @@
 #include "memory.h"
 
 #ifndef EXTERN_UNLESS_MAIN_MODULE
-#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
+#if !defined (INCLUDED_BY_MAIN_MODULE)
 #define EXTERN_UNLESS_MAIN_MODULE extern
 #else
 #define EXTERN_UNLESS_MAIN_MODULE 
diff --git a/tools/bftest.c b/tools/bftest.c
index 8a1572c2b..5afd7e125 100644
--- a/tools/bftest.c
+++ b/tools/bftest.c
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 #endif
 
+#define INCLUDED_BY_MAIN_MODULE
 #include "util.h"
 #include "cipher.h"
 #include "i18n.h"
diff --git a/tools/mpicalc.c b/tools/mpicalc.c
index 46e5fc824..31acd82a4 100644
--- a/tools/mpicalc.c
+++ b/tools/mpicalc.c
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#define INCLUDED_BY_MAIN_MODULE
 #include "util.h"
 #include "mpi.h"
 #include "i18n.h"
diff --git a/util/iobuf.c b/util/iobuf.c
index c8442929a..0d9ee4cec 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -113,6 +113,8 @@ typedef struct {
  static CLOSE_CACHE close_cache;
 #endif
 
+int iobuf_debug_mode;
+
 #ifdef _WIN32
 typedef struct {
     int sock;
-- 
2.26.2