Any chance this could be pushed to gitorious.org/bsnes/bsnes.git? It’s just a series of patches needed to get bsnes to build and run on iOS.
Notably: Calls to stat64 are replaced with calls to stat on iOS. Proper command line arguments are passed to clang during build. libco/armeabi.c is updated to link for iOS.
---
libco/armeabi.c | 11 ++++++++++-
libco/libco.c | 2 +-
nall/file.hpp | 19 ++++++++++++++++---
nall/intrinsics.hpp | 2 +-
target-libretro/Makefile | 6 +++---
5 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/libco/armeabi.c b/libco/armeabi.c
index ad9ed07..865b588 100644
--- a/libco/armeabi.c
+++ b/libco/armeabi.c
@@ -22,7 +22,9 @@ asm (
".arm
"
".align 4
"
".globl co_switch_arm
"
+ ".globl _co_switch_arm
"
"co_switch_arm:
"
+ "_co_switch_arm:
"
" stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, lr}
"
" ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}
"
);
@@ -36,7 +38,14 @@ static void crash(void) {
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
size = (size + 1023) & ~1023;
- cothread_t handle = memalign(1024, size + 256);
+ cothread_t handle = 0;
+#if HAVE_POSIX_MEMALIGN >= 1
+ if (posix_memalign(&handle, 1024, size + 256) < 0)
+ return 0;
+#else
+ handle = memalign(1024, size + 256);
+#endif
+
if (!handle)
return handle;
diff --git a/libco/libco.c b/libco/libco.c
index 79fdd07..a997a24 100644
--- a/libco/libco.c
+++ b/libco/libco.c
@@ -10,7 +10,7 @@
#include "amd64.c"
#elif defined(__GNUC__) && defined(_ARCH_PPC)
#include "ppc.c"
-#elif defined(__GNUC__) && defined(__ARM_EABI__)
+#elif defined(__GNUC__) && (defined(__ARM_EABI__) || defined(__arm__))
#include "armeabi.c"
#elif defined(__GNUC__)
#include "sjlj.c"
diff --git a/nall/file.hpp b/nall/file.hpp
index 352682a..a529a16 100644
--- a/nall/file.hpp
+++ b/nall/file.hpp
@@ -8,6 +8,10 @@
#include <nall/windows/utf8.hpp>
#include <nall/stream/memory.hpp>
+#ifdef __APPLE__
+#include "TargetConditionals.h"
+#endif
+
namespace nall {
inline FILE* fopen_utf8(const string& filename, const string& mode) {
@@ -226,7 +230,10 @@ struct file {
}
static bool exists(const string& filename) {
- #if !defined(_WIN32)
+ #if defined(__APPLE__) && TARGET_OS_IPHONE
+ struct stat data;
+ if(stat(filename, &data) != 0) return false;
+ #elif !defined(_WIN32)
struct stat64 data;
if(stat64(filename, &data) != 0) return false;
#else
@@ -238,7 +245,10 @@ struct file {
}
static uintmax_t size(const string& filename) {
- #if !defined(_WIN32)
+ #if defined(__APPLE__) && TARGET_OS_IPHONE
+ struct stat data;
+ if(stat(filename, &data) != 0) return false;
+ #elif !defined(_WIN32)
struct stat64 data;
stat64(filename, &data);
#else
@@ -249,7 +259,10 @@ struct file {
}
static time_t timestamp(const string& filename, file::time mode = file::time::create) {
- #if !defined(_WIN32)
+ #if defined(__APPLE__) && TARGET_OS_IPHONE
+ struct stat data;
+ if(stat(filename, &data) != 0) return false;
+ #elif !defined(_WIN32)
struct stat64 data;
stat64(filename, &data);
#else
diff --git a/nall/intrinsics.hpp b/nall/intrinsics.hpp
index 8f1e3fe..e9d276b 100755
--- a/nall/intrinsics.hpp
+++ b/nall/intrinsics.hpp
@@ -45,7 +45,7 @@ struct Intrinsics {
/* Endian detection */
-#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64) || defined(__ARM_EABI__)
+#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64) || defined(__ARM_EABI__) || defined(__arm__)
#define ENDIAN_LSB
#define ARCH_LSB
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; }
diff --git a/target-libretro/Makefile b/target-libretro/Makefile
index c088bf3..17a2275 100755
--- a/target-libretro/Makefile
+++ b/target-libretro/Makefile
@@ -10,7 +10,7 @@ ifeq ($(platform),unix)
else ifeq ($(platform),osx)
flags += -fPIC
else ifeq ($(platform),ios)
- flags += -fPIC
+ flags += -arch armv7 -marm -fPIC -isysroot $(IOSSDK) -DHAVE_POSIX_MEMALIGN=1 -w
else ifeq ($(platform),win)
endif
@@ -27,7 +27,7 @@ build: $(objects)
ifeq ($(platform),unix)
$(compiler) -o out/bsnes_libretro.so -shared $(objects) -ldl -Wl,--no-undefined -Wl,--version-script=$(ui)/link.T
else ifeq ($(platform),ios)
- $(compiler) -o out/bsnes_libretro_ios.dylib -dynamiclib $(objects)
+ $(compiler) -o out/bsnes_libretro_ios.dylib -dynamiclib $(objects) -isysroot $(IOSSDK) -arch armv7
else ifeq ($(platform),osx)
$(compiler) -o out/bsnes_libretro.dylib -dynamiclib $(objects)
else ifeq ($(platform),win)
@@ -40,7 +40,7 @@ ifeq ($(platform),unix)
else ifeq ($(platform),osx)
cp out/bsnes_libretro.dylib $(DESTDIR)$(prefix)/lib/bsnes_libretro.dylib
else ifeq ($(platform),ios)
- cp out/bsnes_libretro_io.dylib $(DESTDIR)$(prefix)/lib/bsnes_libretro_ios.dylib
+ cp out/bsnes_libretro_ios.dylib $(DESTDIR)$(prefix)/lib/bsnes_libretro_ios.dylib
endif
uninstall:
--