Move some macros from include/openssl/opensslconf.h.in, add OPENSSL_FUNC
[openssl.git] / include / openssl / macros.h
1 /*
2  * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef OPENSSL_MACROS_H
11 # define OPENSSL_MACROS_H
12
13 /*
14  * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
15  * don't like that.  This will hopefully silence them.
16  */
17 # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
18
19 /*
20  * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
21  * declarations of functions deprecated in or before <version>.  If this is
22  * undefined, the value of the macro OPENSSL_API_MIN above is the default.
23  *
24  * For any version number up until version 1.1.x, <version> is expected to be
25  * the calculated version number 0xMNNFFPPSL.  For version numbers 3.0.0 and
26  * on, <version> is expected to be only the major version number (i.e. 3 for
27  * version 3.0.0).
28  */
29 # ifndef DECLARE_DEPRECATED
30 #  define DECLARE_DEPRECATED(f)   f;
31 #  ifdef __GNUC__
32 #   if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
33 #    undef DECLARE_DEPRECATED
34 #    define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
35 #   endif
36 #  endif
37 # endif
38
39 /*
40  * We convert the OPENSSL_API_COMPAT value to an API level.  The API level
41  * is the major version number for 3.0.0 and on.  For earlier versions, it
42  * uses this scheme, which is close enough for our purposes:
43  *
44  *      0.x.y   0       (0.9.8 was the last release in this series)
45  *      1.0.x   1       (1.0.2 was the last release in this series)
46  *      1.1.x   2       (1.1.1 was the last release in this series)
47  */
48
49 /* In case someone defined both */
50 # if defined(OPENSSL_API_COMPAT) && defined(OPENSSL_API_LEVEL)
51 #  error "Disallowed to define both OPENSSL_API_COMPAT and OPENSSL_API_LEVEL"
52 # endif
53
54 # ifndef OPENSSL_API_COMPAT
55 #  define OPENSSL_API_LEVEL OPENSSL_MIN_API
56 # else
57 #  if (OPENSSL_API_COMPAT < 0x1000L) /* Major version numbers up to 16777215 */
58 #   define OPENSSL_API_LEVEL OPENSSL_API_COMPAT
59 #  elif (OPENSSL_API_COMPAT & 0xF0000000L) == 0x00000000L
60 #   define OPENSSL_API_LEVEL 0
61 #  elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10000000L
62 #   define OPENSSL_API_LEVEL 1
63 #  elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10100000L
64 #   define OPENSSL_API_LEVEL 2
65 #  else
66     /* Major number 3 to 15 */
67 #   define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF)
68 #  endif
69 # endif
70
71 /*
72  * Do not deprecate things to be deprecated in version 4.0 before the
73  * OpenSSL version number matches.
74  */
75 # if OPENSSL_VERSION_MAJOR < 4
76 #  define DEPRECATEDIN_4(f)       f;
77 #  define OPENSSL_API_4 0
78 # elif OPENSSL_API_LEVEL < 4
79 #  define DEPRECATEDIN_4(f)       DECLARE_DEPRECATED(f)
80 #  define OPENSSL_API_4 0
81 # else
82 #  define DEPRECATEDIN_4(f)
83 #  define OPENSSL_API_4 1
84 # endif
85
86 # if OPENSSL_API_LEVEL < 3
87 #  define DEPRECATEDIN_3(f)       DECLARE_DEPRECATED(f)
88 #  define OPENSSL_API_3 0
89 # else
90 #  define DEPRECATEDIN_3(f)
91 #  define OPENSSL_API_3 1
92 # endif
93
94 # if OPENSSL_API_LEVEL < 2
95 #  define DEPRECATEDIN_1_1_0(f)   DECLARE_DEPRECATED(f)
96 #  define OPENSSL_API_1_1_0 0
97 # else
98 #  define DEPRECATEDIN_1_1_0(f)
99 #  define OPENSSL_API_1_1_0 1
100 # endif
101
102 # if OPENSSL_API_LEVEL < 1
103 #  define DEPRECATEDIN_1_0_0(f)   DECLARE_DEPRECATED(f)
104 #  define OPENSSL_API_1_0_0 0
105 # else
106 #  define DEPRECATEDIN_1_0_0(f)
107 #  define OPENSSL_API_1_0_0 1
108 # endif
109
110 # if OPENSSL_API_LEVEL < 0
111 #  define DEPRECATEDIN_0_9_8(f)   DECLARE_DEPRECATED(f)
112 #  define OPENSSL_API_0_9_8 0
113 # else
114 #  define DEPRECATEDIN_0_9_8(f)
115 #  define OPENSSL_API_0_9_8 1
116 # endif
117
118 # ifndef OPENSSL_FILE
119 #  ifdef OPENSSL_NO_FILENAMES
120 #   define OPENSSL_FILE ""
121 #   define OPENSSL_LINE 0
122 #  else
123 #   define OPENSSL_FILE __FILE__
124 #   define OPENSSL_LINE __LINE__
125 #  endif
126 # endif
127
128 # ifndef OPENSSL_FUNC
129 #  if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
130 #   define OPENSSL_FUNC __func__
131 #  elif defined(__STDC__) && defined(PEDANTIC)
132 #   define OPENSSL_FUNC "(PEDANTIC disallows function name)"
133 #  elif defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ >= 2)
134 #   define OPENSSL_FUNC __FUNCTION__
135 #  elif defined(__FUNCSIG__)
136 #   define OPENSSL_FUNC __FUNCSIG__
137 #  else
138 #   define OPENSSL_FUNC "(unknown function)"
139 #  endif
140 # endif
141
142 #endif  /* OPENSSL_MACROS_H */