platform.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright (C) 2005-2012 Gekko Emulator
  3. *
  4. * @file platform.h
  5. * @author ShizZy <shizzy247@gmail.com>
  6. * @date 2012-02-11
  7. * @brief Platform detection macros for portable compilation
  8. *
  9. * @section LICENSE
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * Official project repository can be found at:
  22. * http://code.google.com/p/gekko-gc-emu/
  23. */
  24. #ifndef COMMON_PLATFORM_H_
  25. #define COMMON_PLATFORM_H_
  26. #include "common/common_types.h"
  27. ////////////////////////////////////////////////////////////////////////////////////////////////////
  28. // Platform definitions
  29. /// Enumeration for defining the supported platforms
  30. #define PLATFORM_NULL 0
  31. #define PLATFORM_WINDOWS 1
  32. #define PLATFORM_MACOSX 2
  33. #define PLATFORM_LINUX 3
  34. #define PLATFORM_ANDROID 4
  35. #define PLATFORM_IOS 5
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////
  37. // Platform detection
  38. #ifndef EMU_PLATFORM
  39. #if defined( __WIN32__ ) || defined( _WIN32 )
  40. #define EMU_PLATFORM PLATFORM_WINDOWS
  41. #elif defined( __APPLE__ ) || defined( __APPLE_CC__ )
  42. #define EMU_PLATFORM PLATFORM_MAXOSX
  43. #elif defined(__linux__)
  44. #define EMU_PLATFORM PLATFORM_LINUX
  45. #else // Assume linux otherwise
  46. #define EMU_PLATFORM PLATFORM_LINUX
  47. #endif
  48. #endif
  49. #if defined(__x86_64__) || defined(_M_X64) || defined(__alpha__) || defined(__ia64__)
  50. #define EMU_ARCHITECTURE_X64
  51. #else
  52. #define EMU_ARCHITECTURE_X86
  53. #endif
  54. ////////////////////////////////////////////////////////////////////////////////////////////////////
  55. // Compiler-Specific Definitions
  56. #if EMU_PLATFORM == PLATFORM_WINDOWS
  57. #include <time.h>
  58. #define NOMINMAX
  59. #define EMU_FASTCALL __fastcall
  60. inline struct tm* localtime_r(const time_t *clock, struct tm *result) {
  61. if (localtime_s(result, clock) == 0)
  62. return result;
  63. return NULL;
  64. }
  65. #else
  66. #define EMU_FASTCALL __attribute__((fastcall))
  67. #define __stdcall
  68. #define __cdecl
  69. #define LONG long
  70. #define BOOL bool
  71. #define DWORD u32
  72. #endif
  73. #if EMU_PLATFORM != PLATFORM_WINDOWS
  74. // TODO: Hacks..
  75. #include <limits.h>
  76. #define MAX_PATH PATH_MAX
  77. #include <strings.h>
  78. #define stricmp(str1, str2) strcasecmp(str1, str2)
  79. #define _stricmp(str1, str2) strcasecmp(str1, str2)
  80. #define _snprintf snprintf
  81. #define _getcwd getcwd
  82. #define _tzset tzset
  83. typedef void EXCEPTION_POINTERS;
  84. #endif
  85. #define GCC_VERSION_AVAILABLE(major, minor) (defined(__GNUC__) && (__GNUC__ > (major) || \
  86. (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
  87. #endif // COMMON_PLATFORM_H_