aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/defs.h
blob: ca12a80fd33a4be3d2a81409368eb6a24057ee83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef OSMOCORE_DEFS_H
#define OSMOCORE_DEFS_H

/*! \defgroup utils General-purpose utility functions
 *  @{
 */

/*! \file defs.h
 *  \brief General definitions that are meant to be included from header files.
 */

/*! \brief Check for gcc and version.
 *
 * \note Albeit glibc provides a features.h file that contains a similar
 *       definition (__GNUC_PREREQ), this definition has been copied from there
 *       to have it available with other libraries, too.
 *
 * \return != 0 iff gcc is used and it's version is at least maj.min.
 */
#if defined __GNUC__ && defined __GNUC_MINOR__
# define OSMO_GNUC_PREREQ(maj, min) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define OSMO_GNUC_PREREQ(maj, min) 0
#endif

/*! \brief Set the deprecated attribute with a message.
 */
#if defined(__clang__)
# if __has_attribute(deprecated)
#   define _OSMO_HAS_ATTRIBUTE_DEPRECATED 1
# endif
# if __has_extension(attribute_deprecated_with_message)
#   define _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE 1
# endif
#elif defined(__GNUC__)
# define _OSMO_HAS_ATTRIBUTE_DEPRECATED 1
# if OSMO_GNUC_PREREQ(4,5)
#   define _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE 1
# endif
#endif

#if defined(_OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE)
# define OSMO_DEPRECATED(text)  __attribute__((__deprecated__(text)))
#elif defined(_OSMO_HAS_ATTRIBUTE_DEPRECATED)
# define OSMO_DEPRECATED(text)  __attribute__((__deprecated__))
#else
# define OSMO_DEPRECATED(text)
#endif

#undef _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE
#undef _OSMO_HAS_ATTRIBUTE_DEPRECATED

/*! @} */

#endif