From 6602ae50c350fd2614769e18e8818b127a16db00 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 9 Mar 2019 13:33:08 +1100 Subject: [PATCH] Initial work on NetBSD port --- readme.md | 4 ++++ src/Core.h | 5 +++++ src/Platform.c | 55 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/readme.md b/readme.md index d0af5daaf..66d348d06 100644 --- a/readme.md +++ b/readme.md @@ -73,6 +73,10 @@ Install libexecinfo package if needed. ```gcc *.c -o ClassiCube -isystem /usr/X11R6/include -isystem /usr/local/include -L /usr/X11R6/lib -L /usr/local/lib -lX11 -lGL -lcurl -lopenal -lexecinfo``` +#### NetBSD + +```gcc *.c -o ClassiCube -I /usr/X11R7/include -I /usr/pkg/include -L /usr/X11R7/lib -L /usr/pkg/lib -lX11 -lGL -lcurl -lopenal -lpthread -lexecinfo``` + ### Documentation Functions and variables in .h files are mostly documented. diff --git a/src/Core.h b/src/Core.h index 3779d83eb..0d9e38be0 100644 --- a/src/Core.h +++ b/src/Core.h @@ -108,6 +108,11 @@ typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec; #define CC_BUILD_X11 #define CC_BUILD_POSIX #endif +#ifdef __NetBSD__ +#define CC_BUILD_NETBSD +#define CC_BUILD_X11 +#define CC_BUILD_POSIX +#endif #ifdef __EMSCRIPTEN__ #define CC_BUILD_WEB #define CC_BUILD_SDL diff --git a/src/Platform.c b/src/Platform.c index ffdc9c587..89c7a8e48 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -93,6 +93,8 @@ const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK; #elif defined CC_BUILD_OPENBSD #define CC_BUILD_UNIX #include +#elif defined CC_BUILD_NETBSD +#define CC_BUILD_UNIX #elif defined CC_BUILD_SOLARIS #define CC_BUILD_UNIX #include @@ -320,7 +322,18 @@ void DateTime_CurrentLocal(struct DateTime* time_) { #define NS_PER_SEC 1000000000ULL #endif -#if defined CC_BUILD_LINUX || defined CC_BUILD_FREEBSD || defined CC_BUILD_OPENBSD +/* clock_gettime is optional, see http://pubs.opengroup.org/onlinepubs/009696899/functions/clock_getres.html */ +/* "... These functions are part of the Timers option and need not be available on all implementations..." */ +#if defined CC_BUILD_WEB +uint64_t Stopwatch_Measure(void) { + /* time is a milliseconds double */ + return (uint64_t)(emscripten_get_now() * 1000); +} +#elif defined CC_BUILD_OSX +uint64_t Stopwatch_Measure(void) { return mach_absolute_time(); } +#elif defined CC_BUILD_SOLARIS +uint64_t Stopwatch_Measure(void) { return gethrtime(); } +#elif defined CC_BUILD_UNIX uint64_t Stopwatch_Measure(void) { struct timespec t; /* TODO: CLOCK_MONOTONIC_RAW ?? */ @@ -328,22 +341,6 @@ uint64_t Stopwatch_Measure(void) { return (uint64_t)t.tv_sec * NS_PER_SEC + t.tv_nsec; } #endif -#ifdef CC_BUILD_SOLARIS -uint64_t Stopwatch_Measure(void) { - return gethrtime(); -} -#endif -#ifdef CC_BUILD_OSX -uint64_t Stopwatch_Measure(void) { - return mach_absolute_time(); -} -#endif -#ifdef CC_BUILD_WEB -uint64_t Stopwatch_Measure(void) { - /* time is a milliseconds double */ - return (uint64_t)(emscripten_get_now() * 1000); -} -#endif /*########################################################################################################################* @@ -1247,6 +1244,12 @@ static void Font_Init(void) { String_FromConst("C:/Windows/Fonts"), String_FromConst("C:/WINNT/Fonts") }; +#elif defined CC_BUILD_NETBSD + const static String dirs[3] = { + String_FromConst("/usr/X11R7/lib/X11/fonts"), + String_FromConst("/usr/pkg/lib/X11/fonts"), + String_FromConst("/usr/pkg/share/fonts") + }; #elif defined CC_BUILD_UNIX const static String dirs[2] = { String_FromConst("/usr/share/fonts"), @@ -1945,6 +1948,24 @@ ReturnCode Process_GetExePath(String* path) { return 0; } #endif +#ifdef CC_BUILD_NETBSD +ReturnCode Process_GetExePath(String* path) { + char str[600]; + int mib[4]; + size_t size = 600; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC_ARGS; + mib[2] = -1; /* self process id */ + mib[2] = KERN_PROC_PATHNAME; + + if (sysctl(mib, 4, str, &size, NULL, 0) == -1) return errno; + + size = String_CalcLen(str, 600); + Convert_DecodeUtf8(path, str, size); + return 0; +} +#endif #ifdef CC_BUILD_SOLARIS ReturnCode Process_GetExePath(String* path) { char str[600];