3
0
Fork 0

updated to handle libstdc++ and libgcc_s

small_fixes
rgaudin 12 years ago
parent 22886e20d2
commit a18a16e9d3

@ -10,8 +10,8 @@ MODE_BINARY = 2
MODE_LIBRARY = 3 MODE_LIBRARY = 3
MODES = {'c': MODE_COMPONENT, MODES = {'c': MODE_COMPONENT,
'b': MODE_BINARY, 'b': MODE_BINARY,
'l': MODE_LIBRARY} 'l': MODE_LIBRARY}
is_library = False is_library = False
is_component = False is_component = False
@ -19,88 +19,88 @@ is_binary = False
def usage(): def usage():
print(u"Usage: %s MODE component/path.dylib" % sys.argv[0]) print(u"Usage: %s MODE component/path.dylib" % sys.argv[0])
print(u" MODE is c: component or b: binary or l: library") print(u" MODE is c: component or b: binary or l: library")
if len(sys.argv) < 3: if len(sys.argv) < 3:
usage() usage()
exit(0) exit(0)
component = sys.argv[-1] component = sys.argv[-1]
mode = MODES.get(sys.argv[-2].lower()) mode = MODES.get(sys.argv[-2].lower())
if not mode: if not mode:
usage() usage()
exit(1) exit(1)
# mode switchers # mode switchers
if mode == MODE_COMPONENT: if mode == MODE_COMPONENT:
is_component = True is_component = True
elif mode == MODE_LIBRARY: elif mode == MODE_LIBRARY:
is_library = True is_library = True
else: else:
is_binary = True is_binary = True
if not os.path.exists(component): if not os.path.exists(component):
print(u"Unable to access component at: %s" % component) print(u"Unable to access component at: %s" % component)
exit(1) exit(1)
# we'll also allow binaries to be fixed. # we'll also allow binaries to be fixed.
# #
if (is_library or is_component) and not component.endswith('.dylib'): if (is_library or is_component) and not component.endswith('.dylib'):
print(u"%s is not a dylib component" % component) print(u"%s is not a dylib component" % component)
exit(1) exit(1)
print("Fixing %s..." % component) print("Fixing %s..." % component)
basename = os.path.basename(component) basename = os.path.basename(component)
try: try:
name, ext = basename.rsplit('.', 1) name, ext = basename.rsplit('.', 1)
except ValueError: except ValueError:
name = basename name = basename
ext = '' ext = ''
libname = u'lib%s%s.0.dylib' % (name[0].upper(), name[1:]) libname = u'lib%s%s.0.dylib' % (name[0].upper(), name[1:])
# change ID if component to match new name/path # change ID if component to match new name/path
if is_component: if is_component:
os.system('install_name_tool -id %s %s' % (basename, component)) os.system('install_name_tool -id %s %s' % (basename, component))
# run otool to get a list of deps. # run otool to get a list of deps.
otool = subprocess.Popen(['otool', '-L', component], stdout=subprocess.PIPE) otool = subprocess.Popen(['otool', '-L', component], stdout=subprocess.PIPE)
otool_out, otool_err = otool.communicate() otool_out, otool_err = otool.communicate()
for line in otool_out.split('\n'): for line in otool_out.split('\n'):
if ('executable_path' in line if ('executable_path' in line
or 'libSystem' in line or 'libSystem' in line
or 'libstdc++' in line or ':' in line
or 'libgcc' in line or not len(line)
or ':' in line or 'aria2c' in basename):
or not len(line) continue
or 'aria2c' in basename): path, junk = line.strip().split(' (', 1)
continue # erroneous_links.append(path)
path, junk = line.strip().split(' (', 1)
# erroneous_links.append(path) _basename = os.path.basename(path).strip()
_basename = os.path.basename(path).strip() if _basename == basename:
continue
if _basename == basename:
continue # is it a library link?
match = re.match(r'lib([a-z\_\-\d\+]+)([\.?\d]*)\.dylib', _basename)
# is it a library link? if match:
match = re.match(r'lib([a-z\_\-\d]+)([\.?\d]*)\.dylib', _basename) print("match: %s" % match.groups()[0])
if match: if 'libstdc++' in line or 'libgcc' in line:
print("match: %s" % match.groups()[0]) newpath = u'/usr/lib/lib%s%s.dylib' % (match.groups()[0], match.groups()[1])
if is_component: elif is_component:
# newpath = u'@executable_path/../Frameworks/lib%s.dylib' % match.groups()[0] # newpath = u'@executable_path/../Frameworks/lib%s.dylib' % match.groups()[0]
newpath = u'@executable_path/lib%s.dylib' % match.groups()[0] newpath = u'@executable_path/lib%s.dylib' % match.groups()[0]
elif is_binary: elif is_binary:
# newpath = u'@executable_path/../../Frameworks/lib%s.dylib' % match.groups()[0] # newpath = u'@executable_path/../../Frameworks/lib%s.dylib' % match.groups()[0]
newpath = u'@executable_path/../lib%s.dylib' % match.groups()[0] newpath = u'@executable_path/../lib%s.dylib' % match.groups()[0]
else: else:
newpath = u'@loader_path/lib%s.dylib' % match.groups()[0] newpath = u'@loader_path/lib%s.dylib' % match.groups()[0]
print('install_name_tool -change %s %s %s' % (path, newpath, component)) print('install_name_tool -change %s %s %s' % (path, newpath, component))
os.system('install_name_tool -change %s %s %s' % (path, newpath, component)) os.system('install_name_tool -change %s %s %s' % (path, newpath, component))
continue continue
print('\tUnmatched: %s' % path) print('\tUnmatched: %s' % path)
Loading…
Cancel
Save