aboutsummaryrefslogtreecommitdiffstats
path: root/main/python/musl-find_library.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-08-11 11:16:15 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-08-11 11:19:42 +0200
commit837f731a38d0a2c1c20c6a4f86cd5368ff02a23b (patch)
treee0015ca90b53abaa00d4c4a05c86ec8aedabb4d0 /main/python/musl-find_library.patch
parent59b5199ab486881a75bdd72f45679f3dbbfacf4a (diff)
downloadaports-837f731a38d0a2c1c20c6a4f86cd5368ff02a23b.tar.bz2
aports-837f731a38d0a2c1c20c6a4f86cd5368ff02a23b.tar.xz
main/python: fix find_library with musl
ref #4512
Diffstat (limited to 'main/python/musl-find_library.patch')
-rw-r--r--main/python/musl-find_library.patch43
1 files changed, 43 insertions, 0 deletions
diff --git a/main/python/musl-find_library.patch b/main/python/musl-find_library.patch
new file mode 100644
index 0000000000..aad604c451
--- /dev/null
+++ b/main/python/musl-find_library.patch
@@ -0,0 +1,43 @@
+diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
+index 1e882e3..b265cc0 100644
+--- a/Lib/ctypes/util.py
++++ b/Lib/ctypes/util.py
+@@ -238,8 +238,37 @@ elif os.name == "posix":
+ return None
+ return res.group(1)
+
++ def _is_elf(filepath):
++ try:
++ with open(filepath, 'rb') as fh:
++ return fh.read(4) == b'\x7fELF'
++ except:
++ return False
++
++ def _find_libfile(name):
++ from glob import glob
++ # special case for libm, libcrypt and libpthread and musl
++ if name in ['m', 'crypt', 'pthread']:
++ name = 'c'
++ elif name in ['libm.so', 'libcrypt.so', 'libpthread.so']:
++ name = 'libc.so'
++ # search in standard locations
++ paths = ['/lib', '/usr/lib', '/usr/local/lib']
++ if 'LD_LIBRARY_PATH' in os.environ:
++ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths
++ for d in paths:
++ f = os.path.join(d, name)
++ if _is_elf(f):
++ return f
++
++ prefix = os.path.join(d, 'lib'+name)
++ for suffix in ['.so', '.so.*', '.*.so.*']:
++ for f in glob('{0}{1}'.format(prefix, suffix)):
++ if _is_elf(f):
++ return f
++
+ def find_library(name):
+- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
++ return _find_libfile(name) or _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+
+ ################################################################
+ # test code