modplatform.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef MICROPY_INCLUDED_MODPLATFORM_H
  27. #define MICROPY_INCLUDED_MODPLATFORM_H
  28. #include "py/misc.h" // For MP_STRINGIFY.
  29. #include "py/mpconfig.h"
  30. // Preprocessor directives identifying the platform.
  31. // The platform module itself is guarded by MICROPY_PY_PLATFORM, see the
  32. // .c file, but these are made available because they're generally usable.
  33. // TODO: Add more architectures, compilers and libraries.
  34. // See: https://sourceforge.net/p/predef/wiki/Home/
  35. #if defined(__ARM_ARCH)
  36. #define MICROPY_PLATFORM_ARCH "arm"
  37. #elif defined(__x86_64__) || defined(_M_X64)
  38. #define MICROPY_PLATFORM_ARCH "x86_64"
  39. #elif defined(__i386__) || defined(_M_IX86)
  40. #define MICROPY_PLATFORM_ARCH "x86"
  41. #elif defined(__xtensa__)
  42. #define MICROPY_PLATFORM_ARCH "xtensa"
  43. #elif defined(__riscv)
  44. #define MICROPY_PLATFORM_ARCH "riscv"
  45. #else
  46. #define MICROPY_PLATFORM_ARCH ""
  47. #endif
  48. #if defined(__GNUC__)
  49. #define MICROPY_PLATFORM_COMPILER \
  50. "GCC " \
  51. MP_STRINGIFY(__GNUC__) "." \
  52. MP_STRINGIFY(__GNUC_MINOR__) "." \
  53. MP_STRINGIFY(__GNUC_PATCHLEVEL__)
  54. #elif defined(__ARMCC_VERSION)
  55. #define MICROPY_PLATFORM_COMPILER \
  56. "ARMCC " \
  57. MP_STRINGIFY((__ARMCC_VERSION / 1000000)) "." \
  58. MP_STRINGIFY((__ARMCC_VERSION / 10000 % 100)) "." \
  59. MP_STRINGIFY((__ARMCC_VERSION % 10000))
  60. #elif defined(_MSC_VER)
  61. #if defined(_WIN64)
  62. #define MICROPY_PLATFORM_COMPILER_BITS "64 bit"
  63. #elif defined(_M_IX86)
  64. #define MICROPY_PLATFORM_COMPILER_BITS "32 bit"
  65. #else
  66. #define MICROPY_PLATFORM_COMPILER_BITS ""
  67. #endif
  68. #define MICROPY_PLATFORM_COMPILER \
  69. "MSC v." MP_STRINGIFY(_MSC_VER) " " MICROPY_PLATFORM_COMPILER_BITS
  70. #else
  71. #define MICROPY_PLATFORM_COMPILER ""
  72. #endif
  73. #if defined(__GLIBC__)
  74. #define MICROPY_PLATFORM_LIBC_LIB "glibc"
  75. #define MICROPY_PLATFORM_LIBC_VER \
  76. MP_STRINGIFY(__GLIBC__) "." \
  77. MP_STRINGIFY(__GLIBC_MINOR__)
  78. #elif defined(__NEWLIB__)
  79. #define MICROPY_PLATFORM_LIBC_LIB "newlib"
  80. #define MICROPY_PLATFORM_LIBC_VER _NEWLIB_VERSION
  81. #else
  82. #define MICROPY_PLATFORM_LIBC_LIB ""
  83. #define MICROPY_PLATFORM_LIBC_VER ""
  84. #endif
  85. #if defined(__linux)
  86. #define MICROPY_PLATFORM_SYSTEM "Linux"
  87. #elif defined(__unix__)
  88. #define MICROPY_PLATFORM_SYSTEM "Unix"
  89. #elif defined(__CYGWIN__)
  90. #define MICROPY_PLATFORM_SYSTEM "Cygwin"
  91. #elif defined(_WIN32)
  92. #define MICROPY_PLATFORM_SYSTEM "Windows"
  93. #else
  94. #define MICROPY_PLATFORM_SYSTEM "MicroPython"
  95. #endif
  96. #ifndef MICROPY_PLATFORM_VERSION
  97. #define MICROPY_PLATFORM_VERSION ""
  98. #endif
  99. #endif // MICROPY_INCLUDED_MODPLATFORM_H