diff --git a/README.md b/README.md index 3691189e..c93292f3 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ To build you should clone [SDL](https://github.com/libsdl-org/SDL) from `SDL2` b 0) (optional) Examine which build options are available: `./waf --help`. 1) Configure build: `./waf configure --ios --enable-bundled-deps --sdl2 (path/to/SDL2.framework)`, set `--ios-simulator` instead of `--ios` if you want to build for simulator. 2) Compile `./waf build`. -3) Navigate to `build` and copy your compiled SDL2.framework there, then add your client dylibs to `build/ios/cl_dlls` and any other dylibs to `build/ios/dlls` (You can also run `scripts/ios/buildhlsdk.sh` instead to automatically create an ipa with hlsdk dylibs) +3) Navigate to `build` and copy your compiled SDL2.framework there, then add your game dylibs to `build/ios/libs/(gamedir)/(dlls/cl_dlls)`(You can also run `scripts/ios/buildhlsdk.sh` instead to automatically create an ipa with hlsdk dylibs) 4) Run `scripts/ios/createipa.sh` to create an installable ipa ### Running tests diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index 59e56d36..71a0bf18 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -16,6 +16,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#include "xash3d_types.h" #if XASH_SDL == 2 #include // SDL_GetBasePath #elif XASH_SDL == 3 @@ -320,6 +321,11 @@ static qboolean FS_DetermineReadOnlyRootDirectory( char *out, size_t size ) return true; } +#if XASH_IOS + Q_strncpy(out, IOS_GetExecDir(), size); + return true; +#endif + return false; } diff --git a/engine/platform/ios/launchdialog.m b/engine/platform/ios/launchdialog.m index 879aaeb3..9c552ba6 100644 --- a/engine/platform/ios/launchdialog.m +++ b/engine/platform/ios/launchdialog.m @@ -78,6 +78,21 @@ const char *IOS_GetDocsDir(void) } } +const char *IOS_GetExecDir(void) +{ + static const char *dir = NULL; + + if( dir ) + return dir; + + NSString *executableDirctory = [[NSBundle mainBundle] bundlePath]; + + dir = [executableDirctory fileSystemRepresentation]; + NSLog(@"IOS_GetDocsDir: %s", dir); + + return dir; +} + UIBackgroundTaskIdentifier task; FtpServer *server = NULL; diff --git a/engine/platform/ios/lib_ios.c b/engine/platform/ios/lib_ios.c deleted file mode 100644 index 66ebba17..00000000 --- a/engine/platform/ios/lib_ios.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -ios_lib.c - dynamic library code for iOS -Copyright (C) 2017-2018 mittorn - -This program is free software: you can redistribute it and/sor modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -*/ -#include -#include -#include -#include -#include -#include "crtlib.h" -#include "library.h" -#include "platform/ios/lib_ios.h" -#include "common.h" - -const char *g_szLibrarySuffix; - -static void *IOS_LoadLibraryInternal( const char *dllname ) -{ - void *pHandle; - char path[MAX_SYSPATH]; - - Q_snprintf( path, sizeof( path ), "%s%s", SDL_GetBasePath(), dllname ); - pHandle = dlopen( path, RTLD_LAZY ); - - if( !pHandle ) - COM_PushLibraryError(dlerror( )); - - return pHandle; -} - -static qboolean IOS_LibraryExistsInternal( const char *name ) -{ - struct stat buf; - char path[MAX_SYSPATH]; - - Q_snprintf( path, sizeof( path ), "%s%s", SDL_GetBasePath(), name ); - - return stat( path, &buf ) == 0; -} - -static const char *IOS_GetLibraryPostfix( void ) -{ - if( g_szLibrarySuffix ) - return g_szLibrarySuffix; - - return Q_strcmp( host.default_gamedir, FS_Gamedir( )) ? FS_Gamedir( ) : ""; -} - -static void IOS_PrepareGameLibraryPath( const char *dllname, char *out, size_t outsize ) -{ - string strippedname; - - Q_strncpy( strippedname, dllname, sizeof( strippedname )); - COM_StripExtension( strippedname ); - - Q_snprintf( out, outsize, "%s_%s.dylib", strippedname, IOS_GetLibraryPostfix( )); -} - -void *IOS_LoadLibrary( const char *dllname ) -{ - // filesystem_stdio is a special case, as engine won't work correctly without it - // but it's always located at known path - if( !Q_strcmp( dllname, "filesystem_stdio.dylib" )) - return IOS_LoadLibraryInternal( dllname ); - - string name; - char *pHandle; - - IOS_PrepareGameLibraryPath( dllname, name, sizeof( name )); - pHandle = IOS_LoadLibraryInternal( name ); - - if( !pHandle ) - pHandle = IOS_LoadLibraryInternal( dllname ); - - return pHandle; -} - -qboolean IOS_LibraryExists( const char *dllname ) -{ - string name; - - IOS_PrepareGameLibraryPath( dllname, name, sizeof( name )); - - return IOS_LibraryExistsInternal( name ) || IOS_LibraryExistsInternal( dllname ); -} diff --git a/engine/platform/ios/lib_ios.h b/engine/platform/ios/lib_ios.h deleted file mode 100644 index 67bd8bfa..00000000 --- a/engine/platform/ios/lib_ios.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -ios_lib.h - dynamic library code for iOS -Copyright (C) 2017-2018 mittorn - -This program is free software: you can redistribute it and/sor modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -*/ -#pragma once -#if TARGET_OS_IPHONE -#ifndef IOS_LIB_H -#define IOS_LIB_H - -#define Platform_POSIX_LoadLibrary( x ) IOS_LoadLibrary(( x )) - -void *IOS_LoadLibrary( const char *dllname ); -qboolean IOS_LibraryExists( const char *name ); - -#endif // IOS_LIB_H -#endif // TARGET_OS_IPHONE diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 0d214936..d478ed33 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -41,11 +41,11 @@ void Platform_SetStatus( const char *status ); qboolean Platform_DebuggerPresent( void ); // legacy iOS port functions -#if TARGET_OS_IOS +#if XASH_IOS int IOS_GetArgs( char ***argv ); const char *IOS_GetDocsDir( void ); +const char *IOS_GetExecDir( void ); void IOS_LaunchDialog( void ); -#include "platform/ios/lib_ios.h" #endif // TARGET_OS_IOS #if XASH_WIN32 || XASH_LINUX @@ -212,9 +212,7 @@ static inline void Sys_RestoreCrashHandler( void ) static inline qboolean Platform_LibraryExists( const char *name, qboolean gamedironly ) { -#if XASH_IOS - return IOS_LibraryExists( name ); -#elif XASH_ANDROID +#if XASH_ANDROID // sorry, unimplemented return false; #else diff --git a/engine/platform/posix/lib_posix.c b/engine/platform/posix/lib_posix.c index babb38dd..9c34f386 100644 --- a/engine/platform/posix/lib_posix.c +++ b/engine/platform/posix/lib_posix.c @@ -36,7 +36,6 @@ GNU General Public License for more details. #include "filesystem.h" #include "server.h" #include "platform/android/lib_android.h" -#include "platform/ios/lib_ios.h" #ifdef XASH_NO_LIBDL void *dlsym( void *handle, const char *symbol ) diff --git a/scripts/ios/buildhlsdk.sh b/scripts/ios/buildhlsdk.sh index 015109ee..9091575c 100755 --- a/scripts/ios/buildhlsdk.sh +++ b/scripts/ios/buildhlsdk.sh @@ -12,20 +12,19 @@ else git clone --recursive https://github.com/FWGS/hlsdk-portable -b "$1" "$MODPATH" fi -mkdir -p ../../build/ios || exit 1 -IOSDIR=$(realpath ../../build/ios) +if [ ! -d ../../build/ios/libs ]; then + mkdir ../../build/ios/libs || exit 1 +fi + +LIBSDIR=$(realpath ../../build/ios/libs) cd "$MODPATH" || exit 1 #compiling hlsdk for ios release is broken, so just build for debug -cmake -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DGAMEDIR="$IOSDIR" -DCMAKE_BUILD_TYPE=Debug -B build -S . +cmake -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT=0 -DCMAKE_INSTALL_PREFIX="$LIBSDIR" -DCMAKE_BUILD_TYPE=Debug -B build -S . cmake --build build --target install -if [ ! -z "$2" ]; then - mv "$IOSDIR/cl_dlls/client_arm64.dylib" "$IOSDIR/cl_dlls/client_arm64$2.dylib" -else - cd ../../ - ./createipa.sh -fi +cd ../../ +./createipa.sh if [ -d mod-build ]; then rm -rf mod-build/ diff --git a/scripts/ios/createipa.sh b/scripts/ios/createipa.sh index 5b29eeae..a4453903 100755 --- a/scripts/ios/createipa.sh +++ b/scripts/ios/createipa.sh @@ -10,8 +10,7 @@ cd "../../engine/platform/ios/bundle" || exit 1 if [ -d "$BUILDDIR" ]; then mkdir -p "$BUILDDIR/ios/xash3d.app" - cp -r "$BUILDDIR/ios/dlls" "$BUILDDIR/ios/xash3d.app" - cp -r "$BUILDDIR/ios/cl_dlls" "$BUILDDIR/ios/xash3d.app" + cp -r "$BUILDDIR/ios/libs/"* "$BUILDDIR/ios/xash3d.app" cp Info.plist "$BUILDDIR/ios/xash3d.app" cp ftp_commands.plist "$BUILDDIR/ios/xash3d.app" if [ ! -d "$BUILDDIR/SDL2.framework" ]; then