From db5e1d9b8fcf0f76f3b236455420403a3e639357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 18 Feb 2017 21:29:33 -0800 Subject: [PATCH] Cleanup. --- include/bx/config.h | 25 +++++++++++++----------- include/bx/mutex.h | 4 ---- include/bx/platform.h | 35 ++++++++++++++++++++++++++++----- include/bx/semaphore.h | 4 ---- include/bx/thread.h | 4 ---- scripts/toolchain.lua | 44 +++++++++++++++++++++++++----------------- src/commandline.cpp | 4 ++-- src/crtnone.cpp | 10 +++++++--- src/os.cpp | 4 ++++ src/semaphore.cpp | 7 +++++++ src/timer.cpp | 5 ++++- 11 files changed, 94 insertions(+), 52 deletions(-) diff --git a/include/bx/config.h b/include/bx/config.h index 92ef7fd..ad7c5c0 100644 --- a/include/bx/config.h +++ b/include/bx/config.h @@ -17,25 +17,28 @@ #endif // BX_CONFIG_ALLOCATOR_CRT #ifndef BX_CONFIG_CRT_FILE_READER_WRITER -# define BX_CONFIG_CRT_FILE_READER_WRITER !(BX_PLATFORM_NACL) +# define BX_CONFIG_CRT_FILE_READER_WRITER !(0 \ + || BX_PLATFORM_NACL \ + || BX_CRT_NONE \ + ) #endif // BX_CONFIG_CRT_FILE_READER_WRITER #ifndef BX_CONFIG_CRT_PROCESS -# define BX_CONFIG_CRT_PROCESS !(0 \ +# define BX_CONFIG_CRT_PROCESS !(0 \ + || BX_CRT_NONE \ || BX_PLATFORM_EMSCRIPTEN \ - || BX_PLATFORM_NACL \ - || BX_PLATFORM_PS4 \ - || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOXONE \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOXONE \ ) #endif // BX_CONFIG_CRT_PROCESS -#ifndef BX_CONFIG_SEMAPHORE_PTHREAD -# define BX_CONFIG_SEMAPHORE_PTHREAD (BX_PLATFORM_OSX || BX_PLATFORM_IOS) -#endif // BX_CONFIG_SEMAPHORE_PTHREAD - #ifndef BX_CONFIG_SUPPORTS_THREADING -# define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN) +# define BX_CONFIG_SUPPORTS_THREADING !(0 \ + || BX_PLATFORM_EMSCRIPTEN \ + || BX_CRT_NONE \ + ) #endif // BX_CONFIG_SUPPORTS_THREADING #endif // BX_CONFIG_H_HEADER_GUARD diff --git a/include/bx/mutex.h b/include/bx/mutex.h index 220d738..ac8ea7f 100644 --- a/include/bx/mutex.h +++ b/include/bx/mutex.h @@ -8,8 +8,6 @@ #include "bx.h" -#if BX_CONFIG_SUPPORTS_THREADING - namespace bx { /// @@ -61,6 +59,4 @@ namespace bx #include "inline/mutex.inl" -#endif // BX_CONFIG_SUPPORTS_THREADING - #endif // BX_MUTEX_H_HEADER_GUARD diff --git a/include/bx/platform.h b/include/bx/platform.h index 5bf41d2..1f9a98d 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -268,9 +268,24 @@ || BX_PLATFORM_RPI \ ) -#ifndef BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS -# define BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS 0 -#endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS +#define BX_PLATFORM_NONE !(0 \ + || BX_PLATFORM_ANDROID \ + || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_BSD \ + || BX_PLATFORM_HURD \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_QNX \ + || BX_PLATFORM_RPI \ + || BX_PLATFORM_STEAMLINK \ + || BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE \ + ) #if BX_COMPILER_GCC # define BX_COMPILER_NAME "GCC " \ @@ -337,8 +352,10 @@ # define BX_PLATFORM_NAME "Xbox 360" #elif BX_PLATFORM_XBOXONE # define BX_PLATFORM_NAME "Xbox One" -#else +#elif BX_PLATFORM_NONE # define BX_PLATFORM_NAME "None" +#else +# error "Unknown BX_PLATFORM!" #endif // BX_PLATFORM_ #if BX_CPU_ARM @@ -363,12 +380,16 @@ # define BX_CRT_NAME "MSVC C Runtime" #elif BX_CRT_MINGW # define BX_CRT_NAME "MinGW C Runtime" +#elif BX_CRT_LIBCXX +# define BX_CRT_NAME "Clang C Library" #elif BX_CRT_NEWLIB # define BX_CRT_NAME "Newlib" #elif BX_CRT_MUSL # define BX_CRT_NAME "musl libc" -#else +#elif BX_CRT_NONE # define BX_CRT_NAME "None" +#else +# error "Unknown BX_CRT!" #endif // BX_CRT_ #if BX_ARCH_32BIT @@ -377,6 +398,10 @@ # define BX_ARCH_NAME "64-bit" #endif // BX_ARCH_ +#ifndef BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS +# define BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS 0 +#endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS + #if BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS && BX_COMPILER_MSVC # pragma warning(error:4062) // ENABLE warning C4062: enumerator'...' in switch of enum '...' is not handled # pragma warning(error:4100) // ENABLE warning C4100: '' : unreferenced formal parameter diff --git a/include/bx/semaphore.h b/include/bx/semaphore.h index 205e979..867fa9e 100644 --- a/include/bx/semaphore.h +++ b/include/bx/semaphore.h @@ -8,8 +8,6 @@ #include "bx.h" -#if BX_CONFIG_SUPPORTS_THREADING - namespace bx { /// @@ -39,6 +37,4 @@ namespace bx } // namespace bx -#endif // BX_CONFIG_SUPPORTS_THREADING - #endif // BX_SEM_H_HEADER_GUARD diff --git a/include/bx/thread.h b/include/bx/thread.h index e057244..72a072e 100644 --- a/include/bx/thread.h +++ b/include/bx/thread.h @@ -9,8 +9,6 @@ #include "bx.h" #include "semaphore.h" -#if BX_CONFIG_SUPPORTS_THREADING - namespace bx { /// @@ -82,6 +80,4 @@ namespace bx } // namespace bx -#endif // BX_CONFIG_SUPPORTS_THREADING - #endif // BX_THREAD_H_HEADER_GUARD diff --git a/scripts/toolchain.lua b/scripts/toolchain.lua index 6821a66..6c2b2dc 100644 --- a/scripts/toolchain.lua +++ b/scripts/toolchain.lua @@ -8,32 +8,39 @@ local naclToolchain = "" local function crtNone() - if _OPTIONS["with-crtnone"] then - defines { "BX_CRT_NONE" } + defines { + "BX_CRT_NONE=1", + } + + buildoptions { + "-nostdlib", + "-nodefaultlibs", + "-nostartfiles", + "-Wa,--noexecstack", + "-ffreestanding", + } + + linkoptions { + "-nostdlib", + "-nodefaultlibs", + "-nostartfiles", + "-Wa,--noexecstack", + "-ffreestanding", + } + + configuration { "linux-*" } buildoptions { - "-nostdlib", - "-nodefaultlibs", - "-nostartfiles", - "-Wa,--noexecstack", - "-ffreestanding", - "-mpreferred-stack-boundary=4", "-mstackrealign", } linkoptions { - "-nostdlib", - "-nodefaultlibs", - "-nostartfiles", - "-Wa,--noexecstack", - "-ffreestanding", - "-mpreferred-stack-boundary=4", "-mstackrealign", } - end + configuration {} end function toolchain(_buildDir, _libDir) @@ -546,6 +553,10 @@ function toolchain(_buildDir, _libDir) flags { "EnableAVX" } end + if _OPTIONS["with-crtnone"] then + crtNone() + end + flags { "NoPCH", "NativeWChar", @@ -741,9 +752,6 @@ function toolchain(_buildDir, _libDir) } buildoptions { "-m64" } - configuration { "linux-*" } - crtNone() - configuration { "linux-clang" } configuration { "linux-gcc-6" } diff --git a/src/commandline.cpp b/src/commandline.cpp index 400e496..6ec2aad 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -175,13 +175,13 @@ namespace bx bool CommandLine::hasArg(const char _short, const char* _long) const { - const char* arg = findOption(_short, _long, 0); + const char* arg = findOption(_short, _long, int32_t(0) ); return NULL != arg; } bool CommandLine::hasArg(const char* _long) const { - const char* arg = findOption('\0', _long, 0); + const char* arg = findOption('\0', _long, int32_t(0) ); return NULL != arg; } diff --git a/src/crtnone.cpp b/src/crtnone.cpp index 67b6cfc..0e88551 100644 --- a/src/crtnone.cpp +++ b/src/crtnone.cpp @@ -9,9 +9,6 @@ #if BX_CRT_NONE -typedef int64_t off64_t; -typedef int32_t pid_t; - extern "C" void* memcpy(void* _dst, const void* _src, size_t _numBytes) { bx::memCopy(_dst, _src, _numBytes); @@ -30,6 +27,11 @@ extern "C" void* memset(void* _dst, int _ch, size_t _numBytes) return _dst; } +#if !BX_PLATFORM_NONE + +typedef int64_t off64_t; +typedef int32_t pid_t; + extern "C" int32_t memcmp(const void* _lhs, const void* _rhs, size_t _numBytes) { return bx::memCmp(_lhs, _rhs, _numBytes); @@ -489,6 +491,8 @@ extern "C" void free(void* _ptr) BX_UNUSED(_ptr); } +#endif // BX_PLATFORM_* + extern "C" void abort() { while (true) {}; diff --git a/src/os.cpp b/src/os.cpp index 8aba304..0c7e9dc 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -7,6 +7,8 @@ #include #include +#if !BX_PLATFORM_NONE + #include #include @@ -453,3 +455,5 @@ namespace bx } } // namespace bx + +#endif // !BX_PLATFORM_NONE diff --git a/src/semaphore.cpp b/src/semaphore.cpp index 6e8a8b3..b4369ff 100644 --- a/src/semaphore.cpp +++ b/src/semaphore.cpp @@ -23,6 +23,13 @@ # endif // BX_PLATFORM_XBOXONE #endif // BX_PLATFORM_ +#ifndef BX_CONFIG_SEMAPHORE_PTHREAD +# define BX_CONFIG_SEMAPHORE_PTHREAD (0 \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_IOS \ + ) +#endif // BX_CONFIG_SEMAPHORE_PTHREAD + namespace bx { struct SemaphoreInternal diff --git a/src/timer.cpp b/src/timer.cpp index ed4cbc0..7f54037 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -31,10 +31,13 @@ namespace bx int64_t i64 = now.tv_sec*INT64_C(1000000000) + now.tv_nsec; #elif BX_PLATFORM_EMSCRIPTEN int64_t i64 = int64_t(1000.0f * emscripten_get_now() ); -#else +#elif !BX_PLATFORM_NONE struct timeval now; gettimeofday(&now, 0); int64_t i64 = now.tv_sec*INT64_C(1000000) + now.tv_usec; +#else + BX_CHECK(false, "Not implemented!"); + int64_t i64 = UINT64_MAX; #endif // BX_PLATFORM_ return i64; }