platform.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #pragma once
  25. #include "common/common_types.h"
  26. ////////////////////////////////////////////////////////////////////////////////////////////////////
  27. // Platform definitions
  28. /// Enumeration for defining the supported platforms
  29. #define PLATFORM_NULL 0
  30. #define PLATFORM_WINDOWS 1
  31. #define PLATFORM_MACOSX 2
  32. #define PLATFORM_LINUX 3
  33. #define PLATFORM_ANDROID 4
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. // Platform detection
  36. #ifndef EMU_PLATFORM
  37. #if defined( __WIN32__ ) || defined( _WIN32 )
  38. #define EMU_PLATFORM PLATFORM_WINDOWS
  39. #elif defined( __APPLE__ ) || defined( __APPLE_CC__ )
  40. #define EMU_PLATFORM PLATFORM_MACOSX
  41. #elif defined(__linux__)
  42. #define EMU_PLATFORM PLATFORM_LINUX
  43. #else // Assume linux otherwise
  44. #define EMU_PLATFORM PLATFORM_LINUX
  45. #endif
  46. #endif
  47. #if defined(__x86_64__) || defined(_M_X64) || defined(__alpha__) || defined(__ia64__)
  48. #define EMU_ARCHITECTURE_X64
  49. #else
  50. #define EMU_ARCHITECTURE_X86
  51. #endif
  52. ////////////////////////////////////////////////////////////////////////////////////////////////////
  53. // Compiler-Specific Definitions
  54. #if EMU_PLATFORM == PLATFORM_WINDOWS
  55. #include <time.h>
  56. #ifndef NOMINMAX
  57. #define NOMINMAX
  58. #endif
  59. #define EMU_FASTCALL __fastcall
  60. #ifdef _MSC_VER
  61. inline struct tm* localtime_r(const time_t *clock, struct tm *result) {
  62. if (localtime_s(result, clock) == 0)
  63. return result;
  64. return nullptr;
  65. }
  66. #endif
  67. #else
  68. #define EMU_FASTCALL __attribute__((fastcall))
  69. #define __stdcall
  70. #define __cdecl
  71. #define BOOL bool
  72. #define DWORD u32
  73. #endif
  74. #if EMU_PLATFORM != PLATFORM_WINDOWS
  75. // TODO: Hacks..
  76. #include <limits.h>
  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))))