1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#! /bin/sh -e
# DP: ctypes.util.find_library(): Determine the shared object name of a library
# DP: using ldconfig only, only fall back to objdump/gcc if ldconfig fails.
# DP: Raise exceptions if gcc or objdump cannot be found.
dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
pdir="-d $3"
dir="$3/"
elif [ $# -ne 1 ]; then
echo >&2 "usage: `basename $0`: -patch|-unpatch [-d <srcdir>]"
exit 1
fi
case "$1" in
-patch)
patch $pdir -f --no-backup-if-mismatch -p0 < $0
;;
-unpatch)
patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
;;
*)
echo >&2 "usage: `basename $0`: -patch|-unpatch [-d <srcdir>]"
exit 1
esac
exit 0
--- Lib/ctypes/util.py~ 2009-01-04 17:48:19.000000000 +0100
+++ Lib/ctypes/util.py 2009-01-04 18:10:45.000000000 +0100
@@ -49,18 +49,20 @@
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
fdout, ccout = tempfile.mkstemp()
os.close(fdout)
- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; else CC=cc; fi;' \
+ cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
try:
f = os.popen(cmd)
trace = f.read()
- f.close()
+ rv = f.close()
finally:
try:
os.unlink(ccout)
except OSError, e:
if e.errno != errno.ENOENT:
raise
+ if rv == 10:
+ raise OSError, 'gcc or cc command not found'
res = re.search(expr, trace)
if not res:
return None
@@ -82,7 +84,13 @@
# assuming GNU binutils / ELF
if not f:
return None
- cmd = "objdump -p -j .dynamic 2>/dev/null " + f
+ cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
+ "objdump -p -j .dynamic 2>/dev/null " + f
+ f = os.popen(cmd)
+ dump = f.read()
+ rv = f.close()
+ if rv == 10:
+ raise OSError, 'objdump command not found'
res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
if not res:
return None
@@ -115,6 +123,8 @@
else:
+ import platform
+
def _findLib_ldconfig(name):
# XXX assuming GLIBC's ldconfig (with option -p)
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
@@ -128,8 +138,24 @@
return None
return res.group(0)
+ def _findSoname_ldconfig(name):
+ mach_map = {
+ 'x86_64': 'libc6,x86-64',
+ 'ppc64': 'libc6,64bit',
+ }
+ abi_type = mach_map.get(platform.machine(), 'libc6')
+
+ # XXX assuming GLIBC's ldconfig (with option -p)
+ expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
+ % (abi_type, re.escape(name))
+ res = re.search(expr,
+ os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+ if not res:
+ return None
+ return res.group(1)
+
def find_library(name):
- return _get_soname(_findLib_ldconfig(name) or _findLib_gcc(name))
+ return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
################################################################
# test code
|