|
| 1 | +// |
| 2 | +// Eden.h |
| 3 | +// |
| 4 | +// Compiler and platform specific constants, needed for entire projects. |
| 5 | +// This file should be included with the project as a prefix header |
| 6 | +// (i.e., implicitly included from every source file.) |
| 7 | +// |
| 8 | +// Copyright (c) 2001-2016 Philip Lamb (PRL) phil@eden.net.nz. All rights reserved. |
| 9 | +// |
| 10 | +// |
| 11 | + |
| 12 | +// @@BEGIN_EDEN_LICENSE_HEADER@@ |
| 13 | +// |
| 14 | +// This file is part of The Eden Library. |
| 15 | +// |
| 16 | +// The Eden Library is free software: you can redistribute it and/or modify |
| 17 | +// it under the terms of the GNU Lesser General Public License as published by |
| 18 | +// the Free Software Foundation, either version 3 of the License, or |
| 19 | +// (at your option) any later version. |
| 20 | +// |
| 21 | +// The Eden Library is distributed in the hope that it will be useful, |
| 22 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | +// GNU Lesser General Public License for more details. |
| 25 | +// |
| 26 | +// You should have received a copy of the GNU Lesser General Public License |
| 27 | +// along with The Eden Library. If not, see <http://www.gnu.org/licenses/>. |
| 28 | +// |
| 29 | +// As a special exception, the copyright holders of this library give you |
| 30 | +// permission to link this library with independent modules to produce an |
| 31 | +// executable, regardless of the license terms of these independent modules, and to |
| 32 | +// copy and distribute the resulting executable under terms of your choice, |
| 33 | +// provided that you also meet, for each linked independent module, the terms and |
| 34 | +// conditions of the license of that module. An independent module is a module |
| 35 | +// which is neither derived from nor based on this library. If you modify this |
| 36 | +// library, you may extend this exception to your version of the library, but you |
| 37 | +// are not obligated to do so. If you do not wish to do so, delete this exception |
| 38 | +// statement from your version. |
| 39 | +// |
| 40 | +// @@END_EDEN_LICENSE_HEADER@@ |
| 41 | + |
| 42 | +#ifndef __Eden_h__ |
| 43 | +#define __Eden_h__ |
| 44 | + |
| 45 | +// |
| 46 | +// Keep it simple: define compiler, platform and architecture capabilities here |
| 47 | +// rather than using a configure script. |
| 48 | +// |
| 49 | + |
| 50 | +#include <stdio.h> |
| 51 | +#ifndef _WIN32 // errno is defined in stdlib.h on Windows. |
| 52 | +# include <sys/errno.h> |
| 53 | +#endif |
| 54 | +#ifdef __ANDROID__ |
| 55 | +# include <android/log.h> |
| 56 | +#endif |
| 57 | + |
| 58 | +#ifdef __cplusplus |
| 59 | +extern "C" { |
| 60 | +#endif |
| 61 | + |
| 62 | +#ifdef __ANDROID__ |
| 63 | +# define EDEN_LOG(...) __android_log_print(ANDROID_LOG_INFO, "libeden", __VA_ARGS__); |
| 64 | +# define EDEN_LOGe(...) __android_log_print(ANDROID_LOG_ERROR, "libeden", __VA_ARGS__); |
| 65 | +# define EDEN_LOGperror(s) __android_log_print(ANDROID_LOG_ERROR, "libeden", (s ? "%s: %s\n" : "%s%s\n"), (s ? s : ""), strerror(errno)) |
| 66 | +#else |
| 67 | +# define EDEN_LOG(...) printf(__VA_ARGS__) |
| 68 | +# define EDEN_LOGe(...) fprintf(stderr, __VA_ARGS__) |
| 69 | +# define EDEN_LOGperror(s) fprintf(stderr, (s ? "%s: %s\n" : "%s%s\n"), (s ? s : ""), strerror(errno)) |
| 70 | +#endif |
| 71 | + |
| 72 | +// Check architecture endianess using gcc's macro, or assume little-endian by default. |
| 73 | +// Also, define attribute to produce a tightly packed structure (i.e. all structures |
| 74 | +// byte-aligned.) |
| 75 | +// I don't know how to do this in compilers other than GCC at the moment. |
| 76 | +#if defined(__GNUC__) |
| 77 | +# if defined(__BIG_ENDIAN__) |
| 78 | +# define EDEN_BIGENDIAN // Most Significant Byte has greatest address in memory. |
| 79 | +# endif |
| 80 | +# define EDEN_INLINE_H extern inline |
| 81 | +# define EDEN_INLINE_C |
| 82 | +# define EDEN_PACKED __attribute__ ((__packed__)) |
| 83 | +#else |
| 84 | +# define EDEN_PACKED |
| 85 | +#endif |
| 86 | + |
| 87 | +// GCC on Mac OS X. |
| 88 | +#if defined(__APPLE__) |
| 89 | +# define EDEN_UNIX |
| 90 | +# define EDEN_HAVE_PTHREAD_RELATIVE_TIMEDWAIT |
| 91 | +# include <TargetConditionals.h> |
| 92 | +# include <AvailabilityMacros.h> |
| 93 | +# if TARGET_RT_BIG_ENDIAN |
| 94 | +# define EDEN_BIGENDIAN // Most Significant Byte has greatest address in memory (ppc). |
| 95 | +# elif TARGET_RT_LITTLE_ENDIAN |
| 96 | +# undef EDEN_BIGENDIAN |
| 97 | +# else |
| 98 | +# error |
| 99 | +# endif |
| 100 | + |
| 101 | +# if TARGET_OS_IPHONE |
| 102 | +# define EDEN_IPHONEOS |
| 103 | +# define EDEN_USE_GLES 1 |
| 104 | +# else |
| 105 | +# define EDEN_USE_GL 1 |
| 106 | +# endif |
| 107 | + |
| 108 | +# if !defined(DARWINONLY) && !TARGET_OS_IPHONE |
| 109 | +# define EDEN_MACOSX // Running under Mac OS X. |
| 110 | +//# define EDEN_HAVE_HID // Has HID API available (for joystick). |
| 111 | +//# define EDEN_HAVE_ARTOOLKIT |
| 112 | +# define EDEN_HAVE_MACOSX_CGL |
| 113 | +# if !defined(__LP64__) |
| 114 | +# define EDEN_HAVE_CARBON |
| 115 | +# endif |
| 116 | +# endif |
| 117 | + |
| 118 | +# define EDEN_HAVE_LIBJPEG |
| 119 | +# define EDEN_HAVE_OPENAL |
| 120 | + |
| 121 | +// GCC on Android (NDK) |
| 122 | +#elif defined(__ANDROID__) |
| 123 | +# define EDEN_UNIX |
| 124 | +# define EDEN_HAVE_LIBJPEG |
| 125 | +# ifndef ANDROID |
| 126 | +# define ANDROID |
| 127 | +# endif |
| 128 | +# define EDEN_USE_GLES 1 |
| 129 | + |
| 130 | +// GCC on Cygnus GNU for Windows. |
| 131 | +#elif defined(__CYGWIN__) |
| 132 | +# define EDEN_UNIX // Its a Unix system too! |
| 133 | +# define EDEN_SERIAL_POSIX_ONLY // Use only POSIX-compliant serial calls. |
| 134 | +# define EDEN_USE_GL 1 |
| 135 | + |
| 136 | +// GCC on Linux. |
| 137 | +#elif defined(__linux__) |
| 138 | +# define EDEN_UNIX // Its a Unix-like system. |
| 139 | +//# define EDEN_HAVE_ARTOOLKIT |
| 140 | +# define EDEN_USE_GL 1 |
| 141 | + |
| 142 | +// GCC on NetBSD. |
| 143 | +#elif defined(__NetBSD__) |
| 144 | +# define EDEN_UNIX |
| 145 | +# define EDEN_USE_GL 1 |
| 146 | + |
| 147 | +// Microsoft C++ on Windows. |
| 148 | +#elif defined(_MSC_VER) |
| 149 | +# include <windows.h> // Is this correct? |
| 150 | +# undef EDEN_BIGENDIAN // Least Significant Byte is highest in memory. |
| 151 | +# define EDEN_HAVE_LIBJPEG |
| 152 | +# define EDEN_HAVE_OPENAL |
| 153 | +//# define EDEN_HAVE_ARTOOLKIT |
| 154 | +# pragma warning (disable:4068) // Disable bogus unknown pragma warnings. |
| 155 | +# pragma warning (disable:4244) // Disable bogus conversion warnings. |
| 156 | +# pragma warning (disable:4305) // Disable bogus conversion warnings. |
| 157 | +# define EDEN_INLINE_H __inline |
| 158 | +# define EDEN_INLINE_C __inline |
| 159 | +# define EDEN_USE_GL 1 |
| 160 | + |
| 161 | +// Generic POSIX-compliant Unix. |
| 162 | +#elif defined(_POSIX) |
| 163 | +# define EDEN_UNIX |
| 164 | +# define EDEN_SERIAL_POSIX_ONLY // Use only POSIX-compliant serial calls. |
| 165 | +# define EDEN_INLINE_H |
| 166 | +# define EDEN_INLINE_C |
| 167 | +# define EDEN_USE_GL 1 |
| 168 | + |
| 169 | +#else |
| 170 | +# error Unrecognised compiler in __FILE__. |
| 171 | +#endif |
| 172 | + |
| 173 | + |
| 174 | +// |
| 175 | +// Application code which is dependent on platform capabilities. |
| 176 | +// |
| 177 | + |
| 178 | +// Features common to all our supported Unix platforms. |
| 179 | +#ifdef EDEN_UNIX |
| 180 | +# define EDEN_HAVE_STRINGS_H |
| 181 | +# define EDEN_HAVE_CTIME_R_IN_TIME_H |
| 182 | +#endif // EDEN_UNIX |
| 183 | + |
| 184 | +// |
| 185 | +// Miscellany. |
| 186 | +// |
| 187 | + |
| 188 | +// Use these definitions rather than those in <stdbool.h>. |
| 189 | +typedef int EDEN_BOOL; |
| 190 | +#define EDEN_BOOL_DEFINED |
| 191 | +#ifndef TRUE |
| 192 | +# define TRUE 1 |
| 193 | +#else |
| 194 | +# if (TRUE != 1) |
| 195 | +# error 'TRUE incorrectly defined somewhere other than __FILE__.' |
| 196 | +# endif |
| 197 | +#endif |
| 198 | +#ifndef FALSE |
| 199 | +# define FALSE 0 |
| 200 | +#else |
| 201 | +# if (FALSE != 0) |
| 202 | +# error 'FALSE incorrectly defined somewhere other than __FILE__.' |
| 203 | +# endif |
| 204 | +#endif |
| 205 | + |
| 206 | +// ASCII keycodes. |
| 207 | +#define EDEN_ASCII_ESC 27 |
| 208 | +#define EDEN_ASCII_TAB 9 |
| 209 | +#define EDEN_ASCII_BS 8 |
| 210 | +#define EDEN_ASCII_CR 13 |
| 211 | +#define EDEN_ASCII_DEL 127 |
| 212 | + |
| 213 | + |
| 214 | +#ifdef __cplusplus |
| 215 | +} |
| 216 | +#endif |
| 217 | + |
| 218 | +#endif // !__Eden_h__ |
| 219 | + |
0 commit comments