From 2c50e102949e6b6a7b532d8f9771ddc1d3bbf93f Mon Sep 17 00:00:00 2001 From: reg_ Date: Mon, 11 Jun 2012 17:10:20 +0000 Subject: [PATCH] fixed (for good) rpath issues on OSX --- src/macosx/cleanup_rpath.py | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 src/macosx/cleanup_rpath.py diff --git a/src/macosx/cleanup_rpath.py b/src/macosx/cleanup_rpath.py new file mode 100755 index 0000000..d635454 --- /dev/null +++ b/src/macosx/cleanup_rpath.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import sys +import os +import subprocess +import re + + +def usage(): + print(u"Usage: %s component/path.dylib" % sys.argv[0]) + +if len(sys.argv) < 2: + usage() + exit(0) + +component = sys.argv[1] + +if not os.path.exists(component): + print(u"Unable to access component at: %s" % component) + exit(1) + +if not component.endswith('.dylib'): + print(u"%s is not a dylib component" % component) + exit(1) + +print("Fixing %s..." % component) + +basename = os.path.basename(component) +name, ext = basename.rsplit('.', 1) +libname = u'lib%s%s.0.dylib' % (name[0].upper(), name[1:]) + +# run otool to get a list of deps. +otool = subprocess.Popen(['otool', '-L', component], stdout=subprocess.PIPE) +otool_out, otool_err = otool.communicate() + +for line in otool_out.split('\n'): + if ('executable_path' in line + or 'libSystem' in line + or 'libstdc++' in line + or ':' in line + or not len(line)): + continue + path, junk = line.strip().split(' (', 1) + # erroneous_links.append(path) + + _basename = os.path.basename(path).strip() + + # remove the libXX.0.dylib from the component (optionnal) + # doesn't seem to work. + if _basename == libname: + # os.system('install_name_tool -delete_rpath %s %s' % (path, component)) + continue + + # is it a library link? + match = re.match(r'lib([a-z\_\-\d]+)([\.?\d]*)\.dylib', _basename) + if match: + newpath = u'@executable_path/../Frameworks/lib%s.dylib' % match.groups()[0] + os.system('install_name_tool -change %s %s %s' % (path, newpath, component)) + continue + + print('\tUnmatched: %s' % path) \ No newline at end of file