From 31af27529e0eb6958ae879d54fc09818395e4296 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 4 Oct 2023 23:20:57 +0000 Subject: [PATCH] This compiles on macos for x86_64, at least. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4485 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 52 +++++++++++++++++++++++++++++++++++++++++++------ src/bcrypt.js.c | 6 ++++++ src/main.c | 9 ++++++--- src/mem.c | 8 ++++---- src/task.c | 11 +++++++---- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 63e5ed2b..6b35873d 100644 --- a/Makefile +++ b/Makefile @@ -9,20 +9,18 @@ VERSION_NAME := Be nothing, and you will have everything to give to others. PROJECT = tildefriends BUILD_DIR ?= out -BUILD_TYPES := debug release windebug winrelease androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androidrelease-armv7a +BUILD_TYPES := debug release windebug winrelease macosdebug macosrelease androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androidrelease-armv7a UNAME_M := $(shell uname -m) CFLAGS += \ -Wall \ -Wextra \ -Wno-unused-parameter \ - -Wno-cast-function-type \ -MMD \ -ffunction-sections \ -fdata-sections \ -fno-exceptions \ -g -LDFLAGS += -Wl,--gc-sections ANDROID_SDK ?= ~/Android/Sdk ANDROID_BUILD_TOOLS := $(ANDROID_SDK)/build-tools/33.0.1 @@ -47,10 +45,15 @@ ANDROID_TARGETS := \ $(ANDROID_X86_64_TARGETS) \ $(ANDROID_ARMV7A_TARGETS) \ $(ANDROID_ARM64_TARGETS) +MACOS_TARGETS := \ + out/macosdebug/tildefriends \ + out/macosrelease/tildefriends +NONMACOS_TARGETS := $(filter-out $(MACOS_TARGETS),$(DEBUG_TARGETS) $(RELEASE_TARGETS)) DEBUG_TARGETS := \ out/debug/tildefriends \ out/windebug/tildefriends \ + out/macosdebug/tildefriends \ out/androiddebug/tildefriends \ out/androiddebug-armv7a/tildefriends \ out/androiddebug-x86_64/tildefriends \ @@ -58,6 +61,7 @@ DEBUG_TARGETS := \ RELEASE_TARGETS := \ out/release/tildefriends \ out/winrelease/tildefriends \ + out/macosrelease/tildefriends \ out/androidrelease/tildefriends \ out/androidrelease-armv7a/tildefriends \ out/androidrelease-x86_64/tildefriends \ @@ -91,6 +95,9 @@ windebug winrelease: LDFLAGS += \ -static \ -lm \ -Ldeps/openssl/mingw64/lib +$(MACOS_TARGETS): CC = xcrun clang +$(NONMACOS_TARGETS): CFLAGS += -Wno-cast-function-type +$(NONMACOS_TARGETS): LDFLAGS += -Wl,--gc-sections $(ANDROID_X86_64_TARGETS): ANDROID_NDK_TARGET_TRIPLE := x86_64-linux-android $(ANDROID_X86_TARGETS): ANDROID_NDK_TARGET_TRIPLE := i686-linux-android $(ANDROID_ARMV7A_TARGETS): ANDROID_NDK_TARGET_TRIPLE := armv7a-linux-androideabi @@ -121,6 +128,7 @@ get_objs = \ $(foreach build_type,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) \ $(foreach build_type,androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androiddebug-armv7a,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_android))))) \ $(foreach build_type,androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androidrelease-armv7a,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ + $(foreach build_type,macosdebug macosrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_macos))))) \ $(foreach build_type,androiddebug-x86 androidrelease-x86,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_x86))))) APP_SOURCES := $(wildcard src/*.c) @@ -142,7 +150,7 @@ $(APP_OBJS): CFLAGS += \ -Wdouble-promotion \ -Werror ifeq ($(UNAME_M),x86_64) -$(filter-out $(BUILD_DIR)/android%,$(APP_OBJS)): CFLAGS += \ +$(filter-out $(BUILD_DIR)/android% $(BUILD_DIR)/macos%,$(APP_OBJS)): CFLAGS += \ -fanalyzer endif @@ -220,6 +228,32 @@ UV_SOURCES_win := \ deps/libuv/src/win/util.c \ deps/libuv/src/win/winapi.c \ deps/libuv/src/win/winsock.c +UV_SOURCES_macos := \ + deps/libuv/src/unix/async.c \ + deps/libuv/src/unix/bsd-ifaddrs.c \ + deps/libuv/src/unix/core.c \ + deps/libuv/src/unix/darwin.c \ + deps/libuv/src/unix/darwin-proctitle.c \ + deps/libuv/src/unix/dl.c \ + deps/libuv/src/unix/fs.c \ + deps/libuv/src/unix/fsevents.c \ + deps/libuv/src/unix/getaddrinfo.c \ + deps/libuv/src/unix/getnameinfo.c \ + deps/libuv/src/unix/kqueue.c \ + deps/libuv/src/unix/loop-watcher.c \ + deps/libuv/src/unix/loop.c \ + deps/libuv/src/unix/pipe.c \ + deps/libuv/src/unix/poll.c \ + deps/libuv/src/unix/process.c \ + deps/libuv/src/unix/proctitle.c \ + deps/libuv/src/unix/random-devurandom.c \ + deps/libuv/src/unix/random-getentropy.c \ + deps/libuv/src/unix/signal.c \ + deps/libuv/src/unix/stream.c \ + deps/libuv/src/unix/tcp.c \ + deps/libuv/src/unix/thread.c \ + deps/libuv/src/unix/tty.c \ + deps/libuv/src/unix/udp.c UV_OBJS := $(call get_objs,UV_SOURCES) $(UV_OBJS): CFLAGS += \ -Ideps/libuv/include \ @@ -371,6 +405,12 @@ LIBBACKTRACE_SOURCES_win := \ deps/libbacktrace/pecoff.c \ deps/libbacktrace/posix.c \ deps/libbacktrace/read.c +LIBBACKTRACE_SOURCES_macos := \ + deps/libbacktrace/dwarf.c \ + deps/libbacktrace/macho.c \ + deps/libbacktrace/mmap.c \ + deps/libbacktrace/mmapio.c \ + deps/libbacktrace/posix.c LIBBACKTRACE_OBJS := $(call get_objs,LIBBACKTRACE_SOURCES) $(LIBBACKTRACE_OBJS): CFLAGS += \ -Ideps/libbacktrace_config \ @@ -400,7 +440,7 @@ $(MINIUNZIP_OBJS): CFLAGS += \ LDFLAGS += \ -pthread \ -lm -debug release: LDFLAGS += \ +debug release $(MACOS_TARGETS): LDFLAGS += \ -ldl \ -lssl \ -lcrypto @@ -449,7 +489,7 @@ $(1): $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe) $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe): $(filter $(BUILD_DIR)/$(1)/%,$(ALL_APP_OBJS)) @echo [link] $$@ - @$$(CC) -o $$@ -Wl,-Map,$$@.map $$^ $$(LDFLAGS) + @$$(CC) -o $$@ $$^ $$(LDFLAGS) $(BUILD_DIR)/$(1)/%.o: %.c @mkdir -p $$(dir $$@) diff --git a/src/bcrypt.js.c b/src/bcrypt.js.c index 46f711d3..f4921d9a 100644 --- a/src/bcrypt.js.c +++ b/src/bcrypt.js.c @@ -44,6 +44,12 @@ JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSVa char buffer[16]; #if defined(_WIN32) ssize_t bytes = SystemFunction036(buffer, sizeof(buffer)) ? sizeof(buffer) : 0; +#elif defined(__APPLE__) + ssize_t bytes = 0; + if (getentropy(buffer, sizeof(buffer)) == 0) + { + bytes = sizeof(buffer); + } #else ssize_t bytes = getrandom(buffer, sizeof(buffer), 0); #endif diff --git a/src/main.c b/src/main.c index 3b9d0592..102dd926 100644 --- a/src/main.c +++ b/src/main.c @@ -16,10 +16,13 @@ #include #include -#if !defined(_WIN32) && !defined(__MACH__) +#if !defined(_WIN32) && !defined(__APPLE__) #include #include #include +#endif + +#if !defined(_WIN32) #include #endif @@ -471,7 +474,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[]) return 2; } -#if !defined(_WIN32) && !defined(__MACH__) +#if !defined(_WIN32) && !defined(__APPLE__) prctl(PR_SET_PDEATHSIG, SIGHUP); #endif tf_task_t* task = tf_task_create(); @@ -591,7 +594,7 @@ int main(int argc, char* argv[]) _backtrace_error, NULL); -#if !defined(_WIN32) +#if !defined(_WIN32) && !defined(__APPLE__) prctl(PR_SET_PDEATHSIG, SIGKILL); #endif tf_mem_replace_uv_allocator(); diff --git a/src/mem.c b/src/mem.c index 428bcdd9..ca28864e 100644 --- a/src/mem.c +++ b/src/mem.c @@ -207,7 +207,7 @@ tf_mem_allocation_t* tf_mem_summarize_allocations(int* out_count) return result; } -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" #endif @@ -306,7 +306,7 @@ static void* _tf_realloc(int64_t* total, void* ptr, size_t size) return NULL; } } -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__APPLE__) #pragma GCC diagnostic pop #endif @@ -334,7 +334,7 @@ static void* _tf_uv_realloc(void* ptr, size_t size) return _tf_realloc(&s_uv_malloc_size, ptr, size); } -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" #endif @@ -372,7 +372,7 @@ static void* _tf_uv_calloc(size_t nmemb, size_t size) return NULL; } } -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__APPLE__) #pragma GCC diagnostic pop #endif diff --git a/src/task.c b/src/task.c index a36a30a6..d51a8c02 100644 --- a/src/task.c +++ b/src/task.c @@ -25,14 +25,17 @@ #include -#ifndef _WIN32 +#include +#include +#include + +#if !defined(_WIN32) #include #endif -#include +#if !defined(__APPLE__) #include -#include -#include +#endif #if !defined(_countof) #define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))