tidy up a load of lintian warnings
[freeradius.git] / src / include / build.h
1 /**
2  * $Id$
3  *
4  * @brief Source control functions
5  *
6  * @copyright 2013 The FreeRADIUS server project
7  */
8 #ifndef _BUILD_H
9 #define _BUILD_H
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 #include <freeradius-devel/autoconf.h>  /* Needed for endian macros */
14
15 /*
16  *      The ubiquitous stringify macros
17  */
18 #define XSTRINGIFY(x) #x
19 #define STRINGIFY(x) XSTRINGIFY(x)
20 #define JOINSTR(x,y) XSTRINGIFY(x ## y)
21
22 /*
23  *      HEX concatenation macros
24  */
25 #ifndef HEXIFY
26 #  define XHEXIFY4(b1,b2,b3,b4) (0x ## b1 ## b2 ## b3 ## b4)
27 #  define HEXIFY4(b1,b2,b3,b4)  XHEXIFY4(b1, b2, b3, b4)
28
29 #  define XHEXIFY3(b1,b2,b3)    (0x ## b1 ## b2 ## b3)
30 #  define HEXIFY3(b1,b2,b3)     XHEXIFY3(b1, b2, b3)
31
32 #  define XHEXIFY2(b1,b2)       (0x ## b1 ## b2)
33 #  define HEXIFY2(b1,b2)        XHEXIFY2(b1, b2)
34
35 #  define XHEXIFY(b1)           (0x ## b1)
36 #  define HEXIFY(b1)            XHEXIFY(b1)
37 #endif
38
39 /*
40  *      struct field size
41  */
42 #define SIZEOF_MEMBER(_t, _m) sizeof(((_t *)0)->_m)
43
44 /*
45  *      Only use GCC __attribute__ if were building with a GCClike
46  *      compiler.
47  */
48 #ifdef __GNUC__
49 #  define CC_HINT(_x) __attribute__ ((_x))
50 #else
51 #  define CC_HINT(_x)
52 #endif
53
54 #ifdef HAVE_ATTRIBUTE_BOUNDED
55 #  define CC_BOUNDED(_x, ...) CC_HINT(__bounded__(_x, ## __VA_ARGS__))
56 #else
57 #  define CC_BOUNDED(...)
58 #endif
59
60 /*
61  *      Macros to add pragmas
62  */
63 #define PRAGMA(_x) _Pragma(#_x)
64
65 /*
66  *      Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
67  */
68 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
69 #  define DIAG_PRAGMA(_x) PRAGMA(GCC diagnostic _x)
70 #  if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
71 #    define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
72 #    define DIAG_ON(_x) DIAG_PRAGMA(pop)
73 #  else
74 #    define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
75 #    define DIAG_ON(_x)  DIAG_PRAGMA(warning JOINSTR(-W,_x))
76 #  endif
77 #elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208)
78 #  define DIAG_PRAGMA(_x) PRAGMA(clang diagnostic _x)
79 #  define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
80 #  define DIAG_ON(_x) DIAG_PRAGMA(pop)
81 #else
82 #  define DIAG_OFF(_x)
83 #  define DIAG_ON(_x)
84 #endif
85
86 /*
87  *      GCC and clang use different macros
88  */
89 #ifdef __clang__
90 # define DIAG_OPTIONAL DIAG_OFF(unknown-pragmas)
91 #else
92 # define DIAG_OPTIONAL DIAG_OFF(pragmas)
93 #endif
94
95 /*
96  *      For dealing with APIs which are only deprecated in OSX (like the OpenSSL API)
97  */
98 #ifdef __APPLE__
99 #  define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
100 #  define USES_APPLE_RST DIAG_ON(deprecated-declarations)
101 #else
102 #  define USES_APPLE_DEPRECATED_API
103 #  define USES_APPLE_RST
104 #endif
105
106 #if defined(__GNUC__)
107 /* force inclusion of ident keywords in the face of optimization */
108 #  define RCSID(id) static char const rcsid[] __attribute__ ((used)) = id;
109 #  define RCSIDH(h, id) static char const rcsid_ ## h [] __attribute__ ((used)) = id;
110 #elif defined(__SUNPRO_C)
111 /* put ident keyword into comment section (nicer than gcc way) */
112 #  define RCSID(id) PRAGMA(sun ident id)
113 #  define RCSIDH(h, id) PRAGMA(sun ident id)
114 #else
115 #  define RCSID(id)
116 #  define RCSIDH(h, id)
117 #endif
118
119 /*
120  *      Try and determine endianness of the target system.
121  *
122  *      Other projects seem to use endian.h and variants, but these are
123  *      in non standard locations, and may mess up cross compiling.
124  *
125  *      Here at least the endianness can be set explicitly with
126  *      -DLITTLE_ENDIAN or -DBIG_ENDIAN.
127  */
128 #if !defined(FR_LITTLE_ENDIAN) && !defined(FR_BIG_ENDIAN)
129 #  if defined(__LITTLE_ENDIAN__) || \
130       (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
131 #    define FR_LITTLE_ENDIAN 1
132 #  elif defined(__BIG_ENDIAN__) || \
133       (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
134 #    define FR_BIG_ENDIAN 1
135 #  else
136 #    error Failed determining endianness of system
137 #  endif
138 #endif
139
140 #ifdef __cplusplus
141 }
142 #endif
143 #endif /* _BUILD_H */