diff --git a/public/build.h b/public/build.h index 4e4fe110..636d97a4 100644 --- a/public/build.h +++ b/public/build.h @@ -30,15 +30,22 @@ For more information, please refer to #ifndef BUILD_H #define BUILD_H -// All XASH_* macros set by this header are guaranteed to have positive value otherwise not defined +/* +All XASH_* macros set by this header are guaranteed to have positive value +otherwise not defined. -// Any new define must be undefined at first -// You can generate #undef list below with this oneliner: -// $ cat build.h | sed 's/\t//g' | grep '^#define XASH' | awk '{ print $2 }' | sort | uniq | awk '{ print "#undef " $1 }' -// -// So in various buildscripts you can grep for ^#undef XASH and select only second word -// or in another oneliner: -// $ cat build.h | grep '^#undef XASH' | awk '{ print $2 }' +Every macro is intended to be the unified interface for buildsystems that lack +platform & CPU detection, and a neat quick way for checks in platform code +For Q_build* macros, refer to buildenums.h + +Any new define must be undefined at first +You can generate #undef list below with this oneliner: + $ sed 's/\t//g' build.h | grep '^#define XASH' | awk '{ print $2 }' | \ + sort | uniq | awk '{ print "#undef " $1 }' + +Then you can use another oneliner to query all variables: + $ grep '^#undef XASH' build.h | awk '{ print $2 }' +*/ #undef XASH_64BIT #undef XASH_AMD64 @@ -53,21 +60,19 @@ For more information, please refer to #undef XASH_ARMv7 #undef XASH_ARMv8 #undef XASH_BIG_ENDIAN -#undef XASH_BSD #undef XASH_DOS4GW #undef XASH_E2K #undef XASH_EMSCRIPTEN #undef XASH_FREEBSD #undef XASH_HAIKU #undef XASH_IOS +#undef XASH_IRIX #undef XASH_JS #undef XASH_LINUX +#undef XASH_LINUX_UNKNOWN #undef XASH_LITTLE_ENDIAN -#undef XASH_MINGW #undef XASH_MIPS -#undef XASH_PPC #undef XASH_MOBILE_PLATFORM -#undef XASH_MSVC #undef XASH_NETBSD #undef XASH_OPENBSD #undef XASH_POSIX @@ -77,74 +82,63 @@ For more information, please refer to #undef XASH_RISCV_SOFTFP #undef XASH_SERENITY #undef XASH_WIN32 -#undef XASH_WIN64 #undef XASH_X86 #undef XASH_NSWITCH #undef XASH_PSVITA //================================================================ // -// OPERATING SYSTEM DEFINES +// PLATFORM DETECTION CODE // //================================================================ -#if defined(_WIN32) +#if defined _WIN32 #define XASH_WIN32 1 - #if defined(__MINGW32__) - #define XASH_MINGW 1 - #elif defined(_MSC_VER) - #define XASH_MSVC 1 - #endif - - #if defined(_WIN64) - #define XASH_WIN64 1 - #endif -#elif defined __SWITCH__ - #define XASH_NSWITCH 1 - #define XASH_LITTLE_ENDIAN 1 - #define XASH_POSIX 1 -#elif defined __vita__ - #define XASH_PSVITA 1 - #define XASH_LITTLE_ENDIAN 1 - #define XASH_POSIX 1 -#elif defined(__linux__) - #define XASH_LINUX 1 - #if defined(__ANDROID__) - #define XASH_ANDROID 1 - #endif // defined(__ANDROID__) - #define XASH_POSIX 1 -#elif defined(__APPLE__) - #include - #define XASH_APPLE 1 - #if TARGET_OS_IOS - #define XASH_IOS 1 - #endif // TARGET_OS_IOS - #define XASH_POSIX 1 -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define XASH_BSD 1 - #if defined(__FreeBSD__) - #define XASH_FREEBSD 1 - #elif defined(__NetBSD__) - #define XASH_NETBSD 1 - #elif defined(__OpenBSD__) - #define XASH_OPENBSD 1 - #endif - #define XASH_POSIX 1 #elif defined __EMSCRIPTEN__ #define XASH_EMSCRIPTEN 1 #elif defined __WATCOMC__ && defined __DOS__ #define XASH_DOS4GW 1 - #define XASH_LITTLE_ENDIAN 1 -#elif defined __HAIKU__ - #define XASH_HAIKU 1 - #define XASH_POSIX 1 -#elif defined __serenity__ - #define XASH_SERENITY 1 +#else // POSIX compatible #define XASH_POSIX 1 -#else -#error "Place your operating system name here! If this is a mistake, try to fix conditions above and report a bug" + #if defined __linux__ + #if defined __ANDROID__ + #define XASH_ANDROID 1 + #else + #include + // if our system libc has features.h header + // try to detect it to not confuse other libcs with built with glibc game libraries + #if !defined __GLIBC__ + #define XASH_LINUX_UNKNOWN 1 + #endif + #endif + #define XASH_LINUX 1 + #elif defined __FreeBSD__ + #define XASH_FREEBSD 1 + #elif defined __NetBSD__ + #define XASH_NETBSD 1 + #elif defined __OpenBSD__ + #define XASH_OPENBSD 1 + #elif defined __HAIKU__ + #define XASH_HAIKU 1 + #elif defined __serenity__ + #define XASH_SERENITY 1 + #elif defined __sgi + #define XASH_IRIX 1 + #elif defined __APPLE__ + #include + #define XASH_APPLE 1 + #if TARGET_OS_IOS + #define XASH_IOS 1 + #endif // TARGET_OS_IOS + #elif defined __SWITCH__ + #define XASH_NSWITCH 1 + #elif defined __vita__ + #define XASH_PSVITA 1 + #else + #error + #endif #endif -#if defined XASH_ANDROID || defined XASH_IOS || defined XASH_NSWITCH || defined XASH_PSVITA +#if XASH_ANDROID || defined XASH_IOS || defined XASH_NSWITCH || defined XASH_PSVITA #define XASH_MOBILE_PLATFORM 1 #endif @@ -154,27 +148,17 @@ For more information, please refer to // //================================================================ -#if defined(XASH_FORCE_LITTLE_ENDIAN) && defined(XASH_FORCE_BIG_ENDIAN) - #error "Both XASH_FORCE_LITTLE_ENDIAN and XASH_FORCE_BIG_ENDIAN are defined" -#elif defined(XASH_FORCE_LITTLE_ENDIAN) - #define XASH_LITTLE_ENDIAN 1 -#elif defined(XASH_FORCE_BIG_ENDIAN) - #define XASH_BIG_ENDIAN 1 -#endif - -#if !defined(XASH_LITTLE_ENDIAN) && !defined(XASH_BIG_ENDIAN) - #if defined XASH_MSVC || __LITTLE_ENDIAN__ +#if !defined XASH_ENDIANNESS + #if defined XASH_WIN32 || __LITTLE_ENDIAN__ //!!! Probably all WinNT installations runs in little endian #define XASH_LITTLE_ENDIAN 1 #elif __BIG_ENDIAN__ #define XASH_BIG_ENDIAN 1 - #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_LITTLE_ENDIAN__) // some compilers define this + #elif defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ && defined __ORDER_LITTLE_ENDIAN__ // some compilers define this #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define XASH_BIG_ENDIAN 1 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define XASH_LITTLE_ENDIAN 1 - #else - #error "Unknown endianness!" #endif #else #include @@ -182,8 +166,6 @@ For more information, please refer to #define XASH_BIG_ENDIAN 1 #elif __BYTE_ORDER == __LITTLE_ENDIAN #define XASH_LITTLE_ENDIAN 1 - #else - #error "Unknown endianness!" #endif #endif // !XASH_WIN32 #endif @@ -193,18 +175,28 @@ For more information, please refer to // CPU ARCHITECTURE DEFINES // //================================================================ -#if defined(__x86_64__) || defined(_M_X64) +#if defined __x86_64__ || defined _M_X64 #define XASH_64BIT 1 #define XASH_AMD64 1 -#elif defined(__i386__) || defined(_X86_) || defined(_M_IX86) +#elif defined __i386__ || defined _X86_ || defined _M_IX86 #define XASH_X86 1 #elif defined __aarch64__ || defined _M_ARM64 #define XASH_64BIT 1 - #define XASH_ARM 8 -#elif defined __arm__ || defined _M_ARM + #define XASH_ARM 8 +#elif defined __mips__ + #define XASH_MIPS 1 +#elif defined __EMSCRIPTEN__ + #define XASH_JS 1 +#elif defined __e2k__ + #define XASH_64BIT 1 + #define XASH_E2K 1 +#elif defined _M_ARM // msvc + #define XASH_ARM 7 + #define XASH_ARM_HARDFP 1 +#elif defined __arm__ #if __ARM_ARCH == 8 || __ARM_ARCH_8__ #define XASH_ARM 8 - #elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || defined _M_ARM // msvc can only armv7 in 32 bit + #elif __ARM_ARCH == 7 || __ARM_ARCH_7__ #define XASH_ARM 7 #elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__ #define XASH_ARM 6 @@ -216,34 +208,17 @@ For more information, please refer to #error "Unknown ARM" #endif - #if defined _M_ARM - #error "No WinMobile port yet! Need to determine which ARM float ABI msvc uses if applicable" - #endif - #if defined __SOFTFP__ || __ARM_PCS_VFP == 0 #define XASH_ARM_SOFTFP 1 #else // __SOFTFP__ #define XASH_ARM_HARDFP 1 #endif // __SOFTFP__ -#elif defined __mips__ - #define XASH_MIPS 1 -#elif defined __powerpc__ - #define XASH_PPC 1 - #if defined __powerpc64__ - #define XASH_64BIT 1 - #endif -#elif defined __EMSCRIPTEN__ - #define XASH_JS 1 -#elif defined __e2k__ - #define XASH_64BIT 1 - #define XASH_E2K 1 #elif defined __riscv #define XASH_RISCV 1 + #if __riscv_xlen == 64 #define XASH_64BIT 1 - #elif __riscv_xlen == 32 - // ... - #else + #elif __riscv_xlen != 32 #error "Unknown RISC-V ABI" #endif @@ -260,10 +235,6 @@ For more information, please refer to #error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug" #endif -#if defined(XASH_WAF_DETECTED_64BIT) && !defined(XASH_64BIT) - #define XASH_64BIT 1 -#endif - #if XASH_ARM == 8 #define XASH_ARMv8 1 #elif XASH_ARM == 7