4 * @brief Source control functions
6 * @copyright 2013 The FreeRADIUS server project
13 #include <freeradius-devel/autoconf.h> /* Needed for endian macros */
16 * The ubiquitous stringify macros
18 #define XSTRINGIFY(x) #x
19 #define STRINGIFY(x) XSTRINGIFY(x)
20 #define JOINSTR(x,y) XSTRINGIFY(x ## y)
23 * HEX concatenation macros
26 # define XHEXIFY4(b1,b2,b3,b4) (0x ## b1 ## b2 ## b3 ## b4)
27 # define HEXIFY4(b1,b2,b3,b4) XHEXIFY4(b1, b2, b3, b4)
29 # define XHEXIFY3(b1,b2,b3) (0x ## b1 ## b2 ## b3)
30 # define HEXIFY3(b1,b2,b3) XHEXIFY3(b1, b2, b3)
32 # define XHEXIFY2(b1,b2) (0x ## b1 ## b2)
33 # define HEXIFY2(b1,b2) XHEXIFY2(b1, b2)
35 # define XHEXIFY(b1) (0x ## b1)
36 # define HEXIFY(b1) XHEXIFY(b1)
42 #define SIZEOF_MEMBER(_t, _m) sizeof(((_t *)0)->_m)
45 * Only use GCC __attribute__ if were building with a GCClike
49 # define CC_HINT(_x) __attribute__ ((_x))
54 #ifdef HAVE_ATTRIBUTE_BOUNDED
55 # define CC_BOUNDED(_x, ...) CC_HINT(__bounded__(_x, ## __VA_ARGS__))
57 # define CC_BOUNDED(...)
61 * Macros to add pragmas
63 #define PRAGMA(_x) _Pragma(#_x)
66 * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
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)
74 # define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
75 # define DIAG_ON(_x) DIAG_PRAGMA(warning JOINSTR(-W,_x))
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)
87 * GCC and clang use different macros
90 # define DIAG_OPTIONAL DIAG_OFF(unknown-pragmas)
92 # define DIAG_OPTIONAL DIAG_OFF(pragmas)
96 * For dealing with APIs which are only deprecated in OSX (like the OpenSSL API)
99 # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
100 # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
102 # define USES_APPLE_DEPRECATED_API
103 # define USES_APPLE_RST
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)
116 # define RCSIDH(h, id)
120 * Try and determine endianness of the target system.
122 * Other projects seem to use endian.h and variants, but these are
123 * in non standard locations, and may mess up cross compiling.
125 * Here at least the endianness can be set explicitly with
126 * -DLITTLE_ENDIAN or -DBIG_ENDIAN.
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
136 # error Failed determining endianness of system
143 #endif /* _BUILD_H */