Permalink
Browse files

upgrade to python 2.7

  • Loading branch information...
1 parent f32ec42 commit b2619ef5ed8d3af958388fd17c67cb670ec8edaf @dennda dennda committed Jul 6, 2011
Showing with 213 additions and 39 deletions.
  1. +17 −0 Python-2.7.1-ssize-t-max.patch
  2. +138 −0 Python-2.7.1-xcompile.patch
  3. +58 −39 iOS-build.sh
@@ -0,0 +1,17 @@
+diff -Naur Python-2.7.1.orig/Include/pyport.h Python-2.7.1/Include/pyport.h
+--- Python-2.7.1.orig/Include/pyport.h 2010-09-14 18:10:22.000000000 +0200
++++ Python-2.7.1/Include/pyport.h 2011-05-13 12:24:53.000000000 +0200
+@@ -186,9 +186,11 @@
+ #endif
+
+ /* Largest positive value of type Py_ssize_t. */
+-#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
++//#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
+ /* Smallest negative value of type Py_ssize_t. */
+-#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
++//#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
++#define PY_SSIZE_T_MAX TMP_MAX
++#define PY_SSIZE_T_MIN -TMP_MAX
+
+ #if SIZEOF_PID_T > SIZEOF_LONG
+ # error "Python doesn't support sizeof(pid_t) > sizeof(long)"
View
@@ -0,0 +1,138 @@
+diff -Naur Python-2.7-old/Makefile.pre.in Python-2.7-new/Makefile.pre.in
+--- Python-2.7-old/Makefile.pre.in 2010-04-11 17:10:46.000000000 -0700
++++ Python-2.7-new/Makefile.pre.in 2010-07-09 13:40:47.000000000 -0700
+@@ -179,6 +179,7 @@
+
+ PYTHON= python$(EXE)
+ BUILDPYTHON= python$(BUILDEXE)
++HOSTPYTHON= ./$(BUILDPYTHON)
+
+ # The task to run while instrument when building the profile-opt target
+ PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
+@@ -212,6 +213,8 @@
+ # Parser
+ PGEN= Parser/pgen$(EXE)
+
++HOSTPGEN= $(PGEN)
++
+ POBJS= \
+ Parser/acceler.o \
+ Parser/grammar1.o \
+@@ -404,8 +407,8 @@
+ # Build the shared modules
+ sharedmods: $(BUILDPYTHON)
+ @case $$MAKEFLAGS in \
+- *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
+- *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
++ *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
++ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
+ esac
+
+ # Build static library
+@@ -538,7 +541,7 @@
+
+ $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
+ -@$(INSTALL) -d Include
+- -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
++ -$(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+
+ $(PGEN): $(PGENOBJS)
+ $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+@@ -919,26 +922,26 @@
+ done; \
+ done
+ $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
+- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+- ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
++ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
++ $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+ -d $(LIBDEST) -f \
+ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+ $(DESTDIR)$(LIBDEST)
+- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+- ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
++ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
++ $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ -d $(LIBDEST) -f \
+ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
+ $(DESTDIR)$(LIBDEST)
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+- ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
++ $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
+ -d $(LIBDEST)/site-packages -f \
+ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+- ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
++ $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ -d $(LIBDEST)/site-packages -f \
+ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+- ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
++ $(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+
+ # Create the PLATDIR source directory, if one wasn't distributed..
+ $(srcdir)/Lib/$(PLATDIR):
+@@ -1042,8 +1045,10 @@
+
+ # Install the dynamically loadable modules
+ # This goes into $(exec_prefix)
+-sharedinstall: sharedmods
+- $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
++sharedinstall: sharedmods
++ CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
++ $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
++ --skip-build \
+ --prefix=$(prefix) \
+ --install-scripts=$(BINDIR) \
+ --install-platlib=$(DESTSHARED) \
+diff -Naur Python-2.7-old/setup.py Python-2.7-new/setup.py
+--- Python-2.7-old/setup.py 2010-06-27 05:36:16.000000000 -0700
++++ Python-2.7-new/setup.py 2010-07-09 13:54:29.000000000 -0700
+@@ -23,6 +23,10 @@
+ # This global variable is used to hold the list of modules to be disabled.
+ disabled_module_list = []
+
++# _ctypes fails to cross-compile due to the libffi configure script.
++if os.environ.has_key('PYTHONXCPREFIX'):
++ disabled_module_list.append('_ctypes')
++
+ def add_dir_to_list(dirlist, dir):
+ """Add the directory 'dir' to the list 'dirlist' (at the front) if
+ 1) 'dir' is not already in 'dirlist'
+@@ -278,6 +282,14 @@
+ (ext.name, sys.exc_info()[1]))
+ self.failed.append(ext.name)
+ return
++
++ # Inport check will not work when cross-compiling.
++ if os.environ.has_key('PYTHONXCPREFIX'):
++ self.announce(
++ 'WARNING: skipping inport check for cross-compiled: "%s"' %
++ ext.name)
++ return
++
+ # Workaround for Mac OS X: The Carbon-based modules cannot be
+ # reliably imported into a command-line Python
+ if 'Carbon' in ext.extra_link_args:
+
+--- Python-2.7Orig/configure 2011-04-29 22:30:59.231331437 +1000
++++ Python-2.7/configure 2010-05-29 01:28:47.000000000 +1000
+@@ -13517,7 +13517,7 @@
+ $as_echo_n "(cached) " >&6
+ else
+ if test "$cross_compiling" = yes; then :
+- ac_cv_have_long_long_format=no
++ ac_cv_have_long_long_format="cross -- assuming yes"
+ else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+@@ -13569,7 +13569,7 @@
+ $as_echo "$ac_cv_have_long_long_format" >&6; }
+ fi
+
+-if test "$ac_cv_have_long_long_format" = yes
++if test "$ac_cv_have_long_long_format" != no
+ then
+
+ $as_echo "#define PY_FORMAT_LONG_LONG \"ll\"" >>confdefs.h
+
View
@@ -1,5 +1,6 @@
#!/bin/zsh
set -o errexit
+set -x
echo "Starting =========="
@@ -10,24 +11,25 @@ echo "Starting =========="
export IOS_VERSION="4.3"
# download python and patch if they aren't there
-if [[ ! -a Python-2.6.5.tar.bz2 ]]; then
- curl http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2 > Python-2.6.5.tar.bz2
+if [[ ! -a Python-2.7.1.tar.bz2 ]]; then
+ curl http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2 > Python-2.7.1.tar.bz2
fi
# get rid of old build
-rm -rf Python-2.6.5
+rm -rf Python-2.7.1
-tar -xjf Python-2.6.5.tar.bz2
-pushd ./Python-2.6.5
+tar -xjf Python-2.7.1.tar.bz2
+pushd ./Python-2.7.1
-# Patch Python for OSX because there is no _environ symbol on OSX
-patch -p0 < ../environ_symbol_fix.patch
+# Patch Python for temporary reduce PY_SSIZE_T_MAX otherzise, splitting string doesnet work
+patch -p1 < ../Python-2.7.1-ssize-t-max.patch
echo "Building for native machine ============================================"
# Compile some stuff statically; Modules/Setup taken from pgs4a-kivy
cp ../ModulesSetup Modules/Setup.local
-CC=clang ./configure
+#CC=clang ./configure
+./configure CC="ccache clang -Qunused-arguments -fcolor-diagnostics"
#make python.exe Parser/pgen
make python Parser/pgen
@@ -39,41 +41,44 @@ mv Parser/pgen Parser/hostpgen
make distclean
# patch python to cross-compile
-patch -p1 < ../Python-2.6.5-xcompile.patch
+patch -p1 < ../Python-2.7.1-xcompile.patch
-echo "Building for iPhone Simulator ==========================================="
-export MACOSX_DEPLOYMENT_TARGET=10.6
-# set up environment variables for simulator compilation
-export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
-export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator${IOS_VERSION}.sdk"
+# avoid iphone builddd
+if [ "X" == "C" ]; then
+ echo "Building for iPhone Simulator ==========================================="
+ export MACOSX_DEPLOYMENT_TARGET=10.6
+ # set up environment variables for simulator compilation
+ export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
+ export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator${IOS_VERSION}.sdk"
-if [ ! -d "$DEVROOT" ]; then
- echo "DEVROOT doesn't exist. DEVROOT=$DEVROOT"
- exit 1
-fi
+ if [ ! -d "$DEVROOT" ]; then
+ echo "DEVROOT doesn't exist. DEVROOT=$DEVROOT"
+ exit 1
+ fi
-if [ ! -d "$SDKROOT" ]; then
- echo "SDKROOT doesn't exist. SDKROOT=$SDKROOT"
- exit 1
-fi
+ if [ ! -d "$SDKROOT" ]; then
+ echo "SDKROOT doesn't exist. SDKROOT=$SDKROOT"
+ exit 1
+ fi
-export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/"
-export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
-export LDFLAGS="-isysroot $SDKROOT"
-export CPP="/usr/bin/cpp $CPPFLAGS"
+ export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/"
+ export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
+ export LDFLAGS="-isysroot $SDKROOT"
+ export CPP="/usr/bin/cpp $CPPFLAGS"
-# Compile some stuff statically; Modules/Setup taken from pgs4a-kivy
-cp ../ModulesSetup Modules/Setup.local
+ # Compile some stuff statically; Modules/Setup taken from pgs4a-kivy
+ cp ../ModulesSetup Modules/Setup.local
-./configure CC="$DEVROOT/usr/bin/i686-apple-darwin10-llvm-gcc-4.2 -m32" \
- LD="$DEVROOT/usr/bin/ld" --disable-toolbox-glue --host=i386-apple-darwin --prefix=/python
+ ./configure CC="$DEVROOT/usr/bin/i686-apple-darwin10-llvm-gcc-4.2 -m32" \
+ LD="$DEVROOT/usr/bin/ld" --disable-toolbox-glue --host=i386-apple-darwin --prefix=/python
-make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
- CROSS_COMPILE_TARGET=yes
+ make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
+ CROSS_COMPILE_TARGET=yes
-mv libpython2.6.a libpython2.6-i386.a
+ mv libpython2.7.a libpython2.7-i386.a
-make distclean
+ make distclean
+fi
export MACOSX_DEPLOYMENT_TARGET=
@@ -98,20 +103,34 @@ export LDFLAGS="-isysroot $SDKROOT -Lextralibs/"
export CPP="/usr/bin/cpp $CPPFLAGS"
# make a link to a differently named library for who knows what reason
-mkdir extralibs
-ln -s "$SDKROOT/usr/lib/libgcc_s.1.dylib" extralibs/libgcc_s.10.4.dylib
+mkdir extralibs||echo "foo"
+ln -s "$SDKROOT/usr/lib/libgcc_s.1.dylib" extralibs/libgcc_s.10.4.dylib || echo "sdf"
# Compile some stuff statically; Modules/Setup taken from pgs4a-kivy
cp ../ModulesSetup Modules/Setup.local
-./configure CC="$DEVROOT/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" \
+# Put arm compiler in path, then ccache can use it
+OLDPATH=$PATH
+export PATH=$PATH:$DEVROOT/usr/bin
+
+# XXX Should prolly use armv7 as well?
+./configure CC="arm-apple-darwin10-llvm-gcc-4.2" \
LD="$DEVROOT/usr/bin/ld" --disable-toolbox-glue --host=armv6-apple-darwin --prefix=/python
+# --without-doc-strings
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix="$PWD/_install"
+# Restore old path
+export PATH=$OLDPATH
+
pushd _install/lib
-mv libpython2.6.a libpython2.6-arm.a
-lipo -create -output libpython2.6.a ../../libpython2.6-i386.a libpython2.6-arm.a
+mv libpython2.7.a libpython2.7-arm.a
+#lipo -create -output libpython2.7.a ../../libpython2.7-i386.a libpython2.7-arm.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
+
+

0 comments on commit b2619ef

Please sign in to comment.