From de94011871d86662cd9fa7ddc8344a1d15e20870 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 5 Dec 2011 10:09:35 +0100 Subject: [PATCH] wip --- .gitignore | 1 - biglink | 50 +++++++++++++++++ build_kivy.sh | 7 +++ build_python.sh | 9 ++- liblink | 73 +++++++++++++++++++++++++ python_files/ModulesSetup | 3 + python_files/Python-2.7.1-dynload.patch | 24 ++++++++ reduce-python.sh | 20 +++++++ 8 files changed, 181 insertions(+), 6 deletions(-) create mode 100755 biglink create mode 100755 liblink create mode 100644 python_files/Python-2.7.1-dynload.patch create mode 100755 reduce-python.sh diff --git a/.gitignore b/.gitignore index a13d637..cfa945c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.swo *.swp Python-* -python_files/Python-* freetype-* SDL_* build/* diff --git a/biglink b/biglink new file mode 100755 index 0000000..bf0de02 --- /dev/null +++ b/biglink @@ -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() diff --git a/build_kivy.sh b/build_kivy.sh index 7b1dc37..9d8eebb 100755 --- a/build_kivy.sh +++ b/build_kivy.sh @@ -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 diff --git a/build_python.sh b/build_python.sh index 896d5a0..af43d2f 100755 --- a/build_python.sh +++ b/build_python.sh @@ -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 diff --git a/liblink b/liblink new file mode 100755 index 0000000..d750933 --- /dev/null +++ b/liblink @@ -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) + + + + + diff --git a/python_files/ModulesSetup b/python_files/ModulesSetup index 7f04002..5ebf5ba 100644 --- a/python_files/ModulesSetup +++ b/python_files/ModulesSetup @@ -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 diff --git a/python_files/Python-2.7.1-dynload.patch b/python_files/Python-2.7.1-dynload.patch new file mode 100644 index 0000000..7cb73f6 --- /dev/null +++ b/python_files/Python-2.7.1-dynload.patch @@ -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 + } diff --git a/reduce-python.sh b/reduce-python.sh new file mode 100755 index 0000000..9470551 --- /dev/null +++ b/reduce-python.sh @@ -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