Skip to content

Instantly share code, notes, and snippets.

@jlhg
Created January 26, 2015 06:15

Revisions

  1. Jian-Long Huang created this gist Jan 26, 2015.
    257 changes: 257 additions & 0 deletions Python-2.7.8-xcompile.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,257 @@
    diff --git a/Makefile.pre.in b/Makefile.pre.in
    index bcd83bf..efbfd8d 100644
    --- a/Makefile.pre.in
    +++ b/Makefile.pre.in
    @@ -461,6 +461,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt
    esac; \
    $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
    _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
    + PYTHONXCPREFIX='$(DESTDIR)$(prefix)' \
    $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build

    # Build static library
    @@ -598,7 +599,7 @@ Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule
    $(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGENSRCS)
    @$(MKDIR_P) Include
    $(MAKE) $(PGEN)
    - $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
    + $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
    $(GRAMMAR_C): $(GRAMMAR_H) $(GRAMMAR_INPUT) $(PGENSRCS)
    $(MAKE) $(GRAMMAR_H)
    touch $(GRAMMAR_C)
    @@ -1009,12 +1010,12 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
    $(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
    $(DESTDIR)$(LIBDEST)/distutils/tests ; \
    fi
    - PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
    + -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
    $(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
    -d $(LIBDEST) -f \
    -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
    $(DESTDIR)$(LIBDEST)
    - PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
    + -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
    $(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
    -d $(LIBDEST) -f \
    -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
    @@ -1142,11 +1143,13 @@ libainstall: all python-config
    # Install the dynamically loadable modules
    # This goes into $(exec_prefix)
    sharedinstall: sharedmods
    + CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
    $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
    + --skip-build \
    --prefix=$(prefix) \
    - --install-scripts=$(BINDIR) \
    - --install-platlib=$(DESTSHARED) \
    - --root=$(DESTDIR)/
    + --install-scripts=$(DESTDIR)$(BINDIR) \
    + --install-platlib=$(DESTDIR)$(DESTSHARED) \
    + --root=/
    -rm $(DESTDIR)$(DESTSHARED)/_sysconfigdata.py*

    # Here are a couple of targets for MacOSX again, to install a full
    diff --git a/Modules/Setup.dist b/Modules/Setup.dist
    index 2ad1aa3..651e0cb 100644
    --- a/Modules/Setup.dist
    +++ b/Modules/Setup.dist
    @@ -109,7 +109,7 @@ PYTHONPATH=$(COREPYTHONPATH)
    # various reasons; therefore they are listed here instead of in the
    # normal order.

    -# This only contains the minimal set of modules required to run the
    +# This only contains the minimal set of modules required to run the
    # setup.py script in the root of the Python source tree.

    posix posixmodule.c # posix (UNIX) system calls
    @@ -127,9 +127,9 @@ zipimport zipimport.c
    # The rest of the modules listed in this file are all commented out by
    # default. Usually they can be detected and built as dynamically
    # loaded modules by the new setup.py script added in Python 2.1. If
    -# you're on a platform that doesn't support dynamic loading, want to
    -# compile modules statically into the Python binary, or need to
    -# specify some odd set of compiler switches, you can uncomment the
    +# you're on a platform that doesn't support dynamic loading, want to
    +# compile modules statically into the Python binary, or need to
    +# specify some odd set of compiler switches, you can uncomment the
    # appropriate lines below.

    # ======================================================================
    @@ -163,7 +163,7 @@ GLHACK=-Dclear=__GLclear
    # it, depending on your system -- see the GNU readline instructions.
    # It's okay for this to be a shared library, too.

    -#readline readline.c -lreadline -ltermcap
    +readline readline.c -lreadline -ltermcap


    # Modules that should always be present (non UNIX dependent):
    @@ -178,7 +178,7 @@ GLHACK=-Dclear=__GLclear
    #_random _randommodule.c # Random number generator
    #_collections _collectionsmodule.c # Container types
    #_heapq _heapqmodule.c # Heapq type
    -#itertools itertoolsmodule.c # Functions creating iterators for efficient looping
    +#itertools itertoolsmodule.c # Functions creating iterators for efficient looping
    #strop stropmodule.c # String manipulations
    #_functools _functoolsmodule.c # Tools for working with functions and callable objects
    #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator
    @@ -200,7 +200,7 @@ GLHACK=-Dclear=__GLclear
    # supported...)

    #fcntl fcntlmodule.c # fcntl(2) and ioctl(2)
    -#spwd spwdmodule.c # spwd(3)
    +#spwd spwdmodule.c # spwd(3)
    #grp grpmodule.c # grp(3)
    #select selectmodule.c # select(2); not on ancient System V

    @@ -215,10 +215,10 @@ GLHACK=-Dclear=__GLclear

    # Socket module helper for SSL support; you must comment out the other
    # socket line above, and possibly edit the SSL variable:
    -#SSL=/usr/local/ssl
    -#_ssl _ssl.c \
    -# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -# -L$(SSL)/lib -lssl -lcrypto
    +SSL=/usr/local/ssl
    +_ssl _ssl.c \
    + -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    + -L$(SSL)/lib -lssl -lcrypto

    # The crypt module is now disabled by default because it breaks builds
    # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
    @@ -303,7 +303,7 @@ GLHACK=-Dclear=__GLclear
    #sunaudiodev sunaudiodev.c


    -# A Linux specific module -- off by default; this may also work on
    +# A Linux specific module -- off by default; this may also work on
    # some *BSDs.

    #linuxaudiodev linuxaudiodev.c
    @@ -369,7 +369,7 @@ GLHACK=-Dclear=__GLclear

    #_curses _cursesmodule.c -lcurses -ltermcap
    # Wrapper for the panel library that's part of ncurses and SYSV curses.
    -#_curses_panel _curses_panel.c -lpanel -lncurses
    +#_curses_panel _curses_panel.c -lpanel -lncurses


    # Generic (SunOS / SVR4) dynamic loading module.
    @@ -464,7 +464,7 @@ GLHACK=-Dclear=__GLclear
    # Andrew Kuchling's zlib module.
    # This require zlib 1.1.3 (or later).
    # See http://www.gzip.org/zlib/
    -#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
    +zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

    # Interface to the Expat XML parser
    #
    diff --git a/configure b/configure
    index 2c1c82d..6633605 100755
    --- a/configure
    +++ b/configure
    @@ -2860,21 +2860,7 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
    if test "$cross_compiling" = yes; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
    $as_echo_n "checking for python interpreter for cross build... " >&6; }
    - if test -z "$PYTHON_FOR_BUILD"; then
    - for interp in python$PACKAGE_VERSION python2 python; do
    - which $interp >/dev/null 2>&1 || continue
    - if $interp -c 'import sys;sys.exit(not (sys.version_info[:2] >= (2,7) and sys.version_info[0] < 3))'; then
    - break
    - fi
    - interp=
    - done
    - if test x$interp = x; then
    - as_fn_error $? "python$PACKAGE_VERSION interpreter not found" "$LINENO" 5
    - fi
    - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
    -$as_echo "$interp" >&6; }
    - PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
    - fi
    + PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) $(srcdir)/$(BUILDPYTHON)_for_build'
    elif test "$cross_compiling" = maybe; then
    as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
    else
    diff --git a/setup.py b/setup.py
    index a46bf35..c19a237 100644
    --- a/setup.py
    +++ b/setup.py
    @@ -17,7 +17,7 @@ from distutils.command.install import install
    from distutils.command.install_lib import install_lib
    from distutils.spawn import find_executable

    -cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
    +cross_compiling = ("_PYTHON_HOST_PLATFORM" in os.environ) or ('PYTHONXCPREFIX' in os.environ)

    def get_platform():
    # cross build
    @@ -324,6 +324,9 @@ class PyBuildExt(build_ext):

    # Don't try to load extensions for cross builds
    if cross_compiling:
    + self.announce(
    + 'WARNING: skipping import check for cross-compiled: "%s"' %
    + ext.name)
    return

    try:
    @@ -436,13 +439,11 @@ class PyBuildExt(build_ext):
    os.unlink(tmpfile)

    def detect_modules(self):
    - # Ensure that /usr/local is always used
    + # Ensure that /usr/local is always used, unless cross-compiling
    if not cross_compiling:
    add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
    - if cross_compiling:
    - self.add_gcc_paths()
    - self.add_multiarch_paths()
    + self.add_multiarch_paths()

    # Add paths specified in the environment variables LDFLAGS and
    # CPPFLAGS for header and library files.
    @@ -478,7 +479,7 @@ class PyBuildExt(build_ext):
    for directory in reversed(options.dirs):
    add_dir_to_list(dir_list, directory)

    - if os.path.normpath(sys.prefix) != '/usr' \
    + if os.path.normpath(sys.prefix) != '/usr' and not cross_compiling \
    and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
    # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
    # (PYTHONFRAMEWORK is set) to avoid # linking problems when
    @@ -1596,14 +1597,14 @@ class PyBuildExt(build_ext):


    # Platform-specific libraries
    - if host_platform == 'linux2':
    + if host_platform in ('linux2', 'linux2-i686'):
    # Linux-specific modules
    exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
    else:
    missing.append('linuxaudiodev')

    - if (host_platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
    - 'freebsd7', 'freebsd8')
    + if (host_platform in ('linux2', 'linux2-i686', 'freebsd4', 'freebsd5', 'freebsd6',
    + 'freebsd7', 'freebsd8')
    or host_platform.startswith("gnukfreebsd")):
    exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
    else:
    @@ -2026,8 +2027,13 @@ class PyBuildExt(build_ext):

    # Pass empty CFLAGS because we'll just append the resulting
    # CFLAGS to Python's; -g or -O2 is to be avoided.
    - cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
    - % (ffi_builddir, ffi_srcdir, " ".join(config_args))
    + if cross_compiling:
    + cmd = "cd %s && env CFLAGS='' '%s/configure' --host=%s --build=%s %s" \
    + % (ffi_builddir, ffi_srcdir, os.environ.get('HOSTARCH'),
    + os.environ.get('BUILDARCH'), " ".join(config_args))
    + else:
    + cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
    + % (ffi_builddir, ffi_srcdir, " ".join(config_args))

    res = os.system(cmd)
    if res or not os.path.exists(ffi_configfile):