Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
os.h
Go to the documentation of this file.
1/* Copyright (C) 2012 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_WIN64 1
42#else
43# define OS_WIN64 0
44#endif
45#if defined(_WIN32)
46# define OS_WIN 1
47#else
48# define OS_WIN 0
49#endif
50// Linux
51#if defined(linux) || defined(__linux) || defined(__linux__)
52# define OS_LINUX 1
53#else
54# define OS_LINUX 0
55#endif
56// Android (subset of Linux)
57#if defined(__ANDROID__)
58# define OS_ANDROID 1
59#else
60# define OS_ANDROID 0
61#endif
62// Mac OS X
63#if (defined(__APPLE__) && defined(__MACH__))
64# define OS_MACOSX 1
65#else
66# define OS_MACOSX 0
67#endif
68// BSD
69#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)
70# define OS_BSD 1
71// OpenBSD has no aio.h and we need a way to disable it for it only
72# if defined(__OpenBSD__)
73# define OS_OPENBSD 1
74# endif
75#else
76# define OS_BSD 0
77#endif
78#ifndef OS_OPENBSD
79# define OS_OPENBSD 0
80#endif
81// Solaris
82#if defined(sun) || defined(__sun)
83# define OS_SOLARIS 1
84#else
85# define OS_SOLARIS 0
86#endif
87// BeOS
88#if defined(__BEOS__)
89# define OS_BEOS 1
90#else
91# define OS_BEOS 0
92#endif
93// Mac OS 9 or below
94#if defined(macintosh)
95# define OS_MAC 1
96#else
97# define OS_MAC 0
98#endif
99// Amiga
100#if defined(AMIGA)
101# define OS_AMIGA 1
102#else
103# define OS_AMIGA 0
104#endif
105// Unix-based
106#if defined(unix) || defined(__unix) || defined(__unix__) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE)
107# define OS_UNIX 1
108#else
109# define OS_UNIX 0
110#endif
111
112// convenience: additionally set OS_UNIX for Unix-based OSes
113// note: doing this in an separate section instead of adding the extra define
114// to all affected OSes saves a few undefs or macro redefinition warnings.
115#if OS_LINUX || OS_MACOSX || OS_BSD || OS_SOLARIS
116# undef OS_UNIX
117# define OS_UNIX 1
118#endif
119
120// convenience: additionally set OS_BSD for BSD-based OSes. see note above.
121#if OS_MACOSX
122# undef OS_BSD
123# define OS_BSD 1
124#endif
125
126#endif // #ifndef INCLUDED_OS