From 74cbcc28af13207ffc7e1c9c1dbd2b9e3fc7f30b Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Thu, 28 Jul 2022 10:59:56 +0700 Subject: [PATCH] Added support for building on Linux (incl. Android/WSL) This does not require a compatibility layer (Darling) nor a toolchain (Theos). Instead, clang and lld from Linux distribution is used with iOS SDK to compile the natives part (C/Objective-C). Of course, this also allows compiling on Android with Termux or Windows with WSL. --- Makefile | 34 +++++++++++++++++++++++++--------- Natives/AppDelegate.h | 2 +- Natives/CMakeLists.txt | 14 +++++++++++++- Natives/non_darwin_utils.m | 11 +++++++++++ 4 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 Natives/non_darwin_utils.m diff --git a/Makefile b/Makefile index 3586c8d2..e697710d 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,12 @@ DEVICE_IP ?= 127.0.0.1 DEVICE_PORT ?= 22 $(warning Building on a jailbroken iOS device.) endif +else ifeq ($(DETECTPLAT),Linux) +$(warning Building on Linux. Note that all targets may not compile or require external components.) +IOS := 0 +# SDKPATH presence is checked later +BOOTJDK ?= /usr/bin +SYSARCH := $(shell uname -m) else $(error This platform is not currently supported for building PojavLauncher.) endif @@ -132,23 +138,23 @@ DEPLOY = \ ldid -S$(SOURCEDIR)/entitlements.xml $(WORKINGDIR)/PojavLauncher.app/PojavLauncher; \ if [ '$(2)' = '0' ]; then \ scp -r -P $(DEVICE_PORT) -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" \ - $(WORKINGDIR)/libOSMesaOverride.dylib.framework \ - $(WORKINGDIR)/libawt_xawt.dylib \ + $(WORKINGDIR)/*.framework \ + $(WORKINGDIR)/*.dylib \ $(WORKINGDIR)/PojavLauncher.app/PojavLauncher \ $(SOURCEDIR)/JavaApp/local_out/*.jar \ root@$(DEVICE_IP):/var/tmp/; \ ssh root@$(DEVICE_IP) -p $(DEVICE_PORT) -t " \ - mv /var/tmp/libawt_xawt.dylib $(1)/Applications/PojavLauncher.app/Frameworks/libawt_xawt.dylib && \ - mv /var/tmp/libOSMesaOverride.dylib.framework $(1)/Applications/PojavLauncher.app/Frameworks/libOSMesaOverride.dylib.framework && \ + mv /var/tmp/*.dylib $(1)/Applications/PojavLauncher.app/Frameworks/ && \ + mv /var/tmp/*.framework $(1)/Applications/PojavLauncher.app/Frameworks/ && \ mv /var/tmp/PojavLauncher $(1)/Applications/PojavLauncher.app/PojavLauncher && \ mv /var/tmp/*.jar $(1)/Applications/PojavLauncher.app/libs/ && \ cd $(1)/Applications/PojavLauncher.app/Frameworks && \ ln -sf libawt_xawt.dylib libawt_headless.dylib && \ chown -R 501:501 $(1)/Applications/PojavLauncher.app/*"; \ else \ - sudo rm -rf $(1)/Applications/PojavLauncher.app/Frameworks/libOSMesaOverride.dylib.framework; \ - sudo mv $(WORKINGDIR)/libawt_xawt.dylib $(1)/Applications/PojavLauncher.app/Frameworks/libawt_xawt.dylib; \ - sudo mv $(WORKINGDIR)/libOSMesaOverride.dylib.framework $(1)/Applications/PojavLauncher.app/Frameworks/; \ + sudo rm -rf $(1)/Applications/PojavLauncher.app/Frameworks/{libOSMesaOverride.dylib,MetalANGLE}.framework; \ + sudo mv $(WORKINGDIR)/*.dylib $(1)/Applications/PojavLauncher.app/Frameworks/; \ + sudo mv $(WORKINGDIR)/*.framework $(1)/Applications/PojavLauncher.app/Frameworks/; \ sudo mv $(WORKINGDIR)/PojavLauncher.app/PojavLauncher $(1)/Applications/PojavLauncher.app/PojavLauncher; \ sudo mv $(SOURCEDIR)/JavaApp/local_out/*.jar $(1)/Applications/PojavLauncher.app/libs/; \ cd $(1)/Applications/PojavLauncher.app/Frameworks; \ @@ -183,6 +189,12 @@ ifeq ($(call HAS_COMMAND,dpkg-deb --version),1) $(error You need to install dpkg-dev) endif +ifeq ($(DETECTPLAT),Linux) +ifeq ($(call HAS_COMMAND,lld),1) +$(error You need to install lld) +endif +endif + ifeq ($(call HAS_COMMAND,nproc --version),1) ifeq ($(call HAS_COMMAND,gnproc --version),1) $(warning Unable to determine number of threads, defaulting to 2.) @@ -194,6 +206,10 @@ else JOBS ?= $(shell nproc) endif +ifndef SDKPATH +$(error You need to specify SDKPATH to the path of iPhoneOS.sdk. The SDK version should be 14.0 or newer.) +endif + # Now for the actual Makefile recipes. # all - runs clean, native, java, extras, and package. # check - Makes sure that all variables are correct. @@ -282,9 +298,9 @@ deb: native java extras $(call DIRCHECK,$(WORKINGDIR)/PojavLauncher.app/libs) $(call DIRCHECK,$(WORKINGDIR)/PojavLauncher.app/libs_caciocavallo) @cp -R $(SOURCEDIR)/Natives/resources/* $(WORKINGDIR)/PojavLauncher.app/ || exit 1 - @cp $(WORKINGDIR)/libawt_xawt.dylib $(WORKINGDIR)/PojavLauncher.app/Frameworks/ || exit 1 + @cp $(WORKINGDIR)/*.dylib $(WORKINGDIR)/PojavLauncher.app/Frameworks/ || exit 1 @( cd $(WORKINGDIR)/PojavLauncher.app/Frameworks; ln -sf libawt_xawt.dylib libawt_headless.dylib ) || exit 1 - @cp -R $(WORKINGDIR)/libOSMesaOverride.dylib.framework $(WORKINGDIR)/PojavLauncher.app/Frameworks/ || exit 1 + @cp -R $(WORKINGDIR)/*.framework $(WORKINGDIR)/PojavLauncher.app/Frameworks/ || exit 1 @cp -R $(SOURCEDIR)/JavaApp/libs/* $(WORKINGDIR)/PojavLauncher.app/libs/ || exit 1 @cp $(SOURCEDIR)/JavaApp/local_out/*.jar $(WORKINGDIR)/PojavLauncher.app/libs/ || exit 1 @cp -R $(SOURCEDIR)/JavaApp/libs_caciocavallo/* $(WORKINGDIR)/PojavLauncher.app/libs_caciocavallo/ || exit 1 diff --git a/Natives/AppDelegate.h b/Natives/AppDelegate.h index 451791d3..d7b7becf 100644 --- a/Natives/AppDelegate.h +++ b/Natives/AppDelegate.h @@ -2,7 +2,7 @@ // AppDelegate.h // -#import "MGLKit.h" +#import @interface AppDelegate : UIResponder diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 86982cc0..716cac8b 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -1,9 +1,15 @@ cmake_minimum_required(VERSION 3.6) project(PojavLauncher) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon -fobjc-arc -ObjC") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target arm64-apple-ios -fcommon -fobjc-arc -ObjC") set(CMAKE_C_FLAGS_DEBUG "-funwind-tables -g") +if("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "Linux|^GNU$|Android") +set(GLOBAL_LDFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} -Wl,-syslibroot,${CMAKE_OSX_SYSROOT} -fuse-ld=lld") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GLOBAL_LDFLAGS}") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GLOBAL_LDFLAGS}") +endif() + include_directories( "resources/Frameworks/Alderis.framework/Headers" "external/AFNetworking/AFNetworking" @@ -48,6 +54,7 @@ set_target_properties(libOSMesaOverride.dylib PROPERTIES MACOSX_FRAMEWORK_IDENTIFIER dylib.mesa3d.libOSMesaOverride ) target_link_libraries(libOSMesaOverride.dylib + "${GLOBAL_LDFLAGS}" "${OSMESA_LIB}" ) @@ -57,6 +64,7 @@ add_library(tinygl4angle SHARED external/gl4es/tinygl4angle.c ) target_link_libraries(tinygl4angle + "${GLOBAL_LDFLAGS}" "-F'${CMAKE_CURRENT_LIST_DIR}/resources/Frameworks'" "-framework MetalANGLE" ) @@ -118,6 +126,10 @@ add_executable(PojavLauncher utils.m ) +if("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "Linux|^GNU$|Android") +target_sources(PojavLauncher PUBLIC non_darwin_utils.m) +endif() + target_link_libraries(PojavLauncher "-F'${CMAKE_CURRENT_LIST_DIR}/build'" "-F'${CMAKE_CURRENT_LIST_DIR}/resources/Frameworks'" diff --git a/Natives/non_darwin_utils.m b/Natives/non_darwin_utils.m new file mode 100644 index 00000000..706c6e23 --- /dev/null +++ b/Natives/non_darwin_utils.m @@ -0,0 +1,11 @@ +#import + +// This is only compiled when building on non-Apple platforms + +int __isPlatformVersionAtLeast(int platform, int major, int minor, int patch) { + NSOperatingSystemVersion version; + version.majorVersion = major; + version.minorVersion = minor; + version.patchVersion = patch; + return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version]; +}