enable DECLARE_DEPRECATED macro for Oracle Developer Studio compiler
[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 #  elif defined(__SUNPRO_C)
37 #   if (__SUNPRO_C >= 0x5130)
38 #    undef DECLARE_DEPRECATED
39 #    define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
40 #   endif
41 #  endif
42 # endif
43
44 /*
45  * We convert the OPENSSL_API_COMPAT value to an API level.  The API level
46  * is the major version number for 3.0.0 and on.  For earlier versions, it
47  * uses this scheme, which is close enough for our purposes:
48  *
49  *      0.x.y   0       (0.9.8 was the last release in this series)
50  *      1.0.x   1       (1.0.2 was the last release in this series)
51  *      1.1.x   2       (1.1.1 was the last release in this series)
52  */
53
54 /* In case someone defined both */
55 # if defined(OPENSSL_API_COMPAT) && defined(OPENSSL_API_LEVEL)
56 #  error "Disallowed to define both OPENSSL_API_COMPAT and OPENSSL_API_LEVEL"
57 # endif
58
59 # ifndef OPENSSL_API_COMPAT
60 #  define OPENSSL_API_LEVEL OPENSSL_MIN_API
61 # else
62 #  if (OPENSSL_API_COMPAT < 0x1000L) /* Major version numbers up to 16777215 */
63 #   define OPENSSL_API_LEVEL OPENSSL_API_COMPAT
64 #  elif (OPENSSL_API_COMPAT & 0xF0000000L) == 0x00000000L
65 #   define OPENSSL_API_LEVEL 0
66 #  elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10000000L
67 #   define OPENSSL_API_LEVEL 1
68 #  elif (OPENSSL_API_COMPAT & 0xFFF00000L) == 0x10100000L
69 #   define OPENSSL_API_LEVEL 2
70 #  else
71     /* Major number 3 to 15 */
72 #   define OPENSSL_API_LEVEL ((OPENSSL_API_COMPAT >> 28) & 0xF)
73 #  endif
74 # endif
75
76 /*
77  * Do not deprecate things to be deprecated in version 4.0 before the
78  * OpenSSL version number matches.
79  */
80 # if OPENSSL_VERSION_MAJOR < 4
81 #  define DEPRECATEDIN_4(f)       f;
82 #  define OPENSSL_API_4 0
83 # elif OPENSSL_API_LEVEL < 4
84 #  define DEPRECATEDIN_4(f)       DECLARE_DEPRECATED(f)
85 #  define OPENSSL_API_4 0
86 # else
87 #  define DEPRECATEDIN_4(f)
88 #  define OPENSSL_API_4 1
89 # endif
90
91 # if OPENSSL_API_LEVEL < 3
92 #  define DEPRECATEDIN_3(f)       DECLARE_DEPRECATED(f)
93 #  define OPENSSL_API_3 0
94 # else
95 #  define DEPRECATEDIN_3(f)
96 #  define OPENSSL_API_3 1
97 # endif
98
99 # if OPENSSL_API_LEVEL < 2
100 #  define DEPRECATEDIN_1_1_0(f)   DECLARE_DEPRECATED(f)
101 #  define OPENSSL_API_1_1_0 0
102 # else
103 #  define DEPRECATEDIN_1_1_0(f)
104 #  define OPENSSL_API_1_1_0 1
105 # endif
106
107 # if OPENSSL_API_LEVEL < 1
108 #  define DEPRECATEDIN_1_0_0(f)   DECLARE_DEPRECATED(f)
109 #  define OPENSSL_API_1_0_0 0
110 # else
111 #  define DEPRECATEDIN_1_0_0(f)
112 #  define OPENSSL_API_1_0_0 1
113 # endif
114
115 # if OPENSSL_API_LEVEL < 0
116 #  define DEPRECATEDIN_0_9_8(f)   DECLARE_DEPRECATED(f)
117 #  define OPENSSL_API_0_9_8 0
118 # else
119 #  define DEPRECATEDIN_0_9_8(f)
120 #  define OPENSSL_API_0_9_8 1
121 # endif
122
123 # ifndef OPENSSL_FILE
124 #  ifdef OPENSSL_NO_FILENAMES
125 #   define OPENSSL_FILE ""
126 #   define OPENSSL_LINE 0
127 #  else
128 #   define OPENSSL_FILE __FILE__
129 #   define OPENSSL_LINE __LINE__
130 #  endif
131 # endif
132
133 # ifndef OPENSSL_FUNC
134 #  if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
135 #   define OPENSSL_FUNC __func__
136 #  elif defined(__STDC__) && defined(PEDANTIC)
137 #   define OPENSSL_FUNC "(PEDANTIC disallows function name)"
138 #  elif defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ >= 2)
139 #   define OPENSSL_FUNC __FUNCTION__
140 #  elif defined(__FUNCSIG__)
141 #   define OPENSSL_FUNC __FUNCSIG__
142 #  else
143 #   define OPENSSL_FUNC "(unknown function)"
144 #  endif
145 # endif
146
147 #endif  /* OPENSSL_MACROS_H */