9 return os
.popen(command
).read()
11 def dylib_lst(input_file
):
12 return sh("otool -L %s | grep -e '\t' | awk '{ print $1 }'" % input_file
)
14 sys_re
= re
.compile("/System")
15 exe_re
= re
.compile("@executable_path")
17 def is_user_lib(libname
, input_file
):
18 return not sys_re
.match(libname
) and \
19 not exe_re
.match(libname
) and \
20 not "libobjc" in libname
and \
21 not "libSystem" in libname
and \
22 not "libgcc" in libname
and \
23 not os
.path
.basename(input_file
) in libname
and \
26 def user_dylib_lst(input_file
):
27 return [lib
for lib
in dylib_lst(input_file
).split("\n") if
28 is_user_lib(lib
, input_file
)]
34 return os
.path
.join(bundle_name(), 'Contents', 'Info.plist')
36 def target_directory():
37 return os
.path
.join(bundle_name(), 'Contents', 'MacOS')
40 return os
.path
.join(target_directory(), 'mplayer2')
43 if os
.path
.isdir(bundle_name()):
44 shutil
.rmtree(bundle_name())
46 os
.path
.join('TOOLS', 'osxbundle', bundle_name()),
50 shutil
.copy('mplayer', target_binary())
52 def run_install_name_tool(target_file
, dylib_path
, dest_dir
, root
=True):
53 new_dylib_path
= os
.path
.join("@executable_path", "lib",
54 os
.path
.basename(dylib_path
))
56 sh("install_name_tool -change %s %s %s" % \
57 (dylib_path
, new_dylib_path
, target_file
))
59 sh("install_name_tool -id %s %s" % \
60 (new_dylib_path
, os
.path
.join(dest_dir
,
61 os
.path
.basename(dylib_path
))))
63 def cp_dylibs(target_file
, dest_dir
):
64 for dylib_path
in user_dylib_lst(target_file
):
65 dylib_dest_path
= os
.path
.join(dest_dir
, os
.path
.basename(dylib_path
))
66 shutil
.copy(dylib_path
, dylib_dest_path
)
67 os
.chmod(dylib_dest_path
, 0o755)
68 cp_dylibs(dylib_dest_path
, dest_dir
)
70 def fix_dylibs_paths(target_file
, dest_dir
, root
=True):
71 for dylib_path
in user_dylib_lst(target_file
):
72 dylib_dest_path
= os
.path
.join(dest_dir
, os
.path
.basename(dylib_path
))
73 run_install_name_tool(target_file
, dylib_path
, dest_dir
, root
)
74 fix_dylibs_paths(dylib_dest_path
, dest_dir
, False)
76 def apply_plist_template(plist_file
, version
):
77 sh("sed -i -e 's/{{VERSION}}/%s/g' %s" % (version
, plist_file
))
79 version
= sh("TOOLS/osxbundle/version.sh").strip()
81 print("Creating Mac OS X application bundle (version: %s)..." % version
)
85 apply_plist_template(target_plist(), version
)
86 cp_dylibs(sys
.argv
[1], os
.path
.join(target_directory(), "lib"))
87 fix_dylibs_paths(target_binary(), os
.path
.join(target_directory(), "lib"))