Skip to content

Commit 60c6bd8

Browse files
build: Refactor visibility logic
1 parent c498779 commit 60c6bd8

File tree

1 file changed

+32
-39
lines changed

1 file changed

+32
-39
lines changed

include/secp256k1.h

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,45 +121,38 @@ typedef int (*secp256k1_nonce_function)(
121121
#endif
122122

123123
/* Symbol visibility. */
124-
#if defined(_WIN32)
125-
/* GCC for Windows (e.g., MinGW) accepts the __declspec syntax
126-
* for MSVC compatibility. A __declspec declaration implies (but is not
127-
* exactly equivalent to) __attribute__ ((visibility("default"))), and so we
128-
* actually want __declspec even on GCC, see "Microsoft Windows Function
129-
* Attributes" in the GCC manual and the recommendations in
130-
* https://gcc.gnu.org/wiki/Visibility. */
131-
# if defined(SECP256K1_BUILD)
132-
# if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)
133-
/* Building libsecp256k1 as a DLL.
134-
* 1. If using Libtool, it defines DLL_EXPORT automatically.
135-
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
136-
# define SECP256K1_API extern __declspec (dllexport)
137-
# else
138-
/* Building libsecp256k1 as a static library on Windows.
139-
* No declspec is needed, and so we would want the non-Windows-specific
140-
* logic below take care of this case. However, this may result in setting
141-
* __attribute__ ((visibility("default"))), which is supposed to be a noop
142-
* on Windows but may trigger warnings when compiling with -flto due to a
143-
* bug in GCC, see
144-
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */
145-
# define SECP256K1_API extern
146-
# endif
147-
/* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static
148-
* library on Windows. */
149-
# elif !defined(SECP256K1_STATIC)
150-
/* Consuming libsecp256k1 as a DLL. */
151-
# define SECP256K1_API extern __declspec (dllimport)
152-
# endif
153-
#endif
154-
#ifndef SECP256K1_API
155-
/* All cases not captured by the Windows-specific logic. */
156-
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
157-
/* Building libsecp256k1 using GCC or compatible. */
158-
# define SECP256K1_API extern __attribute__ ((visibility ("default")))
159-
# else
160-
/* Fall back to standard C's extern. */
161-
# define SECP256K1_API extern
162-
# endif
124+
#if !defined(SECP256K1_API)
125+
# if defined(SECP256K1_BUILD)
126+
/* On Windows, assume a shared library only if explicitly requested.
127+
* 1. If using Libtool, it defines DLL_EXPORT automatically.
128+
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
129+
# if defined(_WIN32) && defined(SECP256K1_DLL_EXPORT) || defined(DLL_EXPORT)
130+
/* GCC for Windows (e.g., MinGW) accepts the __declspec syntax for
131+
* MSVC compatibility. A __declspec declaration implies (but is not
132+
* exactly equivalent to) __attribute__ ((visibility("default"))),
133+
* and so we actually want __declspec even on GCC, see "Microsoft
134+
* Windows Function Attributes" in the GCC manual and the
135+
* recommendations in https://gcc.gnu.org/wiki/Visibility . */
136+
# define SECP256K1_API extern __declspec(dllexport)
137+
/* Avoid __attribute__ ((visibility("default"))) on Windows to get rid
138+
* of warnings when compiling with -flto due to a bug in GCC, see
139+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */
140+
# elif defined (__GNUC__) && (__GNUC__ >= 4) && !defined(_WIN32)
141+
# define SECP256K1_API extern __attribute__ ((visibility("default")))
142+
# else
143+
# define SECP256K1_API extern
144+
# endif
145+
# else
146+
/* On Windows, SECP256K1_STATIC must be defined when consuming
147+
* libsecp256k1 as a static library. Note that SECP256K1_STATIC is a
148+
* "consumer-only" macro, and it has no meaning when building
149+
* libsecp256k1. */
150+
# if defined(_WIN32) && !defined(SECP256K1_STATIC)
151+
# define SECP256K1_API extern __declspec(dllimport)
152+
# else
153+
# define SECP256K1_API extern
154+
# endif
155+
# endif
163156
#endif
164157

165158
/* Warning attributes

0 commit comments

Comments
 (0)