Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
os.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Wildfire Games.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/*
24 * OS-specific macros
25 */
26
27#ifndef INCLUDED_OS
28#define INCLUDED_OS
29
30// detect OS via predefined macros. rationale:
31// - these macros have consistent names and numerical values; using
32// them saves other code from having to know the obscure predefined macros.
33// - we'd like to use #if/#elif/#endif chains for e.g. OS_* to allow warning
34// if none is selected, but there's no good way to #define all inapplicable
35// settings to 0. doing so up front is hard to maintain and would require
36// #undef before setting any one to 1. #ifndef afterwards for each setting
37// is ugly and brittle as well. we therefore use #if/#else/#endif.
38
39// Windows
40#if defined(_WIN64)
41# define OS_WIN 1
42# define OS_WIN64 1
43#else
44# define OS_WIN64 0
45#if defined(_WIN32)
46# define OS_WIN 1
47#else
48# define OS_WIN 0
49#endif
50#endif
51// Linux
52#if defined(linux) || defined(__linux) || defined(__linux__)
53# define OS_LINUX 1
54#else
55# define OS_LINUX 0
56#endif
57// Android (subset of Linux)
58#if defined(__ANDROID__)
59# define OS_ANDROID 1
60#else
61# define OS_ANDROID 0
62#endif
63// Mac OS X
64#if (defined(__APPLE__) && defined(__MACH__))
65# define OS_MACOSX 1
66#else
67# define OS_MACOSX 0
68#endif
69// BSD
70#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)
71# define OS_BSD 1
72// OpenBSD has no aio.h and we need a way to disable it for it only
73# if defined(__OpenBSD__)
74# define OS_OPENBSD 1
75# endif
76#else
77# define OS_BSD 0
78#endif
79#ifndef OS_OPENBSD
80# define OS_OPENBSD 0
81#endif
82// Solaris
83#if defined(sun) || defined(__sun)
84# define OS_SOLARIS 1
85#else
86# define OS_SOLARIS 0
87#endif
88// BeOS
89#if defined(__BEOS__)
90# define OS_BEOS 1
91#else
92# define OS_BEOS 0
93#endif
94// Amiga
95#if defined(AMIGA)
96# define OS_AMIGA 1
97#else
98# define OS_AMIGA 0
99#endif
100// Unix-based
101#if defined(unix) || defined(__unix) || defined(__unix__) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE)
102# define OS_UNIX 1
103#else
104# define OS_UNIX 0
105#endif
106
107// convenience: additionally set OS_UNIX for Unix-based OSes
108// note: doing this in an separate section instead of adding the extra define
109// to all affected OSes saves a few undefs or macro redefinition warnings.
110#if OS_LINUX || OS_MACOSX || OS_BSD || OS_SOLARIS
111# undef OS_UNIX
112# define OS_UNIX 1
113#endif
114
115// convenience: additionally set OS_BSD for BSD-based OSes. see note above.
116#if OS_MACOSX
117# undef OS_BSD
118# define OS_BSD 1
119#endif
120
121#endif // #ifndef INCLUDED_OS