1#!/usr/bin/python 2 3import os 4import sys 5import shutil 6import osxtools 7 8def usage(): 9 print """ 10 Usage: mkframework.py bundle [-l libfile] [-v version] 11 12 Creates the directory structure for a framework. 13 If libfile is given, it will be used as the frameworks executable, 14 otherwise the framework will just be an empty shell. 15 16 bundle: the path to the *.framework bundle 17 -l lib: copy lib into the bundle. 18 -v ver: use "ver" as the version instead of the standard 'A' 19 -f: overwrite existing files if version exists 20 """ 21 22 23if len(sys.argv) <= 1 or sys.argv[1] == "-?" : 24 usage() 25 sys.exit(0) 26 27 28 29version = "A" 30overwrite = False 31libfile = None 32bundle = None 33 34argp = 1 35 36while argp < len(sys.argv) : 37 if sys.argv[argp] == '-f': 38 overwrite = True; 39 argp = argp + 1 40 elif sys.argv[argp] == '-l' : 41 libfile = (sys.argv[argp + 1]) 42 argp = argp + 2 43 elif sys.argv[argp][0:2] == '-l' : 44 libfile = (sys.argv[argp][2:]) 45 argp = argp + 1 46 elif sys.argv[argp] == '-v' : 47 version = (sys.argv[argp + 1]) 48 argp = argp + 2 49 elif sys.argv[argp][0:2] == '-v' : 50 version = (sys.argv[argp][2:]) 51 argp = argp + 1 52 elif sys.argv[argp][0:1] == '-' : 53 print "Error: unknown option: " + sys.argv[argp] 54 usage() 55 sys.exit(1) 56 elif bundle == None: 57 bundle = sys.argv[argp] 58 argp = argp + 1 59 else: 60 print "Error: more than one bundle path specified!" 61 usage() 62 sys.exit(1) 63 64if bundle == None: 65 print "Error: no bundle path specified!" 66 usage() 67 sys.exit(1) 68 69if not os.path.isabs(bundle): 70 bundle = os.path.join(os.getenv("PWD"), bundle) 71 72if bundle[-10 : ] != ".framework": 73 bundle = bundle + ".framework" 74fwName = os.path.basename(bundle)[0: -10] 75 76if not os.path.exists(bundle): 77 os.makedirs(bundle, 0755) 78elif not os.path.isdir(bundle): 79 print "Error: '" + bundle + "' is no bundle path!" 80 usage() 81 sys.exit(1) 82 83versionPath = os.path.join(bundle, "Versions", version) 84 85if os.path.exists(versionPath): 86 if overwrite: 87 shutil.removetree(versionPath) 88 else: 89 print "Error: '" + versionPath + "' already exists!" 90 usage() 91 sys.exit(1) 92 93os.makedirs(versionPath, 0755) 94 95if libfile != None: 96 shutil.copy(libfile, os.path.join(versionPath, fwName)) 97 os.system("install_name_tool -id @executable_path/" + 98 os.path.join("../Frameworks", 99 fwName + ".framework", 100 "Versions", 101 version, 102 fwName) + 103 " " + 104 os.path.join(versionPath, fwName)) 105 106osxtools.createSymlinks(bundle, [ 107 ("Versions/Current", version), 108 (fwName, os.path.join("Versions/Current", fwName)), 109 ("Headers", "Versions/Current/Headers") 110]) 111 112