From f7c51ee019c0cffdc200a4fd4f82ce7cd6e89d61 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Sat, 21 Sep 2024 15:47:01 -0400 Subject: [PATCH] Basic work toward compiling on Darwin --- configure | 2 +- include/Cytoplasm/Platform.h | 66 ++++++++++++++++++++++++++++++++++++ src/Util.c | 9 +++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 include/Cytoplasm/Platform.h diff --git a/configure b/configure index deb186e..a1331ef 100755 --- a/configure +++ b/configure @@ -37,7 +37,7 @@ case "$(uname)" in # These systems typically use GCC. SCRIPT_ARGS="${SCRIPT_ARGS} --cc=gcc" ;; - OpenBSD|FreeBSD) + OpenBSD|FreeBSD|Darwin) # These systems typically use Clang. SCRIPT_ARGS="${SCRIPT_ARGS} --cc=clang" ;; diff --git a/include/Cytoplasm/Platform.h b/include/Cytoplasm/Platform.h new file mode 100644 index 0000000..a15da6f --- /dev/null +++ b/include/Cytoplasm/Platform.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef CYTOPLASM_PLATFORM_H +#define CYTOPLASM_PLATFORM_H + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) + #define PLATFORM_WINDOWS + + #ifdef _WIN64 + #define PLATFORM_WIN64 + #else + #define PLATFORM_WIN32 + #endif +#elif __APPLE__ + #define PLATFORM_DARWIN + + #include + #if TARGET_IPHONE_SIMULATOR + // iOS, tvOS, or watchOS Simulator + #define PLATFORM_IPHONE + #elif TARGET_OS_MACCATALYST + // Mac's Catalyst (ports iOS API into Mac, like UIKit). + #define PLATFORM_CATALYST + #elif TARGET_OS_IPHONE + // iOS, tvOS, or watchOS device + #define PLATFORM_IPHONE + #elif TARGET_OS_MAC + // Other kinds of Apple platforms + #define PLATFORM_MAC + #else + # error "Unknown Apple platform" + #endif +#elif __ANDROID__ + #define PLATFORM_ANDROID +#elif __linux__ + #define PLATFORM_LINUX +#elif __unix__ // all unices not caught above + #define PLATFORM_UNIX +#elif defined(_POSIX_VERSION) + #define PLATFORM_POSIX +#else +# error "Unknown compiler" +#endif + +#endif // CYTOPLASM_PLATFORM_H diff --git a/src/Util.c b/src/Util.c index 962ff0b..e01ae4f 100644 --- a/src/Util.c +++ b/src/Util.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -89,6 +90,10 @@ UtilTsMillis(void) return ts; } +#ifdef PLATFORM_DARWIN +#define st_mtim st_mtimespec +#endif + uint64_t UtilLastModified(char *path) { @@ -105,6 +110,10 @@ UtilLastModified(char *path) return ts; } +#ifdef PLATFORM_DARWIN +#undef st_mtim +#endif + int UtilMkdir(const char *dir, const mode_t mode) {