librnr  1.14.5
RoadNarrows Robotics Common Library 1
rnrconfig.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 /*! \file
3  *
4  * \brief RoadNarrows Robotics common configuration file.
5  *
6  * The rnrconfig.h file provides a somewhat unified method to support
7  * various RoadNarrows supported processor architectures and host platforms.
8  *
9  * Common typedefs, sizes, return codes, and useful utility declarations are
10  * declared.
11  *
12  * \par Supported CPU archetectures:
13  * \param i386 Intel i386+ family of 32-bit processors.
14  * \param x86_64 AMD family of 64-bit processors.
15  * \param armpxa XScale PXA Arm processors.
16  *
17  * \par Supported platforms:
18  * \param windows Requires posix libraries.
19  * (see http://www.cygwin.com/)
20  * \param "posix linux" Tested on Ubuntu and Odroid Arm
21  * \param "familiar linux" Tested on K-Team's KoreBot embedded 2.4 linux SBC.
22  * \param "angstrom linux" Tested on K-Team's KoreBot embedded 2.6 linux SBC.
23  * \param os-x Mac OS-X
24  *
25  * \pkgsynopsis
26  * RoadNarrows Robotics Common Library 1
27  *
28  * \pkgcomponent{Library}
29  * librnr
30  *
31  * \pkgfile{rnr/rnrconfig.h}
32  *
33  * \author Robin Knight (robin.knight@roadnarrows.com)
34  *
35  * \pkgcopyright{2007-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
36  *
37  * \license{MIT}
38  *
39  * \EulaBegin
40  * See the README and EULA files for any copyright and licensing information.
41  * \EulaEnd
42  */
43 ////////////////////////////////////////////////////////////////////////////////
44 
45 #ifndef _RNRCONFIG_H
46 #define _RNRCONFIG_H
47 
48 #include <sys/param.h>
49 #include <sys/types.h>
50 
51 //
52 // Compiling for C++/C
53 //
54 #if defined(__CPLUSPLUS__) || defined(__cplusplus)
55 # ifndef __cplusplus
56 # define __cplusplus ///< always use this C++ convention for tests
57 # endif
58 #else
59 # undef __cplusplus
60 #endif
61 
62 //
63 // C declarations in C++
64 //
65 #ifdef __cplusplus
66 # define C_DECLS_BEGIN extern "C" { ///< C declaration block begin in C++
67 # define C_DECLS_END } ///< C declaration block end in C++
68 # define C_DECLS extern "C" ///< C declaration line in C++
69 # define C_EXTERN extern "C" ///< C extern declaration in C++
70 #else // C
71 # define C_DECLS_BEGIN ///< C declaration block begin in C
72 # define C_DECLS_END ///< C declaration block end in C
73 # define C_DECLS ///< C declaration line in C
74 # define C_EXTERN extern ///< C extern declaration in C
75 #endif // __cplusplus
76 
77 
78 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
79 // Platforms
80 // Note: Need to expand this. Posix needs to be factored in plus
81 // are there other platforms.
82 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
83 
84 //
85 // Linux Platforms
86 //
87 #if defined(__linux__) || defined(ARCH_i386) || defined(ARCH_x86_64) || \
88  defined(ARCH_armpxa) || defined(ARCH_armang)
89 
90 #ifndef __linux__
91 #define __linux__ ///< OS key define
92 #endif // __linux__
93 
94 #ifndef OSNAME
95 #define OSNAME "linux" ///< OS simple name
96 #endif // OSNAME
97 
98 //
99 // OS-X Platforms
100 //
101 #elif defined(__osx__) || defined(ARCH_osx)
102 
103 #ifndef __osx__
104 #define __osx__ ///< OS key define
105 #endif // __osx__
106 
107 #ifndef OSNAME
108 #define OSNAME "osx" ///< OS simple name
109 #endif // OSNAME
110 
111 //
112 // Windows Cygwin Platforms
113 //
114 #elif defined(__CYGWIN__) || defined(ARCH_cygwin)
115 
116 #ifndef __cygwin__
117 #define __cygwin__ ///< OS key define
118 #endif // __cygwin__
119 
120 #ifndef OSNAME
121 #define OSNAME "cygwin" ///< OS simple name
122 #endif // OSNAME
123 
124 //
125 // Windows Native Platforms
126 //
127 #elif defined(__windows__) || defined(ARCH_win)
128 
129 #ifndef __windows__
130 #define __windows__ ///< OS key define
131 #endif // __windows__
132 
133 #ifndef OSNAME
134 #define OSNAME "windows" ///< OS simple name
135 #endif // OSNAME
136 
137 #endif // Platforms
138 
139 //
140 // Dynamic Library C Export Declarators
141 // Note: Needs some tweaking.
142 //
143 #ifdef __windows__
144 #define DLL_EXPORT __declspec(dllexport) ///< declarator at definition
145 #define DLL_EXPORT_DECL C_DECLS __declspec(dllexport) ///< at declaration
146 #else
147 #define DLL_EXPORT ///< declarator at definition
148 #define DLL_EXPORT_DECL C_DECLS ///< declarator at declaration
149 #endif // __windows__
150 
151 //
152 // Header defined inline function declaration
153 //
154 #ifdef __cplusplus
155 #define INLINE_IN_H C_DECLS inline ///< inline C funtion in C++ header
156 #else
157 #define INLINE_IN_H C_DECLS static inline ///< inline C funtion in C header
158 #endif // __cplusplus
159 
160 //
161 // Basic types (ifdef by architecture to fit into these types if needed)
162 //
163 
164 // explicit
165 typedef __int8_t s8_t; ///< 8-bit signed integer
166 typedef __uint8_t u8_t; ///< 8-bit unsigned integer
167 typedef __int16_t s16_t; ///< 16-bit signed integer
168 typedef __uint16_t u16_t; ///< 16-bit unsigned integer
169 typedef __int32_t s32_t; ///< 32-bit signed integer
170 typedef __uint32_t u32_t; ///< 32-bit unsigned integer
171 typedef __int64_t s64_t; ///< 64-bit signed integer
172 typedef __uint64_t u64_t; ///< 64-bit unsigned integer
173 typedef float f32_t; ///< 32-bit floating-point number
174 typedef double f64_t; ///< 64-bit floating-point number
175 
176 // symbolic
177 typedef u8_t byte_t; ///< 8-bit byte
178 typedef s8_t schar_t; ///< 8-bit signed integer
179 typedef u16_t ushort_t; ///< 16-bit unsigned integer
180 typedef s16_t sshort_t; ///< 16-bit signed integer
181 typedef u32_t uint_t; ///< 32-bit unsigned integer
182 typedef s32_t sint_t; ///< 32-bit signed integer
183 typedef unsigned long ulong_t; ///< 32/64-bit unsigned long
184 typedef signed long slong_t; ///< 32/64-bit signed long
185 typedef u64_t ulonglong_t; ///< 64-bit unsigned long long integer
186 typedef s64_t slonglong_t; ///< 64-bit signed long long integer
187 typedef int bool_t; ///< "boolean" T/F
188 
189 #ifndef __cplusplus
190 #ifndef true
191 #define true (bool_t)1 ///< (if only it were) true
192 #endif
193 #ifndef false
194 #define false (bool_t)0 ///< (never to thy self be) false
195 #endif
196 #endif // __cplusplus
197 
198 #ifndef NULL
199 #define NULL ((void *)0) ///< null pointer
200 #endif
201 
202 //
203 // Sizes
204 //
205 
206 #ifndef MAX_LINE
207 #define MAX_LINE 2048
208 ///< Maximum bytes of input line (including NULL)
209 #endif
210 
211 #ifndef MAX_PATH
212 #define MAX_PATH 1024
213 ///< Maximum bytes of a fully qualified, absolute file name (including NULL)
214 #endif
215 
216 #ifndef MAX_BASENAME
217 #define MAX_BASENAME 256
218 ///< Maximum bytes of a file basename of path component (including NULL)
219 #endif
220 
221 #ifndef MAX_SEARCH_PATH
222 #define MAX_SEARCH_PATH 4096
223 ///< Maximum bytes of a PATH_SEP separated search path string (including NULL)
224 #endif
225 
226 //
227 // File
228 //
229 #ifndef FILE_SEP
230 #if defined(__windows__)
231 #define PATH_SEP_CHAR ';' ///< path separator (char version)
232 #define PATH_SEP_STR ";" ///< path separator (string version)
233 #define DIR_SEP_CHAR '\\' ///< directory component separator (char version)
234 #define DIR_SEP_STR "\\" ///< directory component separator (string version)
235 #else
236 #define PATH_SEP_CHAR ':' ///< path separator (char version)
237 #define PATH_SEP_STR ":" ///< path separator (string version)
238 #define DIR_SEP_CHAR '/' ///< directory component separator (char version)
239 #define DIR_SEP_STR "/" ///< directory component separator (string version)
240 #endif // __windows__
241 #define FILE_SEP ///< file separator group define
242 #endif // FILE_SEP
243 
244 //
245 // Current function name (keep literal)
246 // Note: Might be protability issues with this macro.
247 //
248 #define THISFUNCNAME __func__ ///< function name
249 
250 //
251 // Array Macros
252 //
253 
254 #ifndef arraysize
255 /*!
256  * \brief array size, i.e. number of array entries
257  * \param array the array to size
258  */
259 #define arraysize(array) (sizeof(array)/sizeof(array[0]))
260 #endif // arraysize
261 
262 //
263 // Structure Member Macros
264 //
265 
266 #ifndef member_defines
267 
268 /*!
269  * \brief structure member offset (bytes)
270  * \param structname structure name or typedef
271  * \param member structure member name
272  */
273 #define memberoffset(structname, member) (size_t)(&(((structname *)0)->member))
274 
275 /*!
276  * \brief member lvalue
277  * \param ctype lvalue type
278  * \param ptr pointer type
279  * \param offset byte offset from pointer
280  */
281 #define memberlvalue(ctype, ptr, offset) *((ctype *)(ptr + offset))
282 
283 /*!
284  * \brief member assignment
285  * \param ctype lvalue type
286  * \param ptr pointer type
287  * \param offset byte offset from pointer
288  * \param val value to assign lvalue.
289  */
290 #define memberassign(ctype, ptr, offset, val) \
291  memberlvalue(ctype, ptr, offset) = (ctype)val
292 
293 #define member_defines ///< member group defines
294 
295 #endif // member_defines
296 
297 //
298 // Simple Exit and Return codes
299 //
300 #ifndef OK
301 #define OK 0 ///< Okay
302 #endif
303 
304 // General error exit code
305 #ifndef EC_ERROR
306 #define EC_ERROR 4 ///< general error exit code
307 #endif
308 
309 // Bad command-line option exit code
310 #ifndef EC_BAD_OPT
311 #define EC_BAD_OPT 2 ///< bad command line option exit code
312 #endif
313 
314 // General function error return code
315 #ifndef RC_ERROR
316 #define RC_ERROR (-1) ///< common function error return code
317 #endif
318 
319 
320 //.............................................................................
321 // Compiler Pragmas
322 //.............................................................................
323 
324 /*!
325  * \brief CPP pragma macro.
326  *
327  * C99 introduces the _Pragma operator. Calling _Pragma("a b c") will produce
328  * \#pragma a b c
329  *
330  * \param x The pragma.
331  */
332 #if defined(_Pragma)
333 # define DO_PRAGMA(x) _Pragma(#x)
334 #else
335 # define DO_PRAGMA(x)
336 #endif
337 
338 /*!
339  * \brief CPP diagnostics pragma macro.
340  *
341  * \note The current Angstrom Arm GCC cross-compiler does not support
342  * diagnostics very well.
343  *
344  * \param x Unquoted front part of pragma
345  * \param y Qouted back part of pragma.
346  */
347 #ifndef ARCH_armang
348 #define PRAGMA_DIAG(x, y) DO_PRAGMA(x #y)
349 #else
350 #define PRAGMA_DIAG(x, y)
351 #endif
352 
353 /*!
354  * \brief Disable compiler warnings on the diagnostics filter.
355  *
356  * \sa "gcc --help=warnings" for list of filters.
357  */
358 #define PRAGMA_IGNORED(filter) PRAGMA_DIAG(GCC diagnostic ignored, -W ## filter)
359 
360 /*!
361  * \brief Enable compiler warnings on the diagnostics filter.
362  *
363  * \sa "gcc --help=warnings" for list of filters.
364  */
365 #define PRAGMA_WARNING(filter) PRAGMA_DIAG(GCC diagnostic warning, -W ## filter)
366 
367 /*!
368  * \brief Treat the diagnostics filter as a compiler error
369  *
370  * \sa "gcc --help=warnings" for list of filters.
371  */
372 #define PRAGMA_ERROR(filter) PRAGMA_DIAG(GCC diagnostic error, -W ## filter)
373 
374 
375 #endif // _RNRCONFIG_H
__int8_t s8_t
8-bit signed integer
Definition: rnrconfig.h:165
u64_t ulonglong_t
64-bit unsigned long long integer
Definition: rnrconfig.h:185
s32_t sint_t
32-bit signed integer
Definition: rnrconfig.h:182
unsigned long ulong_t
32/64-bit unsigned long
Definition: rnrconfig.h:183
__uint16_t u16_t
16-bit unsigned integer
Definition: rnrconfig.h:168
u32_t uint_t
32-bit unsigned integer
Definition: rnrconfig.h:181
double f64_t
64-bit floating-point number
Definition: rnrconfig.h:174
float f32_t
32-bit floating-point number
Definition: rnrconfig.h:173
signed long slong_t
32/64-bit signed long
Definition: rnrconfig.h:184
__uint8_t u8_t
8-bit unsigned integer
Definition: rnrconfig.h:166
s16_t sshort_t
16-bit signed integer
Definition: rnrconfig.h:180
int bool_t
"boolean" T/F
Definition: rnrconfig.h:187
__uint32_t u32_t
32-bit unsigned integer
Definition: rnrconfig.h:170
u8_t byte_t
8-bit byte
Definition: rnrconfig.h:177
__int64_t s64_t
64-bit signed integer
Definition: rnrconfig.h:171
__uint64_t u64_t
64-bit unsigned integer
Definition: rnrconfig.h:172
__int16_t s16_t
16-bit signed integer
Definition: rnrconfig.h:167
s8_t schar_t
8-bit signed integer
Definition: rnrconfig.h:178
u16_t ushort_t
16-bit unsigned integer
Definition: rnrconfig.h:179
s64_t slonglong_t
64-bit signed long long integer
Definition: rnrconfig.h:186
__int32_t s32_t
32-bit signed integer
Definition: rnrconfig.h:169