From 8ad1528b69655e99ce77d52df90fadeb07b1153c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 20 May 2011 06:59:04 +0000 Subject: [PATCH] Support building for iOS (Universal) on Mac. --- GNUmakefile.in | 36 ++++++++++++++++-------------------- Mach/Inject.cpp | 16 ++++++++-------- ObjectiveC/Library.mm | 15 +++++---------- ios.sh | 29 ++++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index 913e229..fb3037c 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -76,8 +76,6 @@ endif paths := $(foreach path,$(paths),$(wildcard $(path))) cflags += $(foreach path,$(paths),-I$(path) -L$(path)) -#svn := $(shell svnversion $(srcdir)) - all: all := cycript @@ -98,10 +96,10 @@ inject := filters := #E4X ldid := true -entitle := $(ldid) +entitle = $(ldid) -Scycript.xml lib := lib dll := @SO@ -depends := +depends ?= restart ?= $(MAKE) uname_s ?= $(shell uname -s) @@ -127,22 +125,20 @@ all += libcycript.la filters += $(shell $(bison) <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23) ifdef arch -deb := $(shell grep ^Package: $(srcdir)/control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: $(srcdir)/control.in | cut -d ' ' -f 2 | $(sed) -e 's/\#/$(svn)/')_$(arch).deb +deb := $(shell grep ^Package: $(srcdir)/control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: $(srcdir)/control.in | cut -d ' ' -f 2 | $(sed) -e 's/\#/$(version)/')_$(arch).deb all: -extra:: - ifeq ($(depends)$(dll),dylib) -control.tmp: control.in cycript $(lib)cycript.dylib - $(sed) -e 's/&/'"$$(dpkg-query -S $$(otool -lah cycript *.dylib | grep dylib | grep -v ':$$' | $(sed) -e 's/^ *name //;s/ (offset [0-9]*)$$//' | sort -u) 2>/dev/null | $(sed) -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ +control.tmp: control.in .libs/cycript .libs/$(lib)cycript.dylib + $(sed) -e 's/&/'"$$(dpkg-query -S $$(otool -lah .libs/cycript .libs/*.dylib | grep dylib | grep -v ':$$' | $(sed) -e 's/^ *name //;s/ (offset [0-9]*)$$//' | sort -u) 2>/dev/null | $(sed) -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(version)/;s/%/$(arch)/' $< >$@ else ifeq ($(depends)$(dll),so) -control.tmp: control.in cycript $(lib)cycript.so - $(sed) -e 's/&/'"$$(dpkg-query -S $$(ldd cycript $(lib)cycript.so | $(sed) -e '/:$$/ d; s/^[ \t]*\([^ ]* => \)\?\([^ ]*\) .*/\2/' | sort -u) 2>/dev/null | $(sed) -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ +control.tmp: control.in .libs/cycript .libs/$(lib)cycript.so + $(sed) -e 's/&/'"$$(dpkg-query -S $$(ldd cycript $(lib)cycript.so | $(sed) -e '/:$$/ d; s/^[ \t]*\([^ ]* => \)\?\([^ ]*\) .*/\2/' | sort -u) 2>/dev/null | $(sed) -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(version)/;s/%/$(arch)/' $< >$@ else control.tmp: control.in - $(sed) -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ + $(sed) -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(version)/;s/%/$(arch)/' $< >$@ endif endif @@ -153,11 +149,11 @@ $(deb): $(all) control rm -rf package mkdir -p package/DEBIAN cp -pR control package/DEBIAN + #sed -i -e '/^Depends: / s/\/mobilesubstrate (>= 0.9.3072)/g' package/DEBIAN/control mkdir -p package/usr/{bin,lib,sbin} - $(restart) extra - cp -pR $(lib)cycript.$(dll) package/usr/lib - cp -pR cycript package/usr/bin - #cp -pR cyrver package/usr/sbin + cp -pR .libs/$(lib)cycript.0.$(dll) package/usr/lib + cp -pR .libs/$(lib)cycript.$(dll) package/usr/lib + cp -pR .libs/cycript package/usr/bin dpkg-deb -b package $(deb) endif @@ -197,7 +193,7 @@ endif all: $(all) clean:: - rm -rf *.lo *.o *.d *.t.hpp .libs */*.d */*.lo */.libs lib*.la $(all) Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.yy Cycript.l control Bridge.gperf Bridge.hpp Cycript.output + rm -rf *.lo *.o *.d *.t.hpp .libs */*.d */*.lo */.libs lib*.la $(all) Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.yy Cycript.l control Bridge.gperf Bridge.hpp Cycript.output ifneq ($(srcdir),.) rm -rf Mach ObjectiveC sig endif @@ -234,11 +230,11 @@ lex.cy.lo: lex.cy.c $(header) libcycript.la: $(code) $(libtool) --mode=link $(cxx) $(ltflags) $(ldflags) -o $@ $(filter %.lo,$^) $(library) $(link) -rpath $(libdir) - $(ldid) $@ + $(ldid) .libs/$(lib)cycript.$(dll) cycript: Console.lo libcycript.la $(inject) $(libtool) --mode=link $(cxx) $(ltflags) $(ldflags) -o $@ $(filter %.lo,$^) libcycript.la $(link) -rpath $(libdir) - $(entitle) cycript + $(entitle) .libs/cycript package: $(deb) @@ -266,4 +262,4 @@ uninstall: $(libtool) --mode=uninstall rm -f $(DESTDIR)$(bindir)/cycript $(libtool) --mode=uninstall rm -f $(DESTDIR)$(libdir)/libcycript.la -.PHONY: all clean extra dist install uninstall package test control.tmp +.PHONY: all clean dist install uninstall package test control.tmp diff --git a/Mach/Inject.cpp b/Mach/Inject.cpp index ec1f1f5..29d1848 100644 --- a/Mach/Inject.cpp +++ b/Mach/Inject.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -75,7 +75,7 @@ void InjectLibrary(pid_t pid) { Trampoline *trampoline; #if defined(__arm__) - trampoline = &Trampoline_arm_; + trampoline = &Trampoline_armv6_; arm_thread_state_t state; flavor = ARM_THREAD_STATE; count = ARM_THREAD_STATE_COUNT; @@ -117,13 +117,13 @@ void InjectLibrary(pid_t pid) { _assert(count == count); #if defined(__arm__) - state.r[0] = data; - state.sp = stack + Stack_; - state.pc = code + trampoline->entry_; + state.__r[0] = data; + state.__sp = stack + Stack_; + state.__pc = code + trampoline->entry_; - if ((state.pc & 0x1) != 0) { - state.pc &= ~0x1; - state.cpsr |= 0x20; + if ((state.__pc & 0x1) != 0) { + state.__pc &= ~0x1; + state.__cpsr |= 0x20; } #elif defined(__i386__) frame[1] = data; diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index b8699cd..36c599a 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -19,12 +19,6 @@ **/ /* }}} */ -#if defined(__APPLE__) && defined(__arm__) -#include -#else -#include -#endif - #ifdef __APPLE__ #include "Struct.hpp" #endif @@ -33,7 +27,8 @@ #include "ObjectiveC/Internal.hpp" -#include +#include +#include #include "cycript.hpp" @@ -2116,7 +2111,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje } CYCatch } /* Hook: objc_registerClassPair {{{ */ -#if defined(__APPLE__) && defined(__arm__) +#if defined(__APPLE__) && defined(__arm__) && 0 // XXX: replace this with associated objects MSHook(void, CYDealloc, id self, SEL sel) { @@ -2492,7 +2487,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition.getPropertyNames = &ObjectiveC_Protocols_getPropertyNames; ObjectiveC_Protocols_ = JSClassCreate(&definition); -#if defined(__APPLE__) && defined(__arm__) +#if defined(__APPLE__) && defined(__arm__) && 0 MSHookFunction(&objc_registerClassPair, MSHake(objc_registerClassPair)); #endif @@ -2536,7 +2531,7 @@ void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry { CYSetProperty(context, cycript, CYJSString("Selector"), Selector); CYSetProperty(context, cycript, CYJSString("Super"), Super); -#if defined(__APPLE__) && defined(__arm__) +#if defined(__APPLE__) && defined(__arm__) && 0 CYSetProperty(context, all, CYJSString("objc_registerClassPair"), &objc_registerClassPair_, kJSPropertyAttributeDontEnum); #endif diff --git a/ios.sh b/ios.sh index a308908..0bcbd49 100755 --- a/ios.sh +++ b/ios.sh @@ -1,26 +1,44 @@ #!/usr/bin/env bash +rm -rf sysroot.ios mkdir -p sysroot.ios -for deb in apr-lib_1.3.3-2 readline_6.0-7; do +for deb in apr-lib_1.3.3-2 libffi_130618-4 readline_6.0-7; do deb=${deb}_iphoneos-arm.deb - #wget http://apt.saurik.com/debs/"${deb}" + [[ -f "${deb}" ]] || wget http://apt.saurik.com/debs/"${deb}" tar=data.tar.lzma ar -x "${deb}" "${tar}" tar -C sysroot.ios -xf "${tar}" rm -f "${tar}" done +mkdir -p sysroot.ios/usr/include/ffi +mv -v sysroot.ios/usr/include/{,ffi/}ffi.h + dev=/Developer/Platforms/iPhoneOS.platform/Developer +sdk=${dev}/SDKs/iPhoneOS4.3.sdk + +ln -s /System/Library/Frameworks/WebKit.framework/Versions/A/Headers sysroot.ios/usr/include/WebKit + +mkdir -p sysroot.ios/Library/Frameworks/JavaScriptCore.framework +ln -s "${sdk}"/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore sysroot.ios/Library/Frameworks/JavaScriptCore.framework +ln -s /System/Library/Frameworks/JavaScriptCore.framework/Headers sysroot.ios/Library/Frameworks/JavaScriptCore.framework + export CC=${dev}/usr/bin/gcc export CXX=${dev}/usr/bin/g++ +export OBJCXX=${dev}/usr/bin/g++ flags_armv6=() -flags_armv6+=(-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk) +flags_armv6+=(-isysroot "${sdk}") +flags_armv6+=(-Fsysroot.ios/Library/Frameworks) flags_armv6+=(-Isysroot.ios/usr/include) flags_armv6+=(-Lsysroot.ios/usr/lib) +flags_armv6+=(-F"${sdk}"/System/Library/PrivateFrameworks) +flags_armv6+=(-framework WebCore) + + flags=() for flag in "${flags_armv6[@]}"; do flags+=(-Xarch_armv6 "${flag}") @@ -29,6 +47,7 @@ done cflags=${flags[*]} export CFLAGS=${cflags} export CXXFLAGS=${cflags} +export OBJCXXFLAGS=${cflags} lflags=() for flag in "${flags[@]}"; do @@ -39,3 +58,7 @@ lflags=${lflags[*]} export LTFLAGS=${lflags} ./configure --prefix=/usr "$@" + +make clean +make -j ldid=ldid all +make arch=iphoneos-arm version=432 dll=dylib depends='apr-lib readline libffi mobilesubstrate' package -- 2.47.2