summaryrefslogtreecommitdiffstats
path: root/TOOLS/osxbundle.py
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2012-08-13 12:08:22 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2012-10-16 07:15:12 +0200
commitc4f68de1456ddb561f322b84e2ba1b790eec4c28 (patch)
treec5d9c9ae8e3be85edbbef4bdd0fe4324d601ad68 /TOOLS/osxbundle.py
parent6557f206efeb4569a42f1e4810172bc97fd64619 (diff)
downloadmpv-c4f68de1456ddb561f322b84e2ba1b790eec4c28.tar.bz2
mpv-c4f68de1456ddb561f322b84e2ba1b790eec4c28.tar.xz
TOOLS: add script for osx bundle generation
Add a make task and python script to create a Mac OS X Application Bundle to be used when compiling with the --enable-macosx-finder and --enable-macosx-bundle configure flags. The main svg icon was created by me and heavily inspired by Apple's iTunes and AppStore icon designs. We are still looking for something better. For the audio, movie and subtitles icons I added the main logo to MPlayer OSX Extended icons. Use with `make osxbundle` after running configure and make.
Diffstat (limited to 'TOOLS/osxbundle.py')
-rwxr-xr-xTOOLS/osxbundle.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/TOOLS/osxbundle.py b/TOOLS/osxbundle.py
new file mode 100755
index 0000000000..9f2f29d88b
--- /dev/null
+++ b/TOOLS/osxbundle.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+import os
+import re
+import shutil
+import sys
+
+def sh(command):
+ return os.popen(command).read()
+
+def dylib_lst(input_file):
+ return sh("otool -L %s | grep -e '\t' | awk '{ print $1 }'" % input_file)
+
+sys_re = re.compile("/System")
+exe_re = re.compile("@executable_path")
+binary_name = sys.argv[1]
+
+def is_user_lib(libname, input_file):
+ return not sys_re.match(libname) and \
+ not exe_re.match(libname) and \
+ not "libobjc" in libname and \
+ not "libSystem" in libname and \
+ not "libgcc" in libname and \
+ not os.path.basename(input_file) in libname and \
+ not libname == ''
+
+def user_dylib_lst(input_file):
+ return [lib for lib in dylib_lst(input_file).split("\n") if
+ is_user_lib(lib, input_file)]
+
+def bundle_name():
+ return "%s.app" % binary_name
+
+def target_plist():
+ return os.path.join(bundle_name(), 'Contents', 'Info.plist')
+
+def target_directory():
+ return os.path.join(bundle_name(), 'Contents', 'MacOS')
+
+def target_binary():
+ return os.path.join(target_directory(), binary_name)
+
+def copy_bundle():
+ if os.path.isdir(bundle_name()):
+ shutil.rmtree(bundle_name())
+ shutil.copytree(
+ os.path.join('TOOLS', 'osxbundle', bundle_name()),
+ bundle_name())
+
+def copy_binary():
+ shutil.copy(binary_name, target_binary())
+
+def run_install_name_tool(target_file, dylib_path, destination_directory):
+ new_dylib_path = os.path.join("@executable_path", "lib",
+ os.path.basename(dylib_path))
+
+ sh("install_name_tool -change %s %s %s" % \
+ (dylib_path, new_dylib_path, target_file))
+ sh("install_name_tool -id %s %s" % \
+ (new_dylib_path, os.path.join(destination_directory,
+ os.path.basename(dylib_path))))
+
+def cp_dylibs(target_file, destination_directory):
+ for dylib_path in user_dylib_lst(target_file):
+ dylib_destination_path = os.path.join(destination_directory,
+ os.path.basename(dylib_path))
+ shutil.copy(dylib_path, dylib_destination_path)
+ os.chmod(dylib_destination_path, 0o755)
+ cp_dylibs(dylib_destination_path, destination_directory)
+
+def fix_dylibs_paths(target_file, destination_directory):
+ for dylib_path in user_dylib_lst(target_file):
+ dylib_destination_path = os.path.join(destination_directory,
+ os.path.basename(dylib_path))
+ run_install_name_tool(target_file, dylib_path, destination_directory)
+ fix_dylibs_paths(dylib_destination_path, destination_directory)
+
+def apply_plist_template(plist_file, version):
+ sh("sed -i -e 's/{{VERSION}}/%s/g' %s" % (version, plist_file))
+
+version = sh("TOOLS/osxbundle/version.sh").strip()
+
+print("Creating Mac OS X application bundle (version: %s)..." % version)
+
+copy_bundle()
+copy_binary()
+apply_plist_template(target_plist(), version)
+cp_dylibs(sys.argv[1], os.path.join(target_directory(), "lib"))
+fix_dylibs_paths(target_binary(), os.path.join(target_directory(), "lib"))