| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef __Q_PLATFORM_H |
| 24 |
#define __Q_PLATFORM_H |
| 25 |
|
| 26 |
// this is for determining if we have an asm version of a C function |
| 27 |
#ifdef Q3_VM |
| 28 |
|
| 29 |
#define id386 0 |
| 30 |
#define idppc 0 |
| 31 |
#define idppc_altivec 0 |
| 32 |
|
| 33 |
#else |
| 34 |
|
| 35 |
#if (defined _M_IX86 || defined __i386__) && !defined(C_ONLY) |
| 36 |
#define id386 1 |
| 37 |
#else |
| 38 |
#define id386 0 |
| 39 |
#endif |
| 40 |
|
| 41 |
#if (defined(powerc) || defined(powerpc) || defined(ppc) || \ |
| 42 |
defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY) |
| 43 |
#define idppc 1 |
| 44 |
#if defined(__VEC__) |
| 45 |
#define idppc_altivec 1 |
| 46 |
#ifdef MACOS_X // Apple's GCC does this differently than the FSF. |
| 47 |
#define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ |
| 48 |
(vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) |
| 49 |
#else |
| 50 |
#define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ |
| 51 |
(vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p} |
| 52 |
#endif |
| 53 |
#else |
| 54 |
#define idppc_altivec 0 |
| 55 |
#endif |
| 56 |
#else |
| 57 |
#define idppc 0 |
| 58 |
#define idppc_altivec 0 |
| 59 |
#endif |
| 60 |
|
| 61 |
#endif |
| 62 |
|
| 63 |
#ifndef __ASM_I386__ // don't include the C bits if included from qasm.h |
| 64 |
|
| 65 |
// for windows fastcall option |
| 66 |
#define QDECL |
| 67 |
|
| 68 |
//================================================================= WIN32 === |
| 69 |
|
| 70 |
#ifdef __MINGW32__ |
| 71 |
|
| 72 |
#undef QDECL |
| 73 |
#define QDECL __cdecl |
| 74 |
|
| 75 |
#if defined( _MSC_VER ) |
| 76 |
#define OS_STRING "win_msvc" |
| 77 |
#elif defined __MINGW32__ |
| 78 |
#define OS_STRING "win_mingw" |
| 79 |
#endif |
| 80 |
|
| 81 |
#define ID_INLINE __inline |
| 82 |
#define PATH_SEP '\\' |
| 83 |
|
| 84 |
#if defined( _M_IX86 ) || defined( __i386__ ) |
| 85 |
#define ARCH_STRING "x86" |
| 86 |
#elif defined _M_ALPHA |
| 87 |
#define ARCH_STRING "AXP" |
| 88 |
#endif |
| 89 |
|
| 90 |
#define Q3_LITTLE_ENDIAN |
| 91 |
|
| 92 |
#define DLL_EXT ".dll" |
| 93 |
|
| 94 |
#endif |
| 95 |
|
| 96 |
//KK-OAX, This is a little hack to be able to build dll's for debugging under Visual Studio |
| 97 |
//Simple copy/paste/rename of the #ifdef __MINGW32__ |
| 98 |
#ifdef VSTUDIO |
| 99 |
|
| 100 |
#undef QDECL |
| 101 |
#define QDECL __cdecl |
| 102 |
|
| 103 |
#if defined( _MSC_VER ) |
| 104 |
#define OS_STRING "win_msvc" |
| 105 |
#elif defined __MINGW32__ |
| 106 |
#define OS_STRING "win_mingw" |
| 107 |
#endif |
| 108 |
|
| 109 |
#define ID_INLINE __inline |
| 110 |
#define PATH_SEP '\\' |
| 111 |
|
| 112 |
#if defined( _M_IX86 ) || defined( __i386__ ) |
| 113 |
#define ARCH_STRING "x86" |
| 114 |
#elif defined _M_ALPHA |
| 115 |
#define ARCH_STRING "AXP" |
| 116 |
#endif |
| 117 |
|
| 118 |
#define Q3_LITTLE_ENDIAN |
| 119 |
|
| 120 |
#define DLL_EXT ".dll" |
| 121 |
|
| 122 |
#endif |
| 123 |
//============================================================== MAC OS X === |
| 124 |
|
| 125 |
#if defined(MACOS_X) || defined(__APPLE_CC__) |
| 126 |
|
| 127 |
// make sure this is defined, just for sanity's sake... |
| 128 |
#ifndef MACOS_X |
| 129 |
#define MACOS_X |
| 130 |
#endif |
| 131 |
|
| 132 |
#define OS_STRING "macosx" |
| 133 |
#define ID_INLINE inline |
| 134 |
#define PATH_SEP '/' |
| 135 |
|
| 136 |
#ifdef __ppc__ |
| 137 |
#define ARCH_STRING "ppc" |
| 138 |
#define Q3_BIG_ENDIAN |
| 139 |
#elif defined __i386__ |
| 140 |
#define ARCH_STRING "i386" |
| 141 |
#define Q3_LITTLE_ENDIAN |
| 142 |
#endif |
| 143 |
|
| 144 |
#define DLL_EXT ".dylib" |
| 145 |
|
| 146 |
#endif |
| 147 |
|
| 148 |
//================================================================= LINUX === |
| 149 |
|
| 150 |
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__) |
| 151 |
|
| 152 |
#include <endian.h> |
| 153 |
|
| 154 |
#if defined(__linux__) |
| 155 |
#define OS_STRING "linux" |
| 156 |
#elif defined(__FreeBSD_kernel__) |
| 157 |
#define OS_STRING "kFreeBSD" |
| 158 |
#else |
| 159 |
#define OS_STRING "GNU" |
| 160 |
#endif |
| 161 |
|
| 162 |
#define ID_INLINE inline |
| 163 |
#define PATH_SEP '/' |
| 164 |
|
| 165 |
#if !defined(ARCH_STRING) |
| 166 |
# error ARCH_STRING should be defined by the Makefile |
| 167 |
#endif |
| 168 |
|
| 169 |
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN |
| 170 |
#define Q3_BIG_ENDIAN |
| 171 |
#else |
| 172 |
#define Q3_LITTLE_ENDIAN |
| 173 |
#endif |
| 174 |
|
| 175 |
#define DLL_EXT ".so" |
| 176 |
|
| 177 |
#endif |
| 178 |
|
| 179 |
//=================================================================== BSD === |
| 180 |
|
| 181 |
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) |
| 182 |
|
| 183 |
#include <sys/types.h> |
| 184 |
#include <machine/endian.h> |
| 185 |
|
| 186 |
#ifndef __BSD__ |
| 187 |
#define __BSD__ |
| 188 |
#endif |
| 189 |
|
| 190 |
#if defined(__FreeBSD__) |
| 191 |
#define OS_STRING "freebsd" |
| 192 |
#elif defined(__OpenBSD__) |
| 193 |
#define OS_STRING "openbsd" |
| 194 |
#elif defined(__NetBSD__) |
| 195 |
#define OS_STRING "netbsd" |
| 196 |
#endif |
| 197 |
|
| 198 |
#define ID_INLINE inline |
| 199 |
#define PATH_SEP '/' |
| 200 |
|
| 201 |
#ifdef __i386__ |
| 202 |
#define ARCH_STRING "i386" |
| 203 |
#elif defined __axp__ |
| 204 |
#define ARCH_STRING "alpha" |
| 205 |
#endif |
| 206 |
|
| 207 |
#if BYTE_ORDER == BIG_ENDIAN |
| 208 |
#define Q3_BIG_ENDIAN |
| 209 |
#else |
| 210 |
#define Q3_LITTLE_ENDIAN |
| 211 |
#endif |
| 212 |
|
| 213 |
#define DLL_EXT ".so" |
| 214 |
|
| 215 |
#endif |
| 216 |
|
| 217 |
//================================================================= SUNOS === |
| 218 |
|
| 219 |
#ifdef __sun |
| 220 |
|
| 221 |
#include <stdint.h> |
| 222 |
#include <sys/byteorder.h> |
| 223 |
|
| 224 |
#define OS_STRING "solaris" |
| 225 |
#define ID_INLINE inline |
| 226 |
#define PATH_SEP '/' |
| 227 |
|
| 228 |
#ifdef __i386__ |
| 229 |
#define ARCH_STRING "i386" |
| 230 |
#elif defined __sparc |
| 231 |
#define ARCH_STRING "sparc" |
| 232 |
#endif |
| 233 |
|
| 234 |
#if defined( _BIG_ENDIAN ) |
| 235 |
#define Q3_BIG_ENDIAN |
| 236 |
#elif defined( _LITTLE_ENDIAN ) |
| 237 |
#define Q3_LITTLE_ENDIAN |
| 238 |
#endif |
| 239 |
|
| 240 |
#define DLL_EXT ".so" |
| 241 |
|
| 242 |
#endif |
| 243 |
|
| 244 |
//================================================================== IRIX === |
| 245 |
|
| 246 |
#ifdef __sgi |
| 247 |
|
| 248 |
#define OS_STRING "irix" |
| 249 |
#define ID_INLINE __inline |
| 250 |
#define PATH_SEP '/' |
| 251 |
|
| 252 |
#define ARCH_STRING "mips" |
| 253 |
|
| 254 |
#define Q3_BIG_ENDIAN // SGI's MIPS are always big endian |
| 255 |
|
| 256 |
#define DLL_EXT ".so" |
| 257 |
|
| 258 |
#endif |
| 259 |
|
| 260 |
//================================================================== Q3VM === |
| 261 |
|
| 262 |
#ifdef Q3_VM |
| 263 |
|
| 264 |
#define OS_STRING "q3vm" |
| 265 |
#define ID_INLINE |
| 266 |
#define PATH_SEP '/' |
| 267 |
|
| 268 |
#define ARCH_STRING "bytecode" |
| 269 |
|
| 270 |
#define DLL_EXT ".qvm" |
| 271 |
|
| 272 |
#endif |
| 273 |
|
| 274 |
//=========================================================================== |
| 275 |
|
| 276 |
//catch missing defines in above blocks |
| 277 |
#if !defined( OS_STRING ) |
| 278 |
#error "Operating system not supported" |
| 279 |
#endif |
| 280 |
|
| 281 |
#if !defined( ARCH_STRING ) |
| 282 |
#error "Architecture not supported" |
| 283 |
#endif |
| 284 |
|
| 285 |
#ifndef ID_INLINE |
| 286 |
#error "ID_INLINE not defined" |
| 287 |
#endif |
| 288 |
|
| 289 |
#ifndef PATH_SEP |
| 290 |
#error "PATH_SEP not defined" |
| 291 |
#endif |
| 292 |
|
| 293 |
#ifndef DLL_EXT |
| 294 |
#error "DLL_EXT not defined" |
| 295 |
#endif |
| 296 |
|
| 297 |
|
| 298 |
//endianness |
| 299 |
short ShortSwap (short l); |
| 300 |
int LongSwap (int l); |
| 301 |
float FloatSwap (const float *f); |
| 302 |
|
| 303 |
#if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN ) |
| 304 |
#error "Endianness defined as both big and little" |
| 305 |
#elif defined( Q3_BIG_ENDIAN ) |
| 306 |
|
| 307 |
#define LittleShort(x) ShortSwap(x) |
| 308 |
#define LittleLong(x) LongSwap(x) |
| 309 |
#define LittleFloat(x) FloatSwap(&x) |
| 310 |
#define BigShort |
| 311 |
#define BigLong |
| 312 |
#define BigFloat |
| 313 |
|
| 314 |
#elif defined( Q3_LITTLE_ENDIAN ) |
| 315 |
|
| 316 |
#define LittleShort |
| 317 |
#define LittleLong |
| 318 |
#define LittleFloat |
| 319 |
#define BigShort(x) ShortSwap(x) |
| 320 |
#define BigLong(x) LongSwap(x) |
| 321 |
#define BigFloat(x) FloatSwap(&x) |
| 322 |
|
| 323 |
#elif defined( Q3_VM ) |
| 324 |
|
| 325 |
#define LittleShort |
| 326 |
#define LittleLong |
| 327 |
#define LittleFloat |
| 328 |
#define BigShort |
| 329 |
#define BigLong |
| 330 |
#define BigFloat |
| 331 |
|
| 332 |
#else |
| 333 |
#error "Endianness not defined" |
| 334 |
#endif |
| 335 |
|
| 336 |
|
| 337 |
//platform string |
| 338 |
#ifdef NDEBUG |
| 339 |
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING |
| 340 |
#else |
| 341 |
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug" |
| 342 |
#endif |
| 343 |
|
| 344 |
#endif |
| 345 |
|
| 346 |
#endif |