1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef BASE_DETECT_H
4#define BASE_DETECT_H
5
6/*
7 this file detected the family, platform and architecture
8 to compile for.
9*/
10
11/* platforms */
12
13/* windows Family */
14#if defined(WIN64) || defined(_WIN64)
15/* Hmm, is this IA64 or x86-64? */
16#define CONF_FAMILY_WINDOWS 1
17#define CONF_FAMILY_STRING "windows"
18#define CONF_PLATFORM_WIN64 1
19#define PLATFORM_STRING "win64"
20#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
21#define CONF_FAMILY_WINDOWS 1
22#define CONF_FAMILY_STRING "windows"
23#define CONF_PLATFORM_WIN32 1
24#define PLATFORM_STRING "win32"
25#endif
26
27/* unix family */
28#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
29#define CONF_FAMILY_UNIX 1
30#define CONF_FAMILY_STRING "unix"
31#define CONF_PLATFORM_FREEBSD 1
32#define PLATFORM_STRING "freebsd"
33#endif
34
35#if defined(__NetBSD__)
36#define CONF_FAMILY_UNIX 1
37#define CONF_FAMILY_STRING "unix"
38#define CONF_PLATFORM_NETBSD 1
39#define PLATFORM_STRING "netbsd"
40#endif
41
42#if defined(__OpenBSD__)
43#define CONF_FAMILY_UNIX 1
44#define CONF_FAMILY_STRING "unix"
45#define CONF_PLATFORM_OPENBSD 1
46#define PLATFORM_STRING "openbsd"
47#endif
48
49#if(defined(__LINUX__) || defined(__linux__) || defined(CONF_WEBASM)) && !defined(__ANDROID__)
50#define CONF_FAMILY_UNIX 1
51#define CONF_FAMILY_STRING "unix"
52#define CONF_PLATFORM_LINUX 1
53#define PLATFORM_STRING "linux"
54#define CONF_BACKEND_OPENGL_ES3 1
55#ifdef CONF_WEBASM
56// GLES only
57#define CONF_BACKEND_OPENGL_ES 1
58#endif
59#endif
60
61#if defined(__ANDROID__)
62#define CONF_FAMILY_UNIX 1
63#define CONF_FAMILY_STRING "unix"
64#define CONF_PLATFORM_ANDROID 1
65#define PLATFORM_STRING "android"
66#define CONF_BACKEND_OPENGL_ES 1
67#define CONF_BACKEND_OPENGL_ES3 1
68#endif
69
70#if defined(__GNU__) || defined(__gnu__)
71#define CONF_FAMILY_UNIX 1
72#define CONF_FAMILY_STRING "unix"
73#define CONF_PLATFORM_HURD 1
74#define PLATFORM_STRING "gnu"
75#endif
76
77#if defined(MACOSX) || defined(__APPLE__) || defined(__DARWIN__)
78#define CONF_FAMILY_UNIX 1
79#define CONF_FAMILY_STRING "unix"
80#define CONF_PLATFORM_MACOS 1
81#define PLATFORM_STRING "macos"
82#endif
83
84#if defined(__sun)
85#define CONF_FAMILY_UNIX 1
86#define CONF_FAMILY_STRING "unix"
87#define CONF_PLATFORM_SOLARIS 1
88#define PLATFORM_STRING "solaris"
89#endif
90
91/* beos family */
92#if defined(__BeOS) || defined(__BEOS__)
93#define CONF_FAMILY_BEOS 1
94#define CONF_FAMILY_STRING "beos"
95#define CONF_PLATFORM_BEOS 1
96#define PLATFORM_STRING "beos"
97#endif
98
99#if defined(__HAIKU__)
100#define CONF_FAMILY_UNIX 1
101#define CONF_FAMILY_STRING "unix"
102#define CONF_PLATFORM_HAIKU 1
103#define PLATFORM_STRING "haiku"
104#endif
105
106/* use gcc endianness definitions when available */
107#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__MINGW32__) && !defined(__sun)
108#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
109#include <sys/endian.h>
110#else
111#include <endian.h>
112#endif
113
114#if __BYTE_ORDER == __LITTLE_ENDIAN
115#define CONF_ARCH_ENDIAN_LITTLE 1
116#elif __BYTE_ORDER == __BIG_ENDIAN
117#define CONF_ARCH_ENDIAN_BIG 1
118#endif
119#endif
120
121/* architectures */
122#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(CONF_PLATFORM_WIN32)
123#define CONF_ARCH_IA32 1
124#define CONF_ARCH_STRING "ia32"
125#if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG)
126#define CONF_ARCH_ENDIAN_LITTLE 1
127#endif
128#endif
129
130#if defined(__ia64__) || defined(_M_IA64)
131#define CONF_ARCH_IA64 1
132#define CONF_ARCH_STRING "ia64"
133#if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG)
134#define CONF_ARCH_ENDIAN_LITTLE 1
135#endif
136#endif
137
138#if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64)
139#define CONF_ARCH_AMD64 1
140#define CONF_ARCH_STRING "amd64"
141#if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG)
142#define CONF_ARCH_ENDIAN_LITTLE 1
143#endif
144#endif
145
146#if defined(__powerpc__) || defined(__ppc__)
147#define CONF_ARCH_PPC 1
148#define CONF_ARCH_STRING "ppc"
149#if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG)
150#define CONF_ARCH_ENDIAN_BIG 1
151#endif
152#endif
153
154#if defined(__sparc__)
155#define CONF_ARCH_SPARC 1
156#define CONF_ARCH_STRING "sparc"
157#if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG)
158#define CONF_ARCH_ENDIAN_BIG 1
159#endif
160#endif
161
162#if defined(__ARMEB__)
163#define CONF_ARCH_ARM 1
164#define CONF_ARCH_STRING "arm"
165#define CONF_ARCH_ENDIAN_BIG 1
166#endif
167
168#if defined(__ARMEL__)
169#define CONF_ARCH_ARM 1
170#define CONF_ARCH_STRING "arm"
171#define CONF_ARCH_ENDIAN_LITTLE 1
172#endif
173
174#if defined(__aarch64__) || defined(__arm64__)
175#define CONF_ARCH_ARM64 1
176#define CONF_ARCH_STRING "arm64"
177#define CONF_ARCH_ENDIAN_LITTLE 1
178#endif
179
180#ifndef CONF_FAMILY_STRING
181#define CONF_FAMILY_STRING "unknown"
182#endif
183
184#ifndef PLATFORM_STRING
185#define PLATFORM_STRING "unknown"
186#endif
187
188#ifndef PLATFORM_SUFFIX
189#define PLATFORM_SUFFIX ""
190#endif
191
192#define CONF_PLATFORM_STRING PLATFORM_STRING PLATFORM_SUFFIX
193
194#ifndef CONF_ARCH_STRING
195#define CONF_ARCH_STRING "unknown"
196#endif
197
198#if defined(CONF_ARCH_ENDIAN_LITTLE)
199#define CONF_ARCH_ENDIAN_STRING "little endian"
200#elif defined(CONF_ARCH_ENDIAN_BIG)
201#define CONF_ARCH_ENDIAN_STRING "big endian"
202#else
203#error "Unsupported endianness"
204#endif
205
206#endif
207