From 9277c9b6b3f8308f32b9a08047047e176f279676 Mon Sep 17 00:00:00 2001 From: lye Date: Wed, 9 Jul 2014 20:34:24 -0700 Subject: [PATCH] Add FreeBSD support to the codebase. The FreeBSD-specific compatibility changes are invoked when the __FreeBSD__ macro is defined, which is the default for (I think all?) toolchains on FreeBSD. This turns on the BX_PLATFORM_FREEBSD macro which can be used for further specializations. FreeBSD is a mix between Linux, NaCl and OSX, with some extra cavaets that have been worked around: * malloc.h is deprecated; FreeBSD uses stdlib.h instead. * alloca.h doesn't exist; it's also in stdlib.h. --- include/bx/allocator.h | 6 +++++- include/bx/macros.h | 1 + include/bx/os.h | 7 ++++--- include/bx/platform.h | 9 ++++++++- include/bx/readerwriter.h | 2 +- include/bx/string.h | 4 +++- include/bx/timer.h | 2 +- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index ba874e0..5af503f 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -12,7 +12,11 @@ #include #if BX_CONFIG_ALLOCATOR_CRT -# include +# if BX_PLATFORM_FREEBSD +# include +# else +# include +# endif #endif // BX_CONFIG_ALLOCATOR_CRT #if BX_CONFIG_ALLOCATOR_DEBUG diff --git a/include/bx/macros.h b/include/bx/macros.h index f3dedb3..03c8baa 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -162,6 +162,7 @@ |BX_PLATFORM_OSX \ |BX_PLATFORM_QNX \ |BX_PLATFORM_WINDOWS \ + |BX_PLATFORM_FREEBSD \ ) #endif // BX_CONFIG_CRT_FILE_READER_WRITER diff --git a/include/bx/os.h b/include/bx/os.h index 5c4a694..bd0134e 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -15,10 +15,11 @@ || BX_PLATFORM_LINUX \ || BX_PLATFORM_OSX \ || BX_PLATFORM_IOS \ - || BX_PLATFORM_EMSCRIPTEN + || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_FREEBSD # include // sched_yield -# if BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL +# if BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD # include // mach_port_t # endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL @@ -71,7 +72,7 @@ namespace bx return (pid_t)::syscall(SYS_gettid); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX return (mach_port_t)::pthread_mach_thread_np(pthread_self() ); -#elif BX_PLATFORM_NACL +#elif BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD // Casting __nc_basic_thread_data*... need better way to do this. return *(uint32_t*)::pthread_self(); #else diff --git a/include/bx/platform.h b/include/bx/platform.h index 81833f4..c9166ae 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -19,6 +19,7 @@ #define BX_PLATFORM_QNX 0 #define BX_PLATFORM_WINDOWS 0 #define BX_PLATFORM_XBOX360 0 +#define BX_PLATFORM_FREEBSD 0 #define BX_CPU_ARM 0 #define BX_CPU_JIT 0 @@ -83,6 +84,9 @@ #elif defined(__QNX__) # undef BX_PLATFORM_QNX # define BX_PLATFORM_QNX 1 +#elif defined(__FreeBSD__) +# undef BX_PLATFORM_FREEBSD +# define BX_PLATFORM_FREEBSD 1 #else # error "BX_PLATFORM_* is not defined!" #endif // @@ -93,7 +97,8 @@ || BX_PLATFORM_LINUX \ || BX_PLATFORM_NACL \ || BX_PLATFORM_OSX \ - || BX_PLATFORM_QNX) + || BX_PLATFORM_QNX \ + || BX_PLATFORM_FREEBSD ) // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures #if defined(__arm__) @@ -160,6 +165,8 @@ # define BX_PLATFORM_NAME "OSX" #elif BX_PLATFORM_QNX # define BX_PLATFORM_NAME "QNX" +#elif BX_PLATFORM_FREEBSD +# define BX_PLATFORM_NAME "FreeBSD" #elif BX_PLATFORM_WINDOWS # define BX_PLATFORM_NAME "Windows" #endif // BX_PLATFORM_ diff --git a/include/bx/readerwriter.h b/include/bx/readerwriter.h index 7419783..ccc84a0 100644 --- a/include/bx/readerwriter.h +++ b/include/bx/readerwriter.h @@ -15,7 +15,7 @@ #if BX_COMPILER_MSVC # define fseeko64 _fseeki64 # define ftello64 _ftelli64 -#elif BX_PLATFORM_ANDROID|BX_PLATFORM_IOS|BX_PLATFORM_OSX|BX_PLATFORM_QNX +#elif BX_PLATFORM_ANDROID|BX_PLATFORM_IOS|BX_PLATFORM_OSX|BX_PLATFORM_QNX|BX_PLATFORM_FREEBSD # define fseeko64 fseeko # define ftello64 ftello #endif // BX_ diff --git a/include/bx/string.h b/include/bx/string.h index 044cd99..a81219f 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -7,7 +7,9 @@ #define BX_PRINTF_H_HEADER_GUARD #include "bx.h" -#include +#if !BX_PLATFORM_FREEBSD +# include +#endif #include // tolower #include // va_list #include // vsnprintf, vsnwprintf diff --git a/include/bx/timer.h b/include/bx/timer.h index ae52038..71df01c 100644 --- a/include/bx/timer.h +++ b/include/bx/timer.h @@ -12,7 +12,7 @@ # include // clock, clock_gettime #elif BX_PLATFORM_EMSCRIPTEN # include -#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX +#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX || BX_PLATFORM_FREEBSD # include // gettimeofday #elif BX_PLATFORM_WINDOWS # include