From fa9af3227e734d01b7052976f4ea2d0b057ef3cc Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Thu, 14 May 2020 23:47:00 +0800 Subject: [PATCH] Make the code buildable on MinGW.org (not mingw-w64) and MSYS1. --- include/PR/ultratypes.h | 4 ++++ include/ultra64.h | 6 ++++++ src/pc/gfx/gfx_pc.c | 14 ++++++++++++++ tools/utils.h | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8a00490a..8d590542 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -38,7 +38,11 @@ typedef s32 ptrdiff_t; #else #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +typedef long ssize_t; +#else typedef ptrdiff_t ssize_t; #endif +#endif #endif diff --git a/include/ultra64.h b/include/ultra64.h index 409a3cf7..94bbc388 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,4 +30,10 @@ #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) +#define bcopy(s1, s2, n) memmove((s2), (s1), (n)) +#endif + #endif diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d674a4d6..72147886 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -153,7 +153,21 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; +#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define CLOCK_MONOTONIC 0 +//https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows +struct timespec { long tv_sec; long tv_nsec; }; //header part +int clock_gettime(int arg, struct timespec *spec) //C-file part +{ __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -=116444736000000000LL; //1jan1601 to 1jan1970 + spec->tv_sec =wintime / 10000000LL; //seconds + spec->tv_nsec =wintime % 10000000LL*100; //nano-seconds + return 0; +} +#else #include +#endif static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); diff --git a/tools/utils.h b/tools/utils.h index dff1d6a3..03f482d0 100644 --- a/tools/utils.h +++ b/tools/utils.h @@ -7,8 +7,9 @@ // printing size_t varies by compiler #if defined(_MSC_VER) || defined(__MINGW32__) + #include #define SIZE_T_FORMAT "%Iu" - #define realpath(N,R) _fullpath((R),(N),_MAX_PATH) + #define realpath(N,R) _fullpath((R),(N),MAX_PATH) #else #define SIZE_T_FORMAT "%zu" #endif