diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-20 22:35:24 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:33 +0200 |
commit | 95fa2a46519d0820548ab7855b32182ff81f0435 (patch) | |
tree | ff5333b61195a0d5019eb3d0aea05a1ff1ba7897 /include | |
parent | 29fa87b048c20a1e6e648cb874c6da1cb7f1766a (diff) |
Change linux platform from 64 to x86_64, add sibs platforms command
Diffstat (limited to 'include')
-rw-r--r-- | include/Conf.hpp | 16 | ||||
-rw-r--r-- | include/Platform.hpp | 61 | ||||
-rw-r--r-- | include/StringView.hpp | 41 | ||||
-rw-r--r-- | include/env.hpp | 27 |
4 files changed, 104 insertions, 41 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp index 2645caa..eae79d4 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -149,10 +149,20 @@ namespace sibs #define CONFIG_STATIC_LIB_FILE_EXTENSION L"lib" #define CONFIG_DYNAMIC_LIB_FILE_EXTENSION L"dll" #elif OS_TYPE == OS_TYPE_LINUX - #ifdef SIBS_ENV_32BIT - const Platform SYSTEM_PLATFORM = PLATFORM_LINUX32; + #ifdef SIBS_ARCH_ARM + #ifdef SIBS_ENV_32BIT + const Platform SYSTEM_PLATFORM = PLATFORM_LINUX_ARM32; + #else + const Platform SYSTEM_PLATFORM = PLATFORM_LINUX_ARM64; + #endif + #elif defined(SIBS_ARCH_X86) + #ifdef SIBS_ENV_32BIT + const Platform SYSTEM_PLATFORM = PLATFORM_LINUX_X86_32; + #else + const Platform SYSTEM_PLATFORM = PLATFORM_LINUX_X86_64; + #endif #else - const Platform SYSTEM_PLATFORM = PLATFORM_LINUX64; + #error "non arm/x86 linux platform" #endif #define CONFIG_STATIC_LIB_FILE_EXTENSION "a" #ifdef __CYGWIN__ diff --git a/include/Platform.hpp b/include/Platform.hpp index 6075383..2c9feb5 100644 --- a/include/Platform.hpp +++ b/include/Platform.hpp @@ -3,43 +3,48 @@ #include "types.hpp" #include "StringView.hpp" #include <vector> +#include <string> namespace sibs { enum Platform : u64 { - PLATFORM_INVALID = 0x00000000, + PLATFORM_INVALID = 0x0000000000000000, - PLATFORM_ANY = 0xFFFFFFFF, + PLATFORM_ANY = 0xFFFFFFFFFFFFFFFF, - PLATFORM_POSIX = 1 << 1, - PLATFORM_POSIX32 = 1 << 2 | PLATFORM_POSIX, - PLATFORM_POSIX64 = 1 << 3 | PLATFORM_POSIX, + PLATFORM_POSIX = 1ULL << 1ULL, + PLATFORM_POSIX32 = 1ULL << 2ULL | PLATFORM_POSIX, + PLATFORM_POSIX64 = 1ULL << 3ULL | PLATFORM_POSIX, - PLATFORM_LINUX = 1 << 4 | PLATFORM_POSIX, - PLATFORM_LINUX32 = 1 << 5 | PLATFORM_LINUX | PLATFORM_POSIX32, - PLATFORM_LINUX64 = 1 << 6 | PLATFORM_LINUX | PLATFORM_POSIX64, + PLATFORM_LINUX = 1ULL << 4ULL | PLATFORM_POSIX, + PLATFORM_LINUX32 = 1ULL << 5ULL | PLATFORM_LINUX | PLATFORM_POSIX32, + PLATFORM_LINUX64 = 1ULL << 6ULL | PLATFORM_LINUX | PLATFORM_POSIX64, - PLATFORM_WIN = 1 << 7, - PLATFORM_WIN32 = 1 << 8 | PLATFORM_WIN, - PLATFORM_WIN64 = 1 << 9 | PLATFORM_WIN, + PLATFORM_WIN = 1ULL << 7ULL, + PLATFORM_WIN32 = 1ULL << 8ULL | PLATFORM_WIN, + PLATFORM_WIN64 = 1ULL << 9ULL | PLATFORM_WIN, - PLATFORM_MACOS = 1 << 10 | PLATFORM_POSIX, - PLATFORM_MACOS32 = 1 << 11 | PLATFORM_MACOS | PLATFORM_POSIX32, - PLATFORM_MACOS64 = 1 << 12 | PLATFORM_MACOS | PLATFORM_POSIX64, + PLATFORM_MACOS = 1ULL << 10ULL | PLATFORM_POSIX, + PLATFORM_MACOS32 = 1ULL << 11ULL | PLATFORM_MACOS | PLATFORM_POSIX32, + PLATFORM_MACOS64 = 1ULL << 12ULL | PLATFORM_MACOS | PLATFORM_POSIX64, - PLATFORM_BSD = 1 << 13 | PLATFORM_POSIX, - PLATFORM_OPENBSD = 1 << 14 | PLATFORM_BSD, - PLATFORM_OPENBSD32 = 1 << 15 | PLATFORM_OPENBSD | PLATFORM_POSIX32, - PLATFORM_OPENBSD64 = 1 << 16 | PLATFORM_OPENBSD | PLATFORM_POSIX64, + PLATFORM_BSD = 1ULL << 13ULL | PLATFORM_POSIX, + PLATFORM_OPENBSD = 1ULL << 14ULL | PLATFORM_BSD, + PLATFORM_OPENBSD32 = 1ULL << 15ULL | PLATFORM_OPENBSD | PLATFORM_POSIX32, + PLATFORM_OPENBSD64 = 1ULL << 16ULL | PLATFORM_OPENBSD | PLATFORM_POSIX64, - PLATFORM_HAIKU = 1 << 24 | PLATFORM_POSIX, - PLATFORM_HAIKU32 = 1 << 25 | PLATFORM_HAIKU | PLATFORM_POSIX32, - PLATFORM_HAIKU64 = 1 << 26 | PLATFORM_HAIKU | PLATFORM_POSIX64, + PLATFORM_HAIKU = 1ULL << 24ULL | PLATFORM_POSIX, + PLATFORM_HAIKU32 = 1ULL << 25ULL | PLATFORM_HAIKU | PLATFORM_POSIX32, + PLATFORM_HAIKU64 = 1ULL << 26ULL | PLATFORM_HAIKU | PLATFORM_POSIX64, - PLATFORM_LINUX_ARM = 1 << 27 | PLATFORM_LINUX, - PLATFORM_LINUX_ARM32 = 1 << 28 | PLATFORM_LINUX32, - PLATFORM_LINUX_ARM64 = 1 << 29 | PLATFORM_LINUX64 + PLATFORM_LINUX_ARM = 1ULL << 27ULL | PLATFORM_LINUX, + PLATFORM_LINUX_ARM32 = 1ULL << 28ULL | PLATFORM_LINUX32, + PLATFORM_LINUX_ARM64 = 1ULL << 29ULL | PLATFORM_LINUX64, + + PLATFORM_LINUX_X86 = 1ULL << 30ULL | PLATFORM_LINUX, + PLATFORM_LINUX_X86_32 = 1ULL << 31ULL | PLATFORM_LINUX32, + PLATFORM_LINUX_X86_64 = 1ULL << 32ULL | PLATFORM_LINUX64 }; const StringViewMap<Platform> PLATFORM_BY_NAME = { @@ -65,12 +70,18 @@ namespace sibs { "haiku64", PLATFORM_HAIKU64 }, { "linux_arm", PLATFORM_LINUX_ARM }, { "linux_arm32", PLATFORM_LINUX_ARM32 }, - { "linux_arm64", PLATFORM_LINUX_ARM64 } + { "linux_arm64", PLATFORM_LINUX_ARM64 }, + { "linux_x86", PLATFORM_LINUX_X86 }, + { "linux_x86_32", PLATFORM_LINUX_X86_32 }, + { "linux_x86_64", PLATFORM_LINUX_X86_64 } }; bool containsPlatform(const std::vector<Platform> &platforms, Platform platform); const char* asString(Platform platform); Platform getPlatformByName(StringView name); + + std::string getPlatformListFormatted(); + // Return true if both platforms are of same type, for example if platform @a is either win, win32, win64 and @b is either win, win32, win64 bool isSamePlatformFamily(Platform a, Platform b); // Returns true if platform @base is a base platform for platform @platform, for example if @platform is win64 and @base is either win64 or win, then this function return true. diff --git a/include/StringView.hpp b/include/StringView.hpp index 4d87d8a..8ca685d 100644 --- a/include/StringView.hpp +++ b/include/StringView.hpp @@ -7,6 +7,7 @@ #include "env.hpp" #include <cstring> #include <unordered_map> +#include <map> #include <cassert> namespace sibs @@ -36,8 +37,7 @@ namespace sibs bool equals(const StringView &other) const { - if(size != other.size) return false; - return memcmp(data, other.data, size) == 0; + return size == other.size && memcmp(data, other.data, size) == 0; } size_t hash() const @@ -54,6 +54,31 @@ namespace sibs assert(index < size); return data[index]; } + + bool operator < (const StringView &other) const + { + return ((ssize)size - (ssize)other.size < 0) || strncmp(data, other.data, size) < 0; + } + + bool operator > (const StringView &other) const + { + return !operator<(other); + } + + size_t operator()() const + { + return hash(); + } + + bool operator()(const StringView &other) const + { + return equals(other); + } + + bool operator == (const StringView &other) const + { + return equals(other); + } const char *data; usize size; @@ -75,9 +100,21 @@ namespace sibs return lhs.equals(rhs); } }; + + struct StringViewCompareSorted + { + public: + bool operator()(const StringView &lhs, const StringView &rhs) const + { + return lhs < rhs; + } + }; template <typename ValueType> using StringViewMap = std::unordered_map<const StringView, ValueType, StringViewHash, StringViewCompare>; + + // template <typename ValueType> + // using StringViewMapSorted = std::map<const StringView, ValueType, StringViewCompareSorted>; } #endif // SIBS_STRING_VIEW_HPP diff --git a/include/env.hpp b/include/env.hpp index b25cb69..8037f26 100644 --- a/include/env.hpp +++ b/include/env.hpp @@ -11,11 +11,6 @@ #define OS_TYPE_HAIKU 10 #if defined(_WIN32) || defined(_WIN64) - #if defined(_WIN64) - #define SIBS_ENV_64BIT - #else - #define SIBS_ENV_32BIT - #endif #define OS_FAMILY OS_FAMILY_WINDOWS #define OS_TYPE OS_TYPE_WINDOWS @@ -64,12 +59,18 @@ #define OS_TYPE OS_TYPE_LINUX #endif -#if defined(__GNUC__) - #if defined(__x86_64__) || defined(__pc64__) - #define SIBS_ENV_64BIT - #else - #define SIBS_ENV_32BIT - #endif +#if defined(__aarch64__) + #define SIBS_ARCH_ARM + #define SIBS_ENV_64BIT +#elif defined(__arm__) || defined(_ARM) || defined(_M_ARM) || defined(__arm) + #define SIBS_ARCH_ARM + #define SIBS_ENV_32BIT +#elif defined(__x86_64__) || defined(__amd64__) || defined(__amd64) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) + #define SIBS_ARCH_X86 + #define SIBS_ENV_64BIT +#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(__IA32__) || defined(_M_I86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) + #define SIBS_ARCH_X86 + #define SIBS_ENV_32BIT #endif #if !defined(SIBS_ENV_32BIT) && !defined(SIBS_ENV_64BIT) @@ -84,6 +85,10 @@ #error "System not supported. Only Windows, linux, macos and openbsd systems supported right now" #endif +#if !defined(SIBS_ARCH_ARM) && !defined(SIBS_ARCH_X86) + #error "System is not detected as either arm or x86" +#endif + #if !defined(DEBUG) && !defined(NDEBUG) #define DEBUG #endif |