@@ -89,20 +89,22 @@ def _findLib_gcc(name):
8989 expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re .escape (name )
9090 fdout , ccout = tempfile .mkstemp ()
9191 os .close (fdout )
92- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; else CC=cc; fi;' \
92+ 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;' \
9393 '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
9494 try :
9595 f = os .popen (cmd )
9696 try :
9797 trace = f .read ()
9898 finally :
99- f .close ()
99+ rv = f .close ()
100100 finally :
101101 try :
102102 os .unlink (ccout )
103103 except OSError as e :
104104 if e .errno != errno .ENOENT :
105105 raise
106+ if rv == 10 :
107+ raise OSError , 'gcc or cc command not found'
106108 res = re .search (expr , trace )
107109 if not res :
108110 return None
@@ -129,7 +131,13 @@ def _get_soname(f):
129131 # assuming GNU binutils / ELF
130132 if not f :
131133 return None
132- cmd = "objdump -p -j .dynamic 2>/dev/null " + f
134+ cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
135+ "objdump -p -j .dynamic 2>/dev/null " + f
136+ f = os .popen (cmd )
137+ dump = f .read ()
138+ rv = f .close ()
139+ if rv == 10 :
140+ raise OSError , 'objdump command not found'
133141 f = os .popen (cmd )
134142 try :
135143 data = f .read ()
@@ -193,8 +201,32 @@ def _findLib_ldconfig(name):
193201 return None
194202 return res .group (0 )
195203
204+ def _findSoname_ldconfig (name ):
205+ import struct
206+ if struct .calcsize ('l' ) == 4 :
207+ machine = os .uname ()[4 ] + '-32'
208+ else :
209+ machine = os .uname ()[4 ] + '-64'
210+ mach_map = {
211+ 'x86_64-64' : 'libc6,x86-64' ,
212+ 'ppc64-64' : 'libc6,64bit' ,
213+ 'sparc64-64' : 'libc6,64bit' ,
214+ 's390x-64' : 'libc6,64bit' ,
215+ 'ia64-64' : 'libc6,IA-64' ,
216+ }
217+ abi_type = mach_map .get (machine , 'libc6' )
218+
219+ # XXX assuming GLIBC's ldconfig (with option -p)
220+ expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
221+ % (abi_type , re .escape (name ))
222+ res = re .search (expr ,
223+ os .popen ('/sbin/ldconfig -p 2>/dev/null' ).read ())
224+ if not res :
225+ return None
226+ return res .group (1 )
227+
196228 def find_library (name ):
197- return _get_soname ( _findLib_ldconfig ( name ) or _findLib_gcc (name ))
229+ return _findSoname_ldconfig ( name ) or _get_soname ( _findLib_gcc (name ))
198230
199231################################################################
200232# test code
0 commit comments