This commit is contained in:
Mathieu Virbel 2011-12-05 10:09:35 +01:00
parent 68925a41f9
commit de94011871
8 changed files with 181 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,7 +1,6 @@
*.swo
*.swp
Python-*
python_files/Python-*
freetype-*
SDL_*
build/*

50
biglink Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env python
import os
import sys
import subprocess
sofiles = [ ]
for dir in sys.argv[1:]:
for fn in os.listdir(dir):
fn = os.path.join(dir, fn)
if not fn.endswith(".so"):
continue
if not os.path.exists(fn + ".o"):
continue
if not os.path.exists(fn + ".libs"):
continue
sofiles.append(fn)
# The raw argument list.
args = [ ]
for fn in sofiles:
afn = fn + ".o"
libsfn = fn + ".libs"
args.append(afn)
args.extend(file(libsfn).read().split(" "))
unique_args = [ ]
while args:
a = args.pop()
if a not in unique_args:
unique_args.insert(0, a)
#args = os.environ["CC"].split() + \
# [ '-shared', "-O3", "-o", "libpymodules.so" ] + \
# unique_args
#subprocess.call(args)
print unique_args
unique_args = ' '.join([ x for x in unique_args if x.endswith('.so.o') ])
print unique_args
subprocess.Popen("ar -q kivy.a " + unique_args, shell=True).communicate()

View file

@ -19,6 +19,13 @@ if [ "X$1" == "X-f" ]; then
try cd ..
fi
export LDSHARED="$KIVYIOSROOT/liblink"
cd kivy
make ios
echo "Now create kivy.a archive"
# FIXME this part is build/cpu dependent :/
build_dir=build/lib.macosx-*/kivy
try $KIVYIOSROOT/biglink $build_dir $build_dir/graphics $build_dir/core/window $build_dir/core/text $build_dir/core/image
try mv kivy.a $BUILDROOT/lib

View file

@ -34,6 +34,7 @@ pushd ./Python-2.7.1
# Patch Python for temporary reduce PY_SSIZE_T_MAX otherzise, splitting string doesnet work
patch -p1 < ../python_files/Python-2.7.1-ssize-t-max.patch
patch -p1 < ../python_files/Python-2.7.1-dynload.patch
echo "Building for native machine ============================================"
# Compile some stuff statically; Modules/Setup taken from pgs4a-kivy
@ -55,7 +56,7 @@ make distclean
patch -p1 < ../python_files/Python-2.7.1-xcompile.patch
# avoid iphone builddd
#if [ "X" == "C" ]; then
if [ "X" == "C" ]; then
echo "Building for iPhone Simulator ==========================================="
export MACOSX_DEPLOYMENT_TARGET=10.6
# set up environment variables for simulator compilation
@ -98,7 +99,7 @@ patch -p1 < ../python_files/Python-2.7.1-xcompile.patch
popd
make distclean
#fi
fi
export MACOSX_DEPLOYMENT_TARGET=
@ -124,8 +125,6 @@ export CPP="/usr/bin/cpp $CPPFLAGS"
export CFLAGS = "$CFLAGS -march=armv7 -mcpu=arm1176jzf-s -mcpu=cortex-a8"
export LDFLAGS = "$LDFLAGS -march=armv7 -mcpu=arm1176jzf-s -mcpu=cortex-a8"
#export CFLAGS = "$CFLAGS -march=armv7"
#export LDFLAGS = "$LDFLAGS -march=armv7"
# make a link to a differently named library for who knows what reason
mkdir extralibs||echo "foo"
@ -163,7 +162,7 @@ cp -R . $PATH_DEV
mkdir $PATH_ALL
cp -R . $PATH_ALL
lipo $PATH_DEV/lib/libpython2.7-arm.a $PATH_SIMU/lib/libpython2.7-i386.a -create -output $PATH_ALL/lib/libpython2.7-iOS5.a
#lipo $PATH_DEV/lib/libpython2.7-arm.a $PATH_SIMU/lib/libpython2.7-i386.a -create -output $PATH_ALL/lib/libpython2.7-iOS5.a
#find python2.7 | grep -E '*\.(py|pyc|so\.o|so\.a|so\.libs)$' | xargs rm
#find python2.7 | grep -E '*test*' | xargs rm -rdf

73
liblink Executable file
View file

@ -0,0 +1,73 @@
#!/usr/bin/env python
import sys
import subprocess
libs = [ ]
objects = [ ]
output = None
i = 1
while i < len(sys.argv):
opt = sys.argv[i]
i += 1
if opt == "-o":
output = sys.argv[i]
i += 1
continue
if opt.startswith("-l") or opt.startswith("-L"):
libs.append(opt)
continue
if opt == "-r":
continue
if opt in ("--sysroot", "-isysroot", "-framework", "-undefined",
"-macosx_version_min"):
i += 1
continue
if opt.startswith("-I"):
continue
if opt.startswith("-m"):
continue
if opt.startswith("-f"):
continue
if opt.startswith("-O"):
continue
if opt.startswith("-g"):
continue
if opt.startswith("-D"):
continue
if opt.startswith("-"):
print sys.argv
print "Unknown option: ", opt
sys.exit(1)
print 'append', opt, 'to output'
objects.append(opt)
f = file(output, "w")
f.close()
f = file(output + ".libs", "w")
f.write(" ".join(libs))
f.close()
print 'objects are', objects
subprocess.call([ "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2", "-r", "-o", output + ".o" ] + objects)

View file

@ -34,3 +34,6 @@ cStringIO cStringIO.c
cPickle cPickle.c
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
xxsubtype xxsubtype.c
# added in case of
unicodedata unicodedata.c # static Unicode character database

View file

@ -0,0 +1,24 @@
--- Python-2.7.1/Python/dynload_shlib.c.orig 2011-12-05 00:00:00.000000000 +0100
+++ Python-2.7.1/Python/dynload_shlib.c 2011-12-05 00:02:51.000000000 +0100
@@ -84,6 +84,15 @@
PyOS_snprintf(funcname, sizeof(funcname),
LEAD_UNDERSCORE "init%.200s", shortname);
+ /* On IOS, dlopen crash as soon as we try to open one of our library.
+ * Instead, we have done a redirection of linking to convert our .so into a
+ * .a. Then the main executable is linked with theses symbol. So, instead
+ * of trying to dlopen, directly do the dlsym.
+ * -- Mathieu
+ */
+ return (dl_funcptr) dlsym(RTLD_MAIN_ONLY, funcname);
+
+#if 0
if (fp != NULL) {
int i;
struct stat statb;
@@ -140,4 +149,5 @@
handles[nhandles++].handle = handle;
p = (dl_funcptr) dlsym(handle, funcname);
return p;
+#endif
}

20
reduce-python.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/zsh
set -o errexit
set -x
echo "Starting reducing=========="
# credit to:
# http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
# http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html
export IOS_VERSION="5.0"
PATH_SIMU=${PWD}/python_files/Python-2.7.1-IOS${IOS_VERSION}-simulator
PATH_DEV=${PWD}/python_files/Python-2.7.1-IOS${IOS_VERSION}-device
PATH_ALL=${PWD}/python_files/Python-2.7.1-IOS${IOS_VERSION}
pushd $PATH_DEV/lib/python2.7
find . -iname '*.pyc' | xargs rm
find . -iname '*.py' | xargs rm
rm -rd *test*
rm -rd lib-* wsgiref bsddb curses idlelib hotshot