Use target platform from the build script, don't autodetect

This commit is contained in:
flysand7 2023-07-27 23:58:00 +11:00
parent 0e14742117
commit 06e1057ad2
2 changed files with 5 additions and 30 deletions

View File

@ -70,6 +70,7 @@ else: # 'debug'
cc_flags.append('-g') cc_flags.append('-g')
cc_flags.append('-O0') cc_flags.append('-O0')
cc_defines.append('DEBUG') cc_defines.append('DEBUG')
cc_defines.append(f'_CIA_OS_{target.upper()}')
# Generate TinyRT headers for the target platform # Generate TinyRT headers for the target platform
print(f"==> Generating TinyRT header for {target}") print(f"==> Generating TinyRT header for {target}")

View File

@ -6,40 +6,14 @@
#define noreturn _Noreturn #define noreturn _Noreturn
#define NULL ((void *)0) #define NULL ((void *)0)
// Platform macros
#define _CIA_LINUX 1
#define _CIA_WINDOWS 2
#define _CIA_ANDROID 3
// Platform detection
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#define _CIA_OS _CIA_WINDOWS
#if !defined(_WIN64)
#error "32-bit windows is not supported"
#endif
#elif __APPLE__
#error "Apple OS's not supported and will never be unless you want to write the support for it"
#elif __ANDROID__
#define _CIA_OS _CIA_ANDROID
#elif __linux__
#define _CIA_OS _CIA_LINUX
#else
#error "Unable to detect the OS"
#endif
// Convenience platform checking macros
#define _CIA_OS_LINUX() (_CIA_OS == _CIA_LINUX)
#define _CIA_OS_WINDOWS() (_CIA_OS == _CIA_WINDOWS)
#define _CIA_OS_ANDROID() (_CIA_OS == _CIA_ANDROID)
// Assert commonly-accepted platform-invariant sizes // Assert commonly-accepted platform-invariant sizes
static_assert(sizeof(char) == 1, "Char isn't 1 bytes long"); static_assert(sizeof(char) == 1, "Char isn't 1 bytes long");
static_assert(sizeof(short) == 2, "Short isn't 2 bytes long"); static_assert(sizeof(short) == 2, "Short isn't 2 bytes long");
static_assert(sizeof(int) == 4, "Int isn't 4 bytes long"); static_assert(sizeof(int) == 4, "Int isn't 4 bytes long");
static_assert(sizeof(long long int) == 8, "Long long isn't 8 bytes long"); static_assert(sizeof(long long int) == 8, "Long long isn't 8 bytes long");
#if _CIA_OS_LINUX() #if defined(_CIA_OS_LINUX)
static_assert(sizeof(long) == 8, "Long on linux isn't 8 bytes"); static_assert(sizeof(long) == 8, "Long on linux isn't 8 bytes");
#elif _CIA_OS_WINDOWS() #elif defined(_CIA_OS_WINDOWS)
static_assert(sizeof(long) == 4, "Long on windows isn't 4 bytes"); static_assert(sizeof(long) == 4, "Long on windows isn't 4 bytes");
#endif #endif
@ -50,10 +24,10 @@ typedef signed short int16_t;
typedef unsigned short uint16_t; typedef unsigned short uint16_t;
typedef signed int int32_t; typedef signed int int32_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
#if _CIA_OS_LINUX() #if defined(_CIA_OS_LINUX)
typedef signed long int64_t; typedef signed long int64_t;
typedef unsigned long uint64_t; typedef unsigned long uint64_t;
#elif _CIA_OS_WINDOWS() #elif defined(_CIA_OS_WINDOWS)
typedef signed long long int64_t; typedef signed long long int64_t;
typedef unsigned long long uint64_t; typedef unsigned long long uint64_t;
#else #else