Sun Sep 18 12:36:41 2016 UTC ()
Forward port patches from python27 for dlopen(3)

Original changes in python27/Makefile r1.62-r1.67
=================================================

Add an option for Python: x11

Fix dlopen(3) calls in _ctypes.so for X11BASE libraries

A Python code can dynamically load shared libraries and it's wrapped with
a plain dlopen(3) call. The holder of this interface (_ctypes module)
without rpath set to X11BASE cannot detect libs like 'GL'.

Fixing find_library() on POSIX-like (excluding Darwin) systems.

This isn't addressing Python's wrapper for dlopen(3).

This possibily addresses mostly NetBSD as other popular OSes have ldconfig.

Testing commands:

 - before applying the patch

>>> from ctypes.util import find_library
>>> find_library("m")
'libm.so.0'
>>> find_library("crypto")
'libcrypto.so.11'
>>> find_library("GL")
>>> find_library("curl")

 - after applying the patch
>>> from ctypes.util import find_library
>>> find_library("m")
'libm.so.0'
>>> find_library("crypto")
'libcrypto.so.11'
>>> find_library("GL")
'libGL.so.2'
>>> find_library("curl")
'libcurl.so.4'

This patch doesn't solve the case of custom dirs like $PREFIX/qt5/lib.
However it's solving most common cases of using this call.

A possible solution is to parse the output "pkg_info -La"... however it's
very slow. In other words a cache with libraries might be needed to handle
it efficiently.


(kamil)
diff -r1.16 -r1.17 pkgsrc/lang/python34/Makefile
diff -r0 -r1.1 pkgsrc/lang/python34/options.mk

cvs diff -r1.16 -r1.17 pkgsrc/lang/python34/Attic/Makefile (expand / switch to unified diff)

--- pkgsrc/lang/python34/Attic/Makefile 2016/05/13 16:35:03 1.16
+++ pkgsrc/lang/python34/Attic/Makefile 2016/09/18 12:36:41 1.17
@@ -1,18 +1,19 @@ @@ -1,18 +1,19 @@
1# $NetBSD: Makefile,v 1.16 2016/05/13 16:35:03 adam Exp $ 1# $NetBSD: Makefile,v 1.17 2016/09/18 12:36:41 kamil Exp $
2 2
3.include "dist.mk" 3.include "dist.mk"
4 4
5PKGNAME= python34-${PY_DISTVERSION} 5PKGNAME= python34-${PY_DISTVERSION}
 6PKGREVISION= 1
6CATEGORIES= lang python 7CATEGORIES= lang python
7 8
8MAINTAINER= pkgsrc-users@NetBSD.org 9MAINTAINER= pkgsrc-users@NetBSD.org
9HOMEPAGE= http://www.python.org/ 10HOMEPAGE= http://www.python.org/
10COMMENT= Interpreted, interactive, object-oriented programming language 11COMMENT= Interpreted, interactive, object-oriented programming language
11LICENSE= python-software-foundation 12LICENSE= python-software-foundation
12 13
13CONFLICTS+= python-[0-9]* 14CONFLICTS+= python-[0-9]*
14 15
15PLIST_AWK+= -f ${PKGSRCDIR}/lang/python/plist-python.awk 16PLIST_AWK+= -f ${PKGSRCDIR}/lang/python/plist-python.awk
16PLIST_AWK_ENV+= PYVERS=34 17PLIST_AWK_ENV+= PYVERS=34
17PRINT_PLIST_AWK+= /^[^@]/ && /[^\/]+\.py[co]$$/ { 18PRINT_PLIST_AWK+= /^[^@]/ && /[^\/]+\.py[co]$$/ {
18PRINT_PLIST_AWK+= gsub(/__pycache__\//, "") 19PRINT_PLIST_AWK+= gsub(/__pycache__\//, "")
@@ -112,26 +113,46 @@ TEST_TARGET= test @@ -112,26 +113,46 @@ TEST_TARGET= test
112INSTALL_TARGET= altinstall 113INSTALL_TARGET= altinstall
113 114
114REPLACE_INTERPRETER+= py34 115REPLACE_INTERPRETER+= py34
115REPLACE.py34.old= .*python[^ ]* 116REPLACE.py34.old= .*python[^ ]*
116REPLACE.py34.new= ${PREFIX}/bin/python${PY_VER_SUFFIX} 117REPLACE.py34.new= ${PREFIX}/bin/python${PY_VER_SUFFIX}
117REPLACE_FILES.py34= Lib/*.py Lib/*/*.py Lib/*/*/*.py Lib/*/*/*/*.py 118REPLACE_FILES.py34= Lib/*.py Lib/*/*.py Lib/*/*/*.py Lib/*/*/*/*.py
118 119
119SUBST_CLASSES+= findlib 120SUBST_CLASSES+= findlib
120SUBST_MESSAGE.findlib= Fixing find_library_file on Darwin. 121SUBST_MESSAGE.findlib= Fixing find_library_file on Darwin.
121SUBST_STAGE.findlib= pre-configure 122SUBST_STAGE.findlib= pre-configure
122SUBST_FILES.findlib= Lib/distutils/unixccompiler.py 123SUBST_FILES.findlib= Lib/distutils/unixccompiler.py
123SUBST_SED.findlib= -e 's,/usr/local,${PREFIX},' 124SUBST_SED.findlib= -e 's,/usr/local,${PREFIX},'
124 125
 126# XXX: It might be needed to add manually more paths like ${PREFIX}/qt5/lib
 127# Testing:
 128# >>> from ctypes.util import find_library
 129# >>> find_library("m")
 130# 'libm.so.0'
 131# >>> find_library("crypto")
 132# 'libcrypto.so.11'
 133# >>> find_library("GL")
 134# 'libGL.so.2'
 135# >>> find_library("curl")
 136# 'libcurl.so.4'
 137
 138SUBST_CLASSES+= pfindlib
 139SUBST_MESSAGE.pfindlib= Fixing find_library() on POSIX-like (excluding Darwin) systems.
 140SUBST_STAGE.pfindlib= pre-configure
 141SUBST_FILES.pfindlib= Lib/ctypes/util.py
 142SUBST_SED.pfindlib= -e 's!\(-Wl,-t -o\)!${COMPILER_RPATH_FLAG}${PREFIX}/lib -L${PREFIX}/lib \1!'
 143
 144.include "options.mk"
 145
125SUBST_CLASSES+= sslbase 146SUBST_CLASSES+= sslbase
126SUBST_MESSAGE.sslbase= Fixing OpenSSL base directory to find header file. 147SUBST_MESSAGE.sslbase= Fixing OpenSSL base directory to find header file.
127SUBST_STAGE.sslbase= pre-configure 148SUBST_STAGE.sslbase= pre-configure
128SUBST_FILES.sslbase= setup.py 149SUBST_FILES.sslbase= setup.py
129SUBST_VARS.sslbase= SSLBASE 150SUBST_VARS.sslbase= SSLBASE
130 151
131CHECK_INTERPRETER_SKIP= lib/python${PY_VER_SUFFIX}/venv/scripts/posix/pydoc 152CHECK_INTERPRETER_SKIP= lib/python${PY_VER_SUFFIX}/venv/scripts/posix/pydoc
132 153
133.if ${OPSYS} == "HPUX" 154.if ${OPSYS} == "HPUX"
134post-install: 155post-install:
135 ${LN} -fs ${DESTDIR}${PREFIX}/lib/libpython3.4.sl \ 156 ${LN} -fs ${DESTDIR}${PREFIX}/lib/libpython3.4.sl \
136 ${DESTDIR}${PREFIX}/lib/libpython3.4.sl.1.0 157 ${DESTDIR}${PREFIX}/lib/libpython3.4.sl.1.0
137.endif 158.endif

File Added: pkgsrc/lang/python34/Attic/options.mk
# $NetBSD: options.mk,v 1.1 2016/09/18 12:36:41 kamil Exp $

PKG_OPTIONS_VAR=	PKG_OPTIONS.python27
PKG_SUPPORTED_OPTIONS+=	x11
PKG_SUGGESTED_OPTIONS=	x11

.include "../../mk/bsd.prefs.mk"
.include "../../mk/bsd.options.mk"

.if !empty(PKG_OPTIONS:Mx11)
# Support for native X11 paths as an option
# This code is no-op for modular X11, however for simplicity don't make it conditional.
SUBST_CLASSES+=			x11findlib
SUBST_MESSAGE.x11findlib=	Fixing find_library() for native X11.
SUBST_STAGE.x11findlib=		pre-configure
SUBST_FILES.x11findlib=		Lib/ctypes/util.py
SUBST_SED.x11findlib=		-e 's!\(-Wl,-t -o\)!${COMPILER_RPATH_FLAG}${X11BASE}/lib -L${X11BASE}/lib \1!'

# Required to get definition of X11BASE and retain X11 rpath paths for linker
# We need to pass rpath to _ctypes.so to get functional dlopen(3) for X11 libs
USE_X11=		yes

SUBST_CLASSES+=		cdlopen
SUBST_MESSAGE.cdlopen=	Handle X11BASE paths in dlopen(3) calls of _ctypes.so
SUBST_STAGE.cdlopen=	pre-configure
SUBST_FILES.cdlopen=	setup.py
SUBST_SED.cdlopen=	-e "s!\(libraries=\[\],\)!\1 runtime_library_dirs=\['${X11BASE}/lib'\],!"
.endif