diff --git a/Makefile b/Makefile index 4c98cfef..d49f4201 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ MAKEFLAGS += --no-builtin-rules PROJECT = tildefriends BUILD_DIR ?= out -BUILD_TYPES := debug release windebug winrelease +BUILD_TYPES := debug release windebug winrelease androiddebug androidrelease UNAME_M := $(shell uname -m) CFLAGS += \ @@ -20,13 +20,27 @@ CFLAGS += \ -g LDFLAGS += -Wl,-gc-sections -debug windebug: CFLAGS += -Og -debug release: LDFLAGS += -rdynamic +NDK_PATH := /usr/lib/android-sdk/ndk-bundle +NDK_SSL_PATH := deps/openssl_android +NDK_API_VERSION := 30 +NDK_TARGET_TRIPLE := aarch64-linux-android + +debug windebug androiddebug: CFLAGS += -Og +debug release androidrelease: LDFLAGS += -rdynamic release winrelease: CFLAGS += -DNDEBUG -O3 windebug winrelease: CC = i686-w64-mingw32-gcc-win32 windebug winrelease: AS = $(CC) windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10 windebug winrelease: LDFLAGS += -static +androiddebug androidrelease: CC = $(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64/bin/clang +androiddebug androidrelease: AS = $(CC) +androiddebug androidrelease: CFLAGS += \ + -target $(NDK_TARGET_TRIPLE)$(NDK_API_VERSION) \ + -I$(NDK_SSL_PATH)/arm64-v8a/usr/local/include \ + -Wno-unknown-warning-option +androiddebug androidrelease: LDFLAGS += \ + -target $(NDK_TARGET_TRIPLE)$(NDK_API_VERSION) \ + -L$(NDK_SSL_PATH)/arm64-v8a/usr/local/lib ifeq ($(UNAME_M),x86_64) debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common @@ -36,7 +50,9 @@ endif get_objs = \ $(foreach build_type,$(BUILD_TYPES),$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ $(foreach build_type,debug release,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ - $(foreach build_type,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) + $(foreach build_type,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) \ + $(foreach build_type,androiddebug androidrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_android))))) \ + $(foreach build_type,androiddebug androidrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) APP_SOURCES := $(wildcard src/*.c) APP_OBJS := $(call get_objs,APP_SOURCES) @@ -105,6 +121,9 @@ UV_SOURCES_unix := \ deps/libuv/src/unix/thread.c \ deps/libuv/src/unix/tty.c \ deps/libuv/src/unix/udp.c +UV_SOURCES_android := \ + deps/libuv/src/unix/pthread-fixes.c \ + deps/libuv/src/unix/random-getentropy.c UV_SOURCES_win := \ deps/libuv/src/win/async.c \ deps/libuv/src/win/core.c \ @@ -282,6 +301,10 @@ windebug winrelease: LDFLAGS += \ -lkernel32 \ -liphlpapi \ -luserenv +androiddebug androidrelease: LDFLAGS += \ + -ldl \ + -lssl \ + -lcrypto unix: debug release win: windebug winrelease diff --git a/src/task.c b/src/task.c index 810d0a65..8e6c1921 100644 --- a/src/task.c +++ b/src/task.c @@ -29,7 +29,9 @@ #include #ifndef _WIN32 +#ifndef __ANDROID__ #include +#endif #include #endif @@ -1147,7 +1149,7 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise) #ifdef _WIN32 count = CaptureStackBackTrace(0, sizeof(buffer) / sizeof(*buffer), buffer, NULL); stack_hash = fnv32a((const void*)buffer, sizeof(void*) * count, stack_hash); -#else +#elif !defined(__ANDROID__) count = backtrace(buffer, sizeof(buffer) / sizeof(*buffer)); stack_hash = fnv32a((const void*)buffer, sizeof(void*) * count, stack_hash); #endif