Skip to content

Commit

Permalink
Merge pull request LibreELEC#4833 from OpenELEC/Python-fixes
Browse files Browse the repository at this point in the history
Python fixes
  • Loading branch information
sraue committed Mar 10, 2016
2 parents a2ef7ca + d48de86 commit 0de0a2a
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 90 deletions.
5 changes: 5 additions & 0 deletions config/functions
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ setup_toolchain() {
export PKG_CONFIG_LIBDIR="$TARGET_PKG_CONFIG_LIBDIR"
export PKG_CONFIG_SYSROOT_DIR="$TARGET_PKG_CONFIG_SYSROOT_DIR"

# set python defaults
export _python_sysroot="$SYSROOT_PREFIX"
export _python_prefix=/usr
export _python_exec_prefix=/usr

# set CMAKE configfile for target
export CMAKE_CONF=$ROOT/$TOOLCHAIN/etc/cmake-$TARGET_NAME.conf

Expand Down
44 changes: 11 additions & 33 deletions packages/lang/Python/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PKG_SHORTDESC="python: The Python programming language"
PKG_LONGDESC="Python is an interpreted object-oriented programming language, and is often compared with Tcl, Perl, Java or Scheme."

PKG_IS_ADDON="no"
PKG_AUTORECONF="no"
PKG_AUTORECONF="yes"

PY_DISABLED_MODULES="readline _curses _curses_panel _tkinter nis gdbm bsddb ossaudiodev"

Expand Down Expand Up @@ -64,45 +64,36 @@ PKG_CONFIGURE_OPTS_TARGET="ac_cv_file_dev_ptc=no \
--without-cxx-main \
--with-system-ffi \
--with-system-expat"
post_patch() {
# This is needed to make sure the Python build process doesn't try to
# regenerate those files with the pgen program. Otherwise, it builds
# pgen for the target, and tries to run it on the host.
touch $PKG_BUILD/Include/graminit.h
touch $PKG_BUILD/Python/graminit.c
}

make_host() {
make PYTHON_MODULES_INCLUDE="$HOST_INCDIR" \
PYTHON_MODULES_LIB="$HOST_LIBDIR" \
PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES"

sed -e "s|$ROOT/$TOOLCHAIN/include|$SYSROOT_PREFIX/usr/include|g" \
-e "s|$ROOT/$TOOLCHAIN/lib|$SYSROOT_PREFIX/usr/lib|g" \
-e "s|$ROOT/$TOOLCHAIN/bin/host-gcc|${TARGET_PREFIX}gcc|g" \
-i build/lib.linux-$(uname -m)-2.7/_sysconfigdata.py
# python distutils per default adds -L$LIBDIR when linking binary extensions
sed -e "s|^ 'LIBDIR':.*| 'LIBDIR': '/usr/lib',|g" -i $(cat pybuilddir.txt)/_sysconfigdata.py
}

makeinstall_host() {
make PYTHON_MODULES_INCLUDE="$HOST_INCDIR" \
PYTHON_MODULES_LIB="$HOST_LIBDIR" \
PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
install

cp Parser/pgen $ROOT/$TOOLCHAIN/bin

# replace python-config to make sure python uses $SYSROOT_PREFIX
mkdir -p $ROOT/$TOOLCHAIN/bin
rm -rf $ROOT/$TOOLCHAIN/bin/python*-config

sed -e "s:%PREFIX%:$SYSROOT_PREFIX/usr:g" -e "s:%CFLAGS%:$TARGET_CFLAGS:g" \
$PKG_DIR/scripts/python-config > $ROOT/$TOOLCHAIN/bin/python2.7-config
chmod +x $ROOT/$TOOLCHAIN/bin/python2.7-config
ln -s python2.7-config $ROOT/$TOOLCHAIN/bin/python-config
}

pre_configure_target() {
export PYTHON_FOR_BUILD=$ROOT/$TOOLCHAIN/bin/python
export BLDSHARED="$CC -shared"
export RUNSHARED="LD_LIBRARY_PATH=$ROOT/$TOOLCHAIN/lib:$LD_LIBRARY_PATH"
}

make_target() {
make -j1 CC="$TARGET_CC" \
HOSTPGEN=$ROOT/$TOOLCHAIN/bin/pgen \
make -j1 CC="$TARGET_CC" LDFLAGS="$TARGET_LDFLAGS -L." \
PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
PYTHON_MODULES_INCLUDE="$TARGET_INCDIR" \
PYTHON_MODULES_LIB="$TARGET_LIBDIR"
Expand All @@ -111,19 +102,13 @@ make_target() {
makeinstall_target() {
make -j1 CC="$TARGET_CC" \
DESTDIR=$SYSROOT_PREFIX \
HOSTPGEN=$ROOT/$TOOLCHAIN/bin/pgen \
PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
PYTHON_MODULES_INCLUDE="$TARGET_INCDIR" \
PYTHON_MODULES_LIB="$TARGET_LIBDIR" \
install

# python distutils per default adds -L$LIBDIR when linking binary extensions
sed -e "s|^LIBDIR=.*|LIBDIR= $SYSROOT_PREFIX/usr/lib|" \
-i $SYSROOT_PREFIX/usr/lib/python*/config/Makefile

make -j1 CC="$TARGET_CC" \
DESTDIR=$INSTALL \
HOSTPGEN=$ROOT/$TOOLCHAIN/bin/pgen \
PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
PYTHON_MODULES_INCLUDE="$TARGET_INCDIR" \
PYTHON_MODULES_LIB="$TARGET_LIBDIR" \
Expand All @@ -139,13 +124,6 @@ post_makeinstall_target() {
python -Wi -t -B ../Lib/compileall.py $INSTALL/usr/lib/python*/ -f
rm -rf `find $INSTALL/usr/lib/python*/ -name "*.py"`

if [ ! -f $INSTALL/usr/lib/python*/lib-dynload/_socket.so ]; then
echo "sometimes Python dont build '_socket.so' for some reasons and continues without failing,"
echo "let it fail here, to be sure '_socket.so' will be installed. A rebuild of Python fixes"
echo "the issue in most cases"
exit 1
fi

rm -rf $INSTALL/usr/lib/python*/config
rm -rf $INSTALL/usr/bin/2to3
rm -rf $INSTALL/usr/bin/idle
Expand Down
25 changes: 0 additions & 25 deletions packages/lang/Python/patches/Python-2.7.11-001_xcompile.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@ diff --git a/Makefile.pre.in b/Makefile.pre.in
index bcd83bf..5e54a0d 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -191,6 +191,7 @@ UNICODE_OBJS= @UNICODE_OBJS@

PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)
+HOSTPYTHON= ./$(BUILDPYTHON)

PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
@@ -231,6 +232,7 @@ LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@
##########################################################################
# Parser
PGEN= Parser/pgen$(EXE)
+HOSTPGEN= $(PGEN)

PSRCS= \
Parser/acceler.c \
@@ -461,6 +463,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt
esac; \
$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
Expand All @@ -26,15 +10,6 @@ index bcd83bf..5e54a0d 100644
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build

# Build static library
@@ -598,7 +601,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)
+ $(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
$(GRAMMAR_C): $(GRAMMAR_H) $(GRAMMAR_INPUT) $(PGENSRCS)
$(MAKE) $(GRAMMAR_H)
touch $(GRAMMAR_C)
@@ -1142,7 +1145,9 @@ libainstall: all python-config
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Adjust library/header paths for cross-compilation

When cross-compiling third-party extensions, the get_python_inc() or
get_python_lib() can be called, to return the path to headers or
libraries. However, they use the sys.prefix of the host Python, which
returns incorrect paths when cross-compiling (paths pointing to host
headers and libraries).

In order to fix this, we introduce the _python_sysroot, _python_prefix
and _python_exec_prefix variables, that allow to override these
values, and get correct header/library paths when cross-compiling
third-party Python modules.

The _python_sysroot variable is also used to prefix the LIBDIR value
taken from the sysconfigdata module.

Signed-off-by: Thomas Petazzoni <[email protected]>

Index: b/Lib/distutils/sysconfig.py
===================================================================
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -19,8 +19,13 @@
from distutils.errors import DistutilsPlatformError

# These are needed in a couple of spots, so just compute them once.
-PREFIX = os.path.normpath(sys.prefix)
-EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
+if "_python_sysroot" in os.environ:
+ _sysroot=os.environ.get('_python_sysroot')
+ PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
+ EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
+else:
+ PREFIX = os.path.normpath(sys.prefix)
+ EXEC_PREFIX = os.path.normpath(sys.exec_prefix)

# Path to the base directory of the project. On Windows the binary may
# live in project/PCBuild9. If we're dealing with an x64 Windows build,
Index: b/Lib/distutils/command/build_ext.py
===================================================================
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -237,7 +237,10 @@
if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
if not sysconfig.python_build:
# building third party extensions
- self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
+ libdir = sysconfig.get_config_var('LIBDIR')
+ if "_python_sysroot" in os.environ:
+ libdir = os.environ.get("_python_sysroot") + libdir
+ self.library_dirs.append(libdir)
else:
# building python standard extensions
self.library_dirs.append('.')
Loading

0 comments on commit 0de0a2a

Please sign in to comment.