- Updated the packaging script to fit to my new config
[mldemos:mldemos.git] / packageOSX.sh
1 #!/bin/sh
2
3 appName='MLDemos'
4 myPath=$appName'.app/Contents/'
5 opencvPath='/usr/local/lib/'
6 opencvListedPath='lib/'
7 opencvVersion='.2.4.dylib';
8 qtPath=''
9 #opencvPath='/Users/basilio/Code/OpenCV-2.3.1a/build/lib/'
10 #qtPath='/Users/basilio/QtSDK/Desktop/Qt/4.8.0/gcc/lib/'
11
12 names=( libopencv_core libopencv_legacy libopencv_highgui libopencv_ml libopencv_features2d libopencv_imgproc libopencv_calib3d libopencv_video libopencv_flann libopencv_contrib libopencv_gpu libopencv_objdetect)
13 namesQT=( QtGui QtCore QtNetwork QtOpenGL OpenGL AGL QtTest QtSvg QtXml QtWebKit phonon QtDBus QtXmlPatterns)
14 namesQTadd=( QtTest QtWebKit phonon QtXmlPatterns)
15 #namesQTadd=( QtWebKit phonon QtDBus QtXmlPatterns)
16 framework='@executable_path/../Frameworks/'
17 frameworkQT='.framework/Versions/4/'
18
19 #first we deploy
20 echo 'macdeployqt' $appName'.app'
21 eval 'macdeployqt' $appName'.app'
22
23 ##########################
24 #   LINKS IN EXECUTABLE  #
25 ##########################
26 # we start with changing the links in the executable
27 for name in ${names[@]}
28 do
29         echo 'install_name_tool -change lib/'$name$opencvVersion $framework$name$opencvVersion $myPath'MacOS/'$appName
30         eval 'install_name_tool -change lib/'$name$opencvVersion $framework$name$opencvVersion $myPath'MacOS/'$appName
31 #       echo 'install_name_tool -change '$opencvPath$name'.2.3.dylib' $framework$name'.2.3.dylib' $myPath'MacOS/'$appName
32 #       eval 'install_name_tool -change '$opencvPath$name'.2.3.dylib' $framework$name'.2.3.dylib' $myPath'MacOS/'$appName
33 done;
34 echo '\n'
35
36 ##########################
37 #      OPENCV FILES      #
38 ##########################
39 # then we copy the opencv library files
40 for name in ${names[@]}
41 do
42         echo 'cp '$opencvPath$name$opencvVersion' ' $myPath'/Frameworks/'
43         eval 'cp '$opencvPath$name$opencvVersion' ' $myPath'/Frameworks/'
44 done;
45 echo '\n'
46
47 # now we change the id on the libs we have copied inside the package
48 for name in ${names[@]}
49 do
50         echo 'install_name_tool -id '$framework$name$opencvVersion $myPath'Frameworks/'$name$opencvVersion
51         eval 'install_name_tool -id '$framework$name$opencvVersion $myPath'Frameworks/'$name$opencvVersion
52 done;
53 echo '\n'
54
55 # then we change the links in the libs we have copied inside the package
56 for name in ${names[@]}
57 do
58         for name2 in ${names[@]}
59         do
60                 echo 'install_name_tool -change '$opencvListedPath$name$opencvVersion $framework$name$opencvVersion $myPath'Frameworks/'$name2$opencvVersion
61                 eval 'install_name_tool -change '$opencvListedPath$name$opencvVersion $framework$name$opencvVersion $myPath'Frameworks/'$name2$opencvVersion
62         done;
63         echo '\n'
64 done;
65
66 # if highgui uses non-QT stuff
67 #guiLibs=( libavcodec.54 libavformat.54 libavutil.51 libswscale.2 libfaac.0 libmp3lame.0 libtheoraenc.1 libtheoradec.1 libogg.0 libx264.125)
68 guiLibs=( libavcodec.54 libavformat.54 libavutil.51 libswscale.2 libfaac.0 libmp3lame.0 libtheoraenc.1 libtheoradec.1 libogg.0 libx264.125)
69 #guiLibs=( libjpeg.8 libz.1 libpng14.14 libtiff.3 libjasper.1 libavcodec.54 libavformat.54 libavutil.51 libswscale.2 libbz2.1.0 libdirac_encoder.0 libdirac_decoder.0 libfaac.0 libfaad.2 libmp3lame.0 libschroedinger-1.0.0 libspeex.1 libtheoraenc.1 libtheoradec.1 libogg.0 libvorbisenc.2 libvorbis.0 libx264.125 liborc-0.4.0)
70 for name in ${guiLibs[@]}
71 do
72         echo 'cp /usr/local/lib/'$name'.dylib ' $myPath'/Frameworks/'
73         eval 'cp /usr/local/lib/'$name'.dylib ' $myPath'/Frameworks/'
74         echo 'install_name_tool -id '$framework$name'.dylib' $myPath'Frameworks/'$name'.dylib'
75         eval 'install_name_tool -id '$framework$name'.dylib' $myPath'Frameworks/'$name'.dylib'
76         echo 'install_name_tool -change /usr/local/lib/'$name'.dylib ' $framework$name'.dylib' $myPath'Frameworks/libopencv_highgui'$opencvVersion
77         eval 'install_name_tool -change /usr/local/lib/'$name'.dylib ' $framework$name'.dylib' $myPath'Frameworks/libopencv_highgui'$opencvVersion
78         for name2 in ${guiLibs[@]}
79         do
80                 echo 'install_name_tool -change /usr/local/lib/'$name2'.dylib ' $framework$name2'.dylib' $myPath'Frameworks/'$name'.dylib'
81                 eval 'install_name_tool -change /usr/local/lib/'$name2'.dylib ' $framework$name2'.dylib' $myPath'Frameworks/'$name'.dylib'
82         done;
83         echo '\n'
84 done;
85
86 # if we built opencv using QT
87 for name in ${namesQT[@]}
88 do
89         for name2 in ${names[@]}
90         do
91                 echo 'install_name_tool -change '$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'Frameworks/'$name2$opencvVersion
92                 eval 'install_name_tool -change '$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'Frameworks/'$name2$opencvVersion
93         done;
94         echo '\n'
95 done;
96
97
98 ########################
99 #  QT FRAMEWORK FILES  #
100 ########################
101 # copy frameworks from namesQTadd to the package
102 # will need to create the folders Resources and Versions/4/ first
103 for name in ${namesQTadd[@]}
104 do
105                 echo 'mkdir '$myPath'Frameworks/'$name'.framework'
106                 eval 'mkdir '$myPath'Frameworks/'$name'.framework'
107                 echo 'mkdir '$myPath'Frameworks/'$name'.framework/Resources'
108                 eval 'mkdir '$myPath'Frameworks/'$name'.framework/Resources'
109                 echo 'mkdir '$myPath'Frameworks/'$name'.framework/Versions'
110                 eval 'mkdir '$myPath'Frameworks/'$name'.framework/Versions'
111                 echo 'mkdir '$myPath'Frameworks/'$name'.framework/Versions/4'
112                 eval 'mkdir '$myPath'Frameworks/'$name'.framework/Versions/4'
113                 echo 'cp /Library/Frameworks/'$name$frameworkQT$name $myPath'Frameworks/'$name$frameworkQT$name
114                 eval 'cp /Library/Frameworks/'$name$frameworkQT$name $myPath'Frameworks/'$name$frameworkQT$name
115 done;
116
117 for name in ${namesQT[@]}
118 do
119         for name2 in ${namesQTadd[@]}
120         do
121                 echo 'install_name_tool -change '$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'Frameworks/'$name2$frameworkQT$name2
122                 eval 'install_name_tool -change '$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'Frameworks/'$name2$frameworkQT$name2
123         done;
124         echo '\n'
125 done;
126
127
128 ##########################
129 #  LINKS TO THE PLUGINS  #
130 ##########################
131 # last we go through our plugins to change these guys as well
132 echo 'mkdir '$myPath'MacOS/plugins'
133 eval 'mkdir '$myPath'MacOS/plugins'
134 echo 'mkdir '$myPath'MacOS/help'
135 eval 'mkdir '$myPath'MacOS/help'
136 echo 'cp plugins/*.dylib '$myPath'MacOS/plugins/'
137 eval 'cp plugins/*.dylib '$myPath'MacOS/plugins/'
138 echo 'cp help/* '$myPath'MacOS/help/'
139 eval 'cp help/* '$myPath'MacOS/help/'
140
141 for filename in plugins/*.dylib
142 do
143         # copy the file in the proper folder
144         for name in ${names[@]}
145         do
146                 echo 'install_name_tool -change '$opencvListedPath$name$opencvVersion $framework$name$opencvVersion $myPath'MacOS/'$filename
147                 eval 'install_name_tool -change '$opencvListedPath$name$opencvVersion $framework$name$opencvVersion $myPath'MacOS/'$filename
148 #               echo 'install_name_tool -change '$opencvPath$name'.2.3.dylib' $framework$name'.2.3.dylib' $myPath'MacOS/'$filename
149 #               eval 'install_name_tool -change '$opencvPath$name'.2.3.dylib' $framework$name'.2.3.dylib' $myPath'MacOS/'$filename
150         done;
151         for name in ${namesQT[@]}
152         do
153                 echo 'install_name_tool -change '$qtPath$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'MacOS/'$filename
154                 eval 'install_name_tool -change '$qtPath$name$frameworkQT$name $framework$name$frameworkQT$name $myPath'MacOS/'$filename
155         done;
156         echo '\n'
157 done;
158
159 #echo 'otool -L' $myPath'MacOS/'$appName
160 #eval 'otool -L' $myPath'MacOS/'$appName
161 #for filename in plugins/*.dylib
162 #do
163 #       echo 'otool -L' $myPath'Resources/'$filename
164 #       eval 'otool -L' $myPath'Resources/'$filename
165 #done;
166