Merge pull request #2796 from jimklimov/fix-docs-markup
[networkupstools.git] / include / nut_platform.h
blob90237d260036bdc8174fa406e0068ae4d5907aa0
1 /**
2 * \brief Platform-specific checks
4 * The header performs checks to resolve the actual build platform.
5 * It defines macra that may be later used to produce platform-tailored
6 * code.
8 * Be careful when writing platform-specific code; avoid that if possible.
10 * References:
11 * http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
13 * \author Vaclav Krpec <VaclavKrpec@Eaton.com>
14 * \date 2012/10/12
17 #ifndef NUT_PLATFORM_H_SEEN
18 #define NUT_PLATFORM_H_SEEN 1
21 * In case doxygen source doc isn't generated
22 * (which is the case at time of writing this),
23 * just check the doxygen-documented (i.e. "**"
24 * prefixed) NUT_PLATFORM_* macra, below.
27 /* Apple Mac OS X, iOS and Darwin */
28 #if (defined __APPLE__ && defined __MACH__)
29 /** Apple OS based on Mach ukernel */
30 # define NUT_PLATFORM_APPLE_MACH
32 /* https://stackoverflow.com/a/2339910/4715872 */
33 # ifndef SOEXT
34 # define SOEXT ".dylib"
35 # endif
37 # include <TargetConditionals.h>
39 # if (defined TARGET_OS_EMBEDDED)
40 /** iOS (implies \ref NUT_PLATFORM_APPLE_MACH) */
41 # define NUT_PLATFORM_APPLE_IOS
42 # endif
43 # if (defined TARGET_IPHONE_SIMULATOR)
44 /** iOS simulator (implies \ref NUT_PLATFORM_APPLE_MACH) */
45 # define NUT_PLATFORM_APPLE_IOS_SIMULATOR
46 # endif
47 # if (defined TARGET_OS_IPHONE)
48 /** iPhone (implies \ref NUT_PLATFORM_APPLE_MACH) */
49 # define NUT_PLATFORM_APPLE_IPHONE
50 # endif
51 # if (defined TARGET_OS_MAC)
52 /** Mac OS X (implies \ref NUT_PLATFORM_APPLE_MACH) */
53 # define NUT_PLATFORM_APPLE_OSX
54 # endif
55 #endif
58 * GCC AIX issue: __unix__ nor __unix are not defined in older GCC
59 * Addressed in GCC 4.7.0, see
60 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39950
61 * Remove if no longer necessary
63 #if (defined _AIX && !defined __unix__)
64 # define __unix__
65 #endif
67 /* Microsoft Windows */
68 #if (defined _WIN32 || defined _WIN64)
69 /** Windows */
70 # define NUT_PLATFORM_MS_WINDOWS
72 # ifndef SOEXT
73 # define SOEXT ".dll"
74 # endif
76 # if (defined NTDDI_WIN8 && NTDDI_VERSION >= NTDDI_WIN8)
77 /** Windows 8 */
78 # define NUT_PLATFORM_MS_WINDOWS8
79 # endif
81 /* UNIX */
82 /* Note that Apple OSX doesn't define __unix__ nor __unix; are they ashamed or something? */
83 #elif (defined __unix__ || defined __unix || defined NUT_PLATFORM_APPLE_MACH)
84 # include <sys/param.h>
85 # include <unistd.h>
87 /** UNIX */
88 # define NUT_PLATFORM_UNIX
90 # if (defined _POSIX_VERSION)
91 /** POSIX (implies \ref NUT_PLATFORM_UNIX), expands to POSIX version */
92 # define NUT_PLATFORM_POSIX _POSIX_VERSION
93 # endif
95 # if (defined __linux__)
96 /** Linux (implies \ref NUT_PLATFORM_UNIX) */
97 # define NUT_PLATFORM_LINUX
98 # endif
99 # if (defined __sun && defined __SVR4)
100 /** Solaris (implies \ref NUT_PLATFORM_UNIX) */
101 # define NUT_PLATFORM_SOLARIS
102 # endif
103 # if (defined __hpux)
104 /** Hewlett-Packard HP-UX (implies \ref NUT_PLATFORM_UNIX) */
105 # define NUT_PLATFORM_HPUX
107 /* Note: depending on CPU arch and OS version, library file
108 * name patterns here could have been "*.so" as well.
109 * E.g. per
110 * https://community.hpe.com/t5/operating-system-hp-ux/so-and-sl-files/td-p/3780528
111 * *.sl are used in PA-RISC (11.11)
112 * *.so shared libraries are used in HP-UX 11.20 and upwards.
113 * Integrity (Itanium-based) HPUX can use *.sl as well,
114 * but it is not recommended, see ld(1) under -lx:
115 * https://web.archive.org/web/20090925153446/http://docs.hp.com/en/B2355-60103/ld.1.html
117 /* FIXME: May want to detect better the CPU or OS version
118 * to decide the SOEXT here*/
119 # ifndef SOEXT
120 # define SOEXT ".sl"
121 # endif
122 # endif
123 # if (defined _AIX)
124 /** AIX (implies \ref NUT_PLATFORM_UNIX) */
125 # define NUT_PLATFORM_AIX
126 # endif
128 /* Note that BSD is defined in sys/param.h */
129 # if (defined BSD)
130 /** BSD (implies \ref NUT_PLATFORM_UNIX) */
131 # define NUT_PLATFORM_BSD
133 # if (defined __DragonFly__)
134 /** DragonFly (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */
135 # define NUT_PLATFORM_DRAGONFLY
136 # elif (defined __FreeBSD__)
137 /** FreeBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */
138 # define NUT_PLATFORM_FREEBSD
139 # elif (defined __OpenBSD__)
140 /** OpenBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */
141 # define NUT_PLATFORM_OPENBSD
142 # elif (defined __NetBSD__)
143 /** NetBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */
144 # define NUT_PLATFORM_NETBSD
145 # endif
146 # endif
147 #endif
149 /* not WIN32, not MACOS, not HPUX... */
150 #ifndef SOEXT
151 # define SOEXT ".so"
152 #endif
154 #endif /* NUT_PLATFORM_H_SEEN */