1 /*  hts_defs.h -- Miscellaneous definitions.
2 
3     Copyright (C) 2013-2015,2017, 2019-2020 Genome Research Ltd.
4 
5     Author: John Marshall <jm18@sanger.ac.uk>
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE.  */
24 
25 #ifndef HTSLIB_HTS_DEFS_H
26 #define HTSLIB_HTS_DEFS_H
27 
28 #if defined __MINGW32__
29 #include <stdio.h>     // For __MINGW_PRINTF_FORMAT macro
30 #endif
31 
32 #ifdef __clang__
33 #ifdef __has_attribute
34 #define HTS_COMPILER_HAS(attribute) __has_attribute(attribute)
35 #endif
36 
37 #elif defined __GNUC__
38 #define HTS_GCC_AT_LEAST(major, minor) \
39     (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
40 #endif
41 
42 #ifndef HTS_COMPILER_HAS
43 #define HTS_COMPILER_HAS(attribute) 0
44 #endif
45 #ifndef HTS_GCC_AT_LEAST
46 #define HTS_GCC_AT_LEAST(major, minor) 0
47 #endif
48 
49 #if HTS_COMPILER_HAS(__nonstring__) || HTS_GCC_AT_LEAST(8,1)
50 #define HTS_NONSTRING __attribute__ ((__nonstring__))
51 #else
52 #define HTS_NONSTRING
53 #endif
54 
55 #if HTS_COMPILER_HAS(__noreturn__) || HTS_GCC_AT_LEAST(3,0)
56 #define HTS_NORETURN __attribute__ ((__noreturn__))
57 #else
58 #define HTS_NORETURN
59 #endif
60 
61 // GCC introduced warn_unused_result in 3.4 but added -Wno-unused-result later
62 #if HTS_COMPILER_HAS(__warn_unused_result__) || HTS_GCC_AT_LEAST(4,5)
63 #define HTS_RESULT_USED __attribute__ ((__warn_unused_result__))
64 #else
65 #define HTS_RESULT_USED
66 #endif
67 
68 #if HTS_COMPILER_HAS(__unused__) || HTS_GCC_AT_LEAST(3,0)
69 #define HTS_UNUSED __attribute__ ((__unused__))
70 #else
71 #define HTS_UNUSED
72 #endif
73 
74 #if HTS_COMPILER_HAS(__deprecated__) || HTS_GCC_AT_LEAST(4,5)
75 #define HTS_DEPRECATED(message) __attribute__ ((__deprecated__ (message)))
76 #elif HTS_GCC_AT_LEAST(3,1)
77 #define HTS_DEPRECATED(message) __attribute__ ((__deprecated__))
78 #else
79 #define HTS_DEPRECATED(message)
80 #endif
81 
82 #if (HTS_COMPILER_HAS(__deprecated__) || HTS_GCC_AT_LEAST(6,4)) && !defined(__ICC)
83 #define HTS_DEPRECATED_ENUM(message) __attribute__ ((__deprecated__ (message)))
84 #else
85 #define HTS_DEPRECATED_ENUM(message)
86 #endif
87 
88 // On mingw the "printf" format type doesn't work.  It needs "gnu_printf"
89 // in order to check %lld and %z, otherwise it defaults to checking against
90 // the Microsoft library printf format options despite linking against the
91 // GNU posix implementation of printf.  The __MINGW_PRINTF_FORMAT macro
92 // expands to printf or gnu_printf as required, but obviously may not
93 // exist
94 #ifdef __MINGW_PRINTF_FORMAT
95 #define HTS_PRINTF_FMT __MINGW_PRINTF_FORMAT
96 #else
97 #define HTS_PRINTF_FMT printf
98 #endif
99 
100 #if HTS_COMPILER_HAS(__format__) || HTS_GCC_AT_LEAST(3,0)
101 #define HTS_FORMAT(type, idx, first) __attribute__((__format__ (type, idx, first)))
102 #else
103 #define HTS_FORMAT(type, idx, first)
104 #endif
105 
106 #if defined(_WIN32) || defined(__CYGWIN__)
107 #if defined(HTS_BUILDING_LIBRARY)
108 #define HTSLIB_EXPORT __declspec(dllexport)
109 #else
110 #define HTSLIB_EXPORT
111 #endif
112 #elif HTS_COMPILER_HAS(__visibility__) || HTS_GCC_AT_LEAST(4,0)
113 #define HTSLIB_EXPORT __attribute__((__visibility__("default")))
114 #elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x550
115 #define HTSLIB_EXPORT __global
116 #else
117 #define HTSLIB_EXPORT
118 #endif
119 
120 #endif
121