| 1 |
from subprocess import call |
| 2 |
import subprocess |
| 3 |
import shutil |
| 4 |
import os |
| 5 |
import pdb |
| 6 |
import fileinput |
| 7 |
import glob |
| 8 |
import sys |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
def change_link(link,new_link, bin_file): |
| 26 |
arguments = ['-change', link, new_link, bin_file] |
| 27 |
retcode = call(['install_name_tool'] + arguments) |
| 28 |
if retcode != 0: |
| 29 |
print "Failed ---------" |
| 30 |
print "changed link:", link, "to", new_link, 'in', bin_file, 'ret:', retcode |
| 31 |
|
| 32 |
def change_id(new_id, file_name): |
| 33 |
arguments = ['-id', new_id, file_name] |
| 34 |
retcode = call(['install_name_tool'] + arguments) |
| 35 |
print "changed id:", new_id, 'in', file_name, 'ret:', retcode |
| 36 |
|
| 37 |
def adjust_link(old_link, new_link, app_name, bin_name, suffix = '64'): |
| 38 |
|
| 39 |
change_id(new_link, app_name + '/Contents/Frameworks/' + new_link[new_link.rindex('/') + 1:]) |
| 40 |
change_link(old_link, new_link, app_name + '/Contents/Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix, suffix)) |
| 41 |
change_link(old_link, new_link, app_name + '/Contents/Frameworks/CsoundLib%s.framework/Versions/5.2/lib_csnd.dylib'%suffix) |
| 42 |
|
| 43 |
def deployWithPython(PRECISION, NEW_NAME, QUTECSOUND_VERSION, QtFrameworksDir, CsoundQtBinPath, PythonQtLibPaths, cs6, debug=False): |
| 44 |
if PythonQtLibPaths: |
| 45 |
py_ext = '-py' |
| 46 |
else: |
| 47 |
py_ext = '' |
| 48 |
if cs6: |
| 49 |
cs6_ext = '-cs6' |
| 50 |
else: |
| 51 |
cs6_ext = '' |
| 52 |
ORIGINAL_NAME = NEW_NAME + PRECISION + py_ext + cs6_ext |
| 53 |
if debug: |
| 54 |
ORIGINAL_NAME += '-debug' |
| 55 |
APP_NAME= NEW_NAME + PRECISION + py_ext + QUTECSOUND_VERSION + '.app' |
| 56 |
|
| 57 |
ORIG_APP_NAME = ORIGINAL_NAME + '.app' |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
arguments = [ORIG_APP_NAME, '-verbose=1'] |
| 64 |
retcode = call([QtBinDir + '/macdeployqt'] + arguments) |
| 65 |
|
| 66 |
add_path = False |
| 67 |
|
| 68 |
for line in fileinput.input( CsoundQtBinPath + '/' + ORIG_APP_NAME+ '/Contents/Info.plist', inplace=1): |
| 69 |
if line.strip().startswith('<string>????</string>'): |
| 70 |
add_path = True |
| 71 |
else: |
| 72 |
if add_path: |
| 73 |
print ''' <key>LSEnvironment</key> |
| 74 |
<array> |
| 75 |
<dict> |
| 76 |
<key>PATH</key> |
| 77 |
<string>/usr/local/bin</string> |
| 78 |
</dict> |
| 79 |
</array>''' |
| 80 |
add_path = False |
| 81 |
print line, |
| 82 |
|
| 83 |
if os.path.exists('../src/res/osx/QuteApp_f.app'): |
| 84 |
shutil.copytree('../src/res/osx/QuteApp_f.app', ORIG_APP_NAME + '/Contents/Resources/QuteApp_f.app', symlinks=True) |
| 85 |
if os.path.exists('../src/res/osx/QuteApp_d.app'): |
| 86 |
shutil.copytree('../src/res/osx/QuteApp_d.app', ORIG_APP_NAME + '/Contents/Resources/QuteApp_d.app', symlinks=True) |
| 87 |
|
| 88 |
shutil.copytree( |
| 89 |
'../src/Examples/McCurdy Collection', ORIG_APP_NAME + '/Contents/Resources/McCurdy Collection') |
| 90 |
shutil.copytree( |
| 91 |
'../src/Scripts', ORIG_APP_NAME + '/Contents/Resources/Scripts') |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
PythonQtPath = None |
| 99 |
if PythonQtLibPaths: |
| 100 |
for path in PythonQtLibPaths: |
| 101 |
if os.path.exists(path + 'libPythonQt.1.0.0.dylib'): |
| 102 |
PythonQtPath = path |
| 103 |
break |
| 104 |
if PythonQtPath: |
| 105 |
print "Using PythonQtPath: " + PythonQtPath |
| 106 |
shutil.copy(PythonQtPath + 'libPythonQt.1.0.0.dylib', ORIG_APP_NAME + '/Contents/Frameworks/libPythonQt.1.dylib') |
| 107 |
shutil.copy(PythonQtPath + 'libPythonQt_QtAll.1.0.0.dylib', ORIG_APP_NAME + '/Contents/Frameworks/libPythonQt_QtAll.1.dylib') |
| 108 |
arguments = ['-id', '@executable_path/../Frameworks/libPythonQt.1.dylib', |
| 109 |
'%s/Contents/Frameworks/libPythonQt.1.dylib'%(ORIG_APP_NAME)] |
| 110 |
retcode = call(['install_name_tool'] + arguments) |
| 111 |
arguments = ['-id', '@executable_path/../Frameworks/libPythonQt_QtAll.1.dylib', |
| 112 |
'%s/Contents/Frameworks/libPythonQt_QtAll.1.dylib'%(ORIG_APP_NAME)] |
| 113 |
retcode = call(['install_name_tool'] + arguments) |
| 114 |
|
| 115 |
change_link('libPythonQt.1.dylib', |
| 116 |
'@executable_path/../Frameworks/libPythonQt.1.dylib', |
| 117 |
'%s/Contents/MacOs/%s'%(ORIG_APP_NAME, ORIGINAL_NAME)) |
| 118 |
change_link('libPythonQt.1.dylib', |
| 119 |
'@executable_path/../Frameworks/libPythonQt.1.dylib', |
| 120 |
'%s/Contents/Frameworks/libPythonQt_QtAll.1.dylib'%(ORIG_APP_NAME)) |
| 121 |
change_link('libPythonQt_QtAll.1.dylib', |
| 122 |
'@executable_path/../Frameworks/libPythonQt_QtAll.1.dylib', |
| 123 |
'%s/Contents/MacOS/%s'%(ORIG_APP_NAME, ORIGINAL_NAME)) |
| 124 |
else: |
| 125 |
print "Can't find libPythonQt. Exiting." |
| 126 |
return |
| 127 |
|
| 128 |
change_link('libsndfile.1.dylib', |
| 129 |
'@executable_path/../Frameworks/libsndfile.1.dylib', |
| 130 |
'%s/Contents/MacOS/%s'%(ORIG_APP_NAME, ORIGINAL_NAME)) |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
QtLibs = ['QtCore', 'QtGui', 'QtXml', 'QtDBus', 'QtSvg', 'QtSql', 'QtXmlPatterns', 'QtOpenGL', 'QtNetwork', 'QtWebKit', 'phonon'] |
| 140 |
|
| 141 |
for lib in QtLibs: |
| 142 |
change_link('%s/gcc/lib/%s.framework/Versions/4/%s'%(QtFrameworksDir,lib,lib), |
| 143 |
'@executable_path/../Frameworks/%s.framework/Versions/4/%s'%(lib,lib), |
| 144 |
'%s/Contents/Frameworks/libPythonQt.1.dylib'%(ORIG_APP_NAME)) |
| 145 |
change_link('%s.framework/Versions/4/%s'%(lib,lib), |
| 146 |
'@executable_path/../Frameworks/%s.framework/Versions/4/%s'%(lib,lib), |
| 147 |
'%s/Contents/Frameworks/libPythonQt_QtAll.1.dylib'%(ORIG_APP_NAME)) |
| 148 |
change_link('%s.framework/Versions/4/%s'%(lib,lib), |
| 149 |
'@executable_path/../Frameworks/%s.framework/Versions/4/%s'%(lib,lib), |
| 150 |
'%s/Contents/Frameworks/libPythonQt.1.dylib'%(ORIG_APP_NAME)) |
| 151 |
change_link('%s/gcc/lib/%s.framework/Versions/4/%s'%(QtFrameworksDir,lib,lib), |
| 152 |
'@executable_path/../Frameworks/%s.framework/Versions/4/%s'%(lib,lib), |
| 153 |
'%s/Contents/Frameworks/libPythonQt_QtAll.1.dylib'%(ORIG_APP_NAME)) |
| 154 |
|
| 155 |
|
| 156 |
if (os.path.exists(APP_NAME)): |
| 157 |
shutil.rmtree(APP_NAME) |
| 158 |
os.rename(ORIG_APP_NAME, APP_NAME) |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
retcode = call(['tar', '-czvf', '%s%s-%s.tar.gz'%(NEW_NAME,PRECISION,QUTECSOUND_VERSION), APP_NAME]) |
| 163 |
|
| 164 |
def deployCsound(app_name, bin_name, doubles=True): |
| 165 |
suffix = '64' if doubles else '' |
| 166 |
cs_framework = '/Library/Frameworks/CsoundLib%s.framework'%suffix |
| 167 |
try: |
| 168 |
shutil.copytree(cs_framework, app_name + '/Contents/Frameworks/CsoundLib%s.framework'%suffix, symlinks=True ) |
| 169 |
except Exception: |
| 170 |
print "Warning: Csound Framework not copied" |
| 171 |
pass |
| 172 |
|
| 173 |
libs = { 'libsndfile.1.dylib': 'libsndfile.1.dylib', |
| 174 |
'libportaudio.2.dylib': 'libportaudio.dylib', |
| 175 |
'libportmidi.dylib': 'libportmidi.dylib', |
| 176 |
|
| 177 |
'liblo.0.dylib' : 'liblo.dylib', |
| 178 |
'libfltk.1.3.dylib' : 'libfltk.dylib', |
| 179 |
'libfltk_images.1.3.dylib' : 'libfltk_images.dylib', |
| 180 |
'libfluidsynth.1.dylib' : 'libfluidsynth.dylib', |
| 181 |
'libpng12.0.dylib' : 'libpng12.dylib', |
| 182 |
'libfluidsynth.1.dylib' : 'libfluidsynth.dylib'} |
| 183 |
|
| 184 |
lib_dir = '/usr/local/lib/' |
| 185 |
for lib, dest_lib in libs.items(): |
| 186 |
shutil.copy(lib_dir + lib, app_name + '/Contents/Frameworks/' + dest_lib ) |
| 187 |
adjust_link('/usr/local/lib/' + lib , '@executable_path/../Frameworks/' + dest_lib, app_name, bin_name, suffix) |
| 188 |
|
| 189 |
change_link('/Library/Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 190 |
'@executable_path/../Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 191 |
bin_name) |
| 192 |
change_link('/Library/Frameworks/CsoundLib%s.framework/Versions/5.2/lib_csnd.dylib'%suffix, |
| 193 |
'@executable_path/../Frameworks/CsoundLib%s.framework/Versions/5.2/lib_csnd.dylib'%suffix, |
| 194 |
bin_name) |
| 195 |
change_link('/Library/Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 196 |
'@executable_path/../Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 197 |
app_name + '/Contents/Frameworks/CsoundLib%s.framework/Versions/5.2/lib_csnd.dylib'%suffix) |
| 198 |
|
| 199 |
|
| 200 |
change_link('/usr/local/lib/libfltk.1.3.dylib', |
| 201 |
'@executable_path/../libfltk.dylib', |
| 202 |
app_name + '/Contents/Frameworks/libfltk_images.dylib') |
| 203 |
change_link('/usr/local/lib/libpng12.0.dylib', |
| 204 |
'@executable_path/../libpng12.dylib', |
| 205 |
app_name + '/Contents/Frameworks/libfltk_images.dylib') |
| 206 |
|
| 207 |
opcode_dir = app_name +'/Contents/Frameworks/CsoundLib%s.framework/Resources/Opcodes%s'%(suffix,suffix) |
| 208 |
opcode_libs = glob.glob(opcode_dir + '/*.dylib') |
| 209 |
|
| 210 |
for op_lib in opcode_libs: |
| 211 |
for dep_lib, dep_dest_lib in libs.items(): |
| 212 |
change_link('/usr/local/lib/' + dep_lib , '@executable_path/../Frameworks/' + dep_dest_lib, |
| 213 |
op_lib) |
| 214 |
change_link('/usr/local/lib/' + dep_lib , '@executable_path/../Frameworks/' + dep_dest_lib, |
| 215 |
op_lib) |
| 216 |
change_link('/Library/Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 217 |
'@executable_path/../Frameworks/CsoundLib%s.framework/Versions/5.2/CsoundLib%s'%(suffix,suffix), |
| 218 |
op_lib) |
| 219 |
|
| 220 |
if __name__=='__main__': |
| 221 |
|
| 222 |
if len(sys.argv) == 1: |
| 223 |
version = raw_input('Enter version number:') |
| 224 |
else: |
| 225 |
version = sys.argv[1] |
| 226 |
NEW_NAME='CsoundQt' |
| 227 |
QMakePath = '' |
| 228 |
QtFrameworksDir = subprocess.Popen([QMakePath + 'qmake', |
| 229 |
'-query', 'QT_INSTALL_LIBS'], |
| 230 |
stdout=subprocess.PIPE).communicate()[0].strip() |
| 231 |
QtBinDir = subprocess.Popen([QMakePath + 'qmake', |
| 232 |
'-query', 'QT_INSTALL_BINS'], |
| 233 |
stdout=subprocess.PIPE).communicate()[0].strip() |
| 234 |
|
| 235 |
if QMakePath == '': |
| 236 |
|
| 237 |
CsoundQtBinPath = './' |
| 238 |
else: |
| 239 |
CsoundQtBinPath = '../../qcs-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/bin' |
| 240 |
|
| 241 |
PythonQtLibPaths = ['/usr/local/lib/', '../../PythonQt2.1_Qt4.8/lib/', '../../../../PythonQt2.1_Qt4.8/lib/', './'] |
| 242 |
|
| 243 |
print "---------------- Making doubles package" |
| 244 |
deployWithPython('-d', NEW_NAME, version, QtFrameworksDir, CsoundQtBinPath,None, cs6=True) |
| 245 |
deployWithPython('-d', NEW_NAME, version, QtFrameworksDir, CsoundQtBinPath,PythonQtLibPaths, cs6=True) |