From ae9e7b5a4a28ef549cc047f94f41aae8c24de2b6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Apr 2013 21:44:46 +0200 Subject: make: add osxbundle-skip-deps This adds a way to generate a Mac OS X application bundle without the bundled dependencies. fixes #57 --- TOOLS/osxbundle.py | 71 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 21 deletions(-) (limited to 'TOOLS/osxbundle.py') diff --git a/TOOLS/osxbundle.py b/TOOLS/osxbundle.py index 8005f8c8c4..e0f240797f 100755 --- a/TOOLS/osxbundle.py +++ b/TOOLS/osxbundle.py @@ -4,6 +4,7 @@ import os import re import shutil import sys +from optparse import OptionParser def sh(command): return os.popen(command).read() @@ -28,27 +29,27 @@ 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(): +def bundle_name(binary_name): return "%s.app" % binary_name -def target_plist(): - return os.path.join(bundle_name(), 'Contents', 'Info.plist') +def target_plist(binary_name): + return os.path.join(bundle_name(binary_name), 'Contents', 'Info.plist') -def target_directory(): - return os.path.join(bundle_name(), 'Contents', 'MacOS') +def target_directory(binary_name): + return os.path.join(bundle_name(binary_name), 'Contents', 'MacOS') -def target_binary(): - return os.path.join(target_directory(), binary_name) +def target_binary(binary_name): + return os.path.join(target_directory(binary_name), binary_name) -def copy_bundle(): - if os.path.isdir(bundle_name()): - shutil.rmtree(bundle_name()) +def copy_bundle(binary_name): + if os.path.isdir(bundle_name(binary_name)): + shutil.rmtree(bundle_name(binary_name)) shutil.copytree( - os.path.join('TOOLS', 'osxbundle', bundle_name()), - bundle_name()) + os.path.join('TOOLS', 'osxbundle', bundle_name(binary_name)), + bundle_name(binary_name)) -def copy_binary(): - shutil.copy(binary_name, target_binary()) +def copy_binary(binary_name): + shutil.copy(binary_name, target_binary(binary_name)) def run_install_name_tool(target_file, dylib_path, dest_dir, root=True): new_dylib_path = os.path.join("@executable_path", "lib", @@ -83,12 +84,40 @@ def fix_dylibs_paths(target_file, dest_dir, root=True): 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() +def bundle_dependencies(binary_name): + lib_bundle_directory = os.path.join(target_directory(binary_name), "lib") + cp_dylibs(binary_name, lib_bundle_directory) + fix_dylibs_paths(target_binary(binary_name), lib_bundle_directory) -print("Creating Mac OS X application bundle (version: %s)..." % version) +def main(): + version = sh("TOOLS/osxbundle/version.sh").strip() -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")) + usage = "usage: %prog [options] arg" + parser = OptionParser(usage) + parser.add_option("-s", "--skip-deps", action="store_false", dest="deps", + default=True, + help="don't bundle the dependencies") + + (options, args) = parser.parse_args() + + if len(args) != 1: + parser.error("incorrect number of arguments") + else: + binary_name = args[0] + + print("Creating Mac OS X application bundle (version: %s)..." % version) + print("> copying bundle skeleton") + copy_bundle(binary_name) + print("> copying binary") + copy_binary(binary_name) + print("> generating Info.plist") + apply_plist_template(target_plist(binary_name), version) + + if options.deps: + print("> bundling dependencies") + bundle_dependencies(binary_name) + + print("done.") + +if __name__ == "__main__": + main() -- cgit v1.2.3