1 /* Copyright 2016 Google Inc. All Rights Reserved. 2 3 Distributed under MIT license. 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 */ 6 7 /* Macros for compiler / platform specific API declarations. */ 8 9 #ifndef BROTLI_COMMON_PORT_H_ 10 #define BROTLI_COMMON_PORT_H_ 11 12 /* The following macros were borrowed from https://github.com/nemequ/hedley 13 * with permission of original author - Evan Nemerson <evan@nemerson.com> */ 14 15 /* >>> >>> >>> hedley macros */ 16 17 #define BROTLI_MAKE_VERSION(major, minor, revision) \ 18 (((major) * 1000000) + ((minor) * 1000) + (revision)) 19 20 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) 21 #define BROTLI_GNUC_VERSION \ 22 BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 23 #elif defined(__GNUC__) 24 #define BROTLI_GNUC_VERSION BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, 0) 25 #endif 26 27 #if defined(BROTLI_GNUC_VERSION) 28 #define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) \ 29 (BROTLI_GNUC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 30 #else 31 #define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) (0) 32 #endif 33 34 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) 35 #define BROTLI_MSVC_VERSION \ 36 BROTLI_MAKE_VERSION((_MSC_FULL_VER / 10000000), \ 37 (_MSC_FULL_VER % 10000000) / 100000, \ 38 (_MSC_FULL_VER % 100000) / 100) 39 #elif defined(_MSC_FULL_VER) 40 #define BROTLI_MSVC_VERSION \ 41 BROTLI_MAKE_VERSION((_MSC_FULL_VER / 1000000), \ 42 (_MSC_FULL_VER % 1000000) / 10000, \ 43 (_MSC_FULL_VER % 10000) / 10) 44 #elif defined(_MSC_VER) 45 #define BROTLI_MSVC_VERSION \ 46 BROTLI_MAKE_VERSION(_MSC_VER / 100, _MSC_VER % 100, 0) 47 #endif 48 49 #if !defined(_MSC_VER) 50 #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) (0) 51 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) 52 #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \ 53 (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) 54 #elif defined(_MSC_VER) && (_MSC_VER >= 1200) 55 #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \ 56 (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) 57 #else 58 #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \ 59 (_MSC_VER >= ((major * 100) + (minor))) 60 #endif 61 62 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) 63 #define BROTLI_INTEL_VERSION \ 64 BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, \ 65 __INTEL_COMPILER % 100, \ 66 __INTEL_COMPILER_UPDATE) 67 #elif defined(__INTEL_COMPILER) 68 #define BROTLI_INTEL_VERSION \ 69 BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) 70 #endif 71 72 #if defined(BROTLI_INTEL_VERSION) 73 #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) \ 74 (BROTLI_INTEL_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 75 #else 76 #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) (0) 77 #endif 78 79 #if defined(__PGI) && \ 80 defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) 81 #define BROTLI_PGI_VERSION \ 82 BROTLI_MAKE_VERSION(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) 83 #endif 84 85 #if defined(BROTLI_PGI_VERSION) 86 #define BROTLI_PGI_VERSION_CHECK(major, minor, patch) \ 87 (BROTLI_PGI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 88 #else 89 #define BROTLI_PGI_VERSION_CHECK(major, minor, patch) (0) 90 #endif 91 92 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) 93 #define BROTLI_SUNPRO_VERSION \ 94 BROTLI_MAKE_VERSION( \ 95 (((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), \ 96 (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), \ 97 (__SUNPRO_C & 0xf) * 10) 98 #elif defined(__SUNPRO_C) 99 #define BROTLI_SUNPRO_VERSION \ 100 BROTLI_MAKE_VERSION((__SUNPRO_C >> 8) & 0xf, \ 101 (__SUNPRO_C >> 4) & 0xf, \ 102 (__SUNPRO_C) & 0xf) 103 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) 104 #define BROTLI_SUNPRO_VERSION \ 105 BROTLI_MAKE_VERSION( \ 106 (((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), \ 107 (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), \ 108 (__SUNPRO_CC & 0xf) * 10) 109 #elif defined(__SUNPRO_CC) 110 #define BROTLI_SUNPRO_VERSION \ 111 BROTLI_MAKE_VERSION((__SUNPRO_CC >> 8) & 0xf, \ 112 (__SUNPRO_CC >> 4) & 0xf, \ 113 (__SUNPRO_CC) & 0xf) 114 #endif 115 116 #if defined(BROTLI_SUNPRO_VERSION) 117 #define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) \ 118 (BROTLI_SUNPRO_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 119 #else 120 #define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) (0) 121 #endif 122 123 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) 124 #define BROTLI_ARM_VERSION \ 125 BROTLI_MAKE_VERSION((__ARMCOMPILER_VERSION / 1000000), \ 126 (__ARMCOMPILER_VERSION % 1000000) / 10000, \ 127 (__ARMCOMPILER_VERSION % 10000) / 100) 128 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION) 129 #define BROTLI_ARM_VERSION \ 130 BROTLI_MAKE_VERSION((__ARMCC_VERSION / 1000000), \ 131 (__ARMCC_VERSION % 1000000) / 10000, \ 132 (__ARMCC_VERSION % 10000) / 100) 133 #endif 134 135 #if defined(BROTLI_ARM_VERSION) 136 #define BROTLI_ARM_VERSION_CHECK(major, minor, patch) \ 137 (BROTLI_ARM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 138 #else 139 #define BROTLI_ARM_VERSION_CHECK(major, minor, patch) (0) 140 #endif 141 142 #if defined(__ibmxl__) 143 #define BROTLI_IBM_VERSION \ 144 BROTLI_MAKE_VERSION(__ibmxl_version__, \ 145 __ibmxl_release__, \ 146 __ibmxl_modification__) 147 #elif defined(__xlC__) && defined(__xlC_ver__) 148 #define BROTLI_IBM_VERSION \ 149 BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) 150 #elif defined(__xlC__) 151 #define BROTLI_IBM_VERSION BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, 0) 152 #endif 153 154 #if defined(BROTLI_IBM_VERSION) 155 #define BROTLI_IBM_VERSION_CHECK(major, minor, patch) \ 156 (BROTLI_IBM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 157 #else 158 #define BROTLI_IBM_VERSION_CHECK(major, minor, patch) (0) 159 #endif 160 161 #if defined(__TI_COMPILER_VERSION__) 162 #define BROTLI_TI_VERSION \ 163 BROTLI_MAKE_VERSION((__TI_COMPILER_VERSION__ / 1000000), \ 164 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \ 165 (__TI_COMPILER_VERSION__ % 1000)) 166 #endif 167 168 #if defined(BROTLI_TI_VERSION) 169 #define BROTLI_TI_VERSION_CHECK(major, minor, patch) \ 170 (BROTLI_TI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 171 #else 172 #define BROTLI_TI_VERSION_CHECK(major, minor, patch) (0) 173 #endif 174 175 #if defined(__IAR_SYSTEMS_ICC__) 176 #if __VER__ > 1000 177 #define BROTLI_IAR_VERSION \ 178 BROTLI_MAKE_VERSION((__VER__ / 1000000), \ 179 (__VER__ / 1000) % 1000, \ 180 (__VER__ % 1000)) 181 #else 182 #define BROTLI_IAR_VERSION BROTLI_MAKE_VERSION(VER / 100, __VER__ % 100, 0) 183 #endif 184 #endif 185 186 #if defined(BROTLI_IAR_VERSION) 187 #define BROTLI_IAR_VERSION_CHECK(major, minor, patch) \ 188 (BROTLI_IAR_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 189 #else 190 #define BROTLI_IAR_VERSION_CHECK(major, minor, patch) (0) 191 #endif 192 193 #if defined(__TINYC__) 194 #define BROTLI_TINYC_VERSION \ 195 BROTLI_MAKE_VERSION(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) 196 #endif 197 198 #if defined(BROTLI_TINYC_VERSION) 199 #define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) \ 200 (BROTLI_TINYC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch)) 201 #else 202 #define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) (0) 203 #endif 204 205 #if defined(__has_attribute) 206 #define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \ 207 __has_attribute(attribute) 208 #else 209 #define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \ 210 BROTLI_GNUC_VERSION_CHECK(major, minor, patch) 211 #endif 212 213 #if defined(__has_builtin) 214 #define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \ 215 __has_builtin(builtin) 216 #else 217 #define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \ 218 BROTLI_GNUC_VERSION_CHECK(major, minor, patch) 219 #endif 220 221 #if defined(_WIN32) || defined(__CYGWIN__) 222 #define BROTLI_PUBLIC 223 #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \ 224 BROTLI_TI_VERSION_CHECK(8, 0, 0) || \ 225 BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \ 226 BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \ 227 BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \ 228 BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \ 229 (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \ 230 defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__)) 231 #define BROTLI_PUBLIC __attribute__ ((visibility ("default"))) 232 #else 233 #define BROTLI_PUBLIC 234 #endif 235 236 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ 237 !defined(__STDC_NO_VLA__) && !defined(__cplusplus) && \ 238 !defined(__PGI) && !defined(__PGIC__) && !defined(__TINYC__) 239 #define BROTLI_ARRAY_PARAM(name) (name) 240 #else 241 #define BROTLI_ARRAY_PARAM(name) 242 #endif 243 244 /* <<< <<< <<< end of hedley macros. */ 245 246 #if defined(BROTLI_SHARED_COMPILATION) 247 #if defined(_WIN32) 248 #if defined(BROTLICOMMON_SHARED_COMPILATION) 249 #define BROTLI_COMMON_API __declspec(dllexport) 250 #else 251 #define BROTLI_COMMON_API __declspec(dllimport) 252 #endif /* BROTLICOMMON_SHARED_COMPILATION */ 253 #if defined(BROTLIDEC_SHARED_COMPILATION) 254 #define BROTLI_DEC_API __declspec(dllexport) 255 #else 256 #define BROTLI_DEC_API __declspec(dllimport) 257 #endif /* BROTLIDEC_SHARED_COMPILATION */ 258 #if defined(BROTLIENC_SHARED_COMPILATION) 259 #define BROTLI_ENC_API __declspec(dllexport) 260 #else 261 #define BROTLI_ENC_API __declspec(dllimport) 262 #endif /* BROTLIENC_SHARED_COMPILATION */ 263 #else /* _WIN32 */ 264 #define BROTLI_COMMON_API BROTLI_PUBLIC 265 #define BROTLI_DEC_API BROTLI_PUBLIC 266 #define BROTLI_ENC_API BROTLI_PUBLIC 267 #endif /* _WIN32 */ 268 #else /* BROTLI_SHARED_COMPILATION */ 269 #define BROTLI_COMMON_API 270 #define BROTLI_DEC_API 271 #define BROTLI_ENC_API 272 #endif 273 274 #endif /* BROTLI_COMMON_PORT_H_ */ 275