All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
build.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef _FR_BUILD_H
17 #define _FR_BUILD_H
18 /**
19  * $Id: c4d8bce46dbfafc3b77301c2d642cb2ffdafe75b $
20  *
21  * @file include/build.h
22  * @brief Source control functions
23  *
24  * @copyright 2013 The FreeRADIUS server project
25  */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 /*
31  * The ubiquitous stringify macros
32  */
33 #define XSTRINGIFY(x) #x
34 #define STRINGIFY(x) XSTRINGIFY(x)
35 #define JOINSTR(x,y) XSTRINGIFY(x ## y)
36 
37 /*
38  * HEX concatenation macros
39  */
40 #ifndef HEXIFY
41 # define XHEXIFY4(b1,b2,b3,b4) (0x ## b1 ## b2 ## b3 ## b4)
42 # define HEXIFY4(b1,b2,b3,b4) XHEXIFY4(b1, b2, b3, b4)
43 
44 # define XHEXIFY3(b1,b2,b3) (0x ## b1 ## b2 ## b3)
45 # define HEXIFY3(b1,b2,b3) XHEXIFY3(b1, b2, b3)
46 
47 # define XHEXIFY2(b1,b2) (0x ## b1 ## b2)
48 # define HEXIFY2(b1,b2) XHEXIFY2(b1, b2)
49 
50 # define XHEXIFY(b1) (0x ## b1)
51 # define HEXIFY(b1) XHEXIFY(b1)
52 #endif
53 
54 /*
55  * Mark variables as unused
56  */
57 #define UNUSED_VAR(_x) ((void)_x)
58 
59 /*
60  * struct field size
61  */
62 #define SIZEOF_MEMBER(_t, _m) sizeof(((_t *)0)->_m)
63 
64 /*
65  * Only use GCC __attribute__ if were building with a GCClike
66  * compiler.
67  */
68 #ifdef __GNUC__
69 # define CC_HINT(_x) __attribute__ ((_x))
70 #else
71 # define CC_HINT(_x)
72 #endif
73 
74 #ifdef HAVE_ATTRIBUTE_BOUNDED
75 # define CC_BOUNDED(_x, ...) CC_HINT(__bounded__(_x, ## __VA_ARGS__))
76 #else
77 # define CC_BOUNDED(...)
78 #endif
79 
80 /*
81  * Macros to add pragmas
82  */
83 #define PRAGMA(_x) _Pragma(#_x)
84 
85 /*
86  * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
87  */
88 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
89 # define DIAG_PRAGMA(_x) PRAGMA(GCC diagnostic _x)
90 # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
91 # define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
92 # define DIAG_ON(_x) DIAG_PRAGMA(pop)
93 # else
94 # define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
95 # define DIAG_ON(_x) DIAG_PRAGMA(warning JOINSTR(-W,_x))
96 # endif
97 #elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208)
98 # define DIAG_PRAGMA(_x) PRAGMA(clang diagnostic _x)
99 # define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x))
100 # define DIAG_ON(_x) DIAG_PRAGMA(pop)
101 #else
102 # define DIAG_OFF(_x)
103 # define DIAG_ON(_x)
104 #endif
105 
106 /*
107  * GCC and clang use different macros
108  */
109 #ifdef __clang__
110 # define DIAG_OPTIONAL DIAG_OFF(unknown-pragmas)
111 #else
112 # define DIAG_OPTIONAL DIAG_OFF(pragmas)
113 #endif
114 
115 /*
116  * For dealing with APIs which are only deprecated in OSX (like the OpenSSL API)
117  */
118 #ifdef __APPLE__
119 # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
120 # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
121 #else
122 # define USES_APPLE_DEPRECATED_API
123 # define USES_APPLE_RST
124 #endif
125 
126 #if defined(__GNUC__)
127 /* force inclusion of ident keywords in the face of optimization */
128 # define RCSID(id) static char const rcsid[] __attribute__ ((used)) = id;
129 # define RCSIDH(h, id) static char const rcsid_ ## h [] __attribute__ ((used)) = id;
130 #elif defined(__SUNPRO_C)
131 /* put ident keyword into comment section (nicer than gcc way) */
132 # define RCSID(id) PRAGMA(sun ident id)
133 # define RCSIDH(h, id) PRAGMA(sun ident id)
134 #else
135 # define RCSID(id)
136 # define RCSIDH(h, id)
137 #endif
138 #ifdef __cplusplus
139 }
140 #endif
141 #endif /* _FR_BUILD_H */