Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / platform / osx / make_dmg.sh
1 #!/bin/bash
2 #
3 # Syntax: make_dmg.sh <builddir>
4 #
5 # e.g. make_dmg.sh /Users/carl/cdist
6
7 # Don't set -e here as egrep (used a few times) returns 1 if no matches
8 # were found.
9
10 version=`cat wscript | egrep ^VERSION | awk '{print $3}' | sed -e "s/'//g"`
11
12 # DMG size in megabytes
13 DMG_SIZE=256
14 ENV=/Users/carl/Environments/osx/10.6
15 ROOT=$1
16
17 # This is our work area for making up the .dmgs
18 mkdir -p build/platform/osx
19 cd build/platform/osx
20
21 function universal_copy {
22     for f in $1/32/$2; do
23         if [ -h $f ]; then
24             ln -s $(readlink $f) "$3/`basename $f`"
25         else
26             g=`echo $f | sed -e "s/\/32\//\/64\//g"`
27             mkdir -p "$3"
28             lipo -create $f $g -output "$3/`basename $f`"
29         fi
30     done
31 }
32
33 function universal_copy_lib {
34     for f in $1/32/lib/$2*.dylib; do
35         if [ -h $f ]; then
36             ln -s $(readlink $f) "$3/`basename $f`"
37         else
38             g=`echo $f | sed -e "s/\/32\//\/64\//g"`
39             mkdir -p "$3"
40             lipo -create $f $g -output "$3/`basename $f`"
41         fi
42     done
43     to_relink="$to_relink|$2"
44 }
45
46 # @param #1 directory to copy to
47 function copy_libs {
48     local dest="$1"
49     universal_copy_lib $ROOT libcxml "$dest"
50     universal_copy_lib $ROOT libdcp-1.0 "$dest"
51     universal_copy_lib $ROOT libasdcp-cth "$dest"
52     universal_copy_lib $ROOT libkumu-cth "$dest"
53     universal_copy_lib $ROOT libsub "$dest"
54     universal_copy_lib $ROOT libopenjp2 "$dest"
55     universal_copy_lib $ROOT libavdevice "$dest"
56     universal_copy_lib $ROOT libavformat "$dest"
57     universal_copy_lib $ROOT libavfilter "$dest"
58     universal_copy_lib $ROOT libavutil "$dest"
59     universal_copy_lib $ROOT libavcodec "$dest"
60     universal_copy_lib $ROOT libswscale "$dest"
61     universal_copy_lib $ROOT libpostproc "$dest"
62     universal_copy_lib $ROOT libswresample "$dest"
63     universal_copy $ROOT src/dcpomatic/build/src/lib/libdcpomatic2.dylib "$dest"
64     universal_copy $ROOT src/dcpomatic/build/src/wx/libdcpomatic2-wx.dylib "$dest"
65     universal_copy_lib $ENV libboost_system "$dest"
66     universal_copy_lib $ENV libboost_filesystem "$dest"
67     universal_copy_lib $ENV libboost_thread "$dest"
68     universal_copy_lib $ENV libboost_date_time "$dest"
69     universal_copy_lib $ENV libboost_locale "$dest"
70     universal_copy_lib $ENV libboost_regex "$dest"
71     universal_copy_lib $ENV libxml++ "$dest"
72     universal_copy_lib $ENV libxslt "$dest"
73     universal_copy_lib $ENV libxml2 "$dest"
74     universal_copy_lib $ENV libglibmm-2.4 "$dest"
75     universal_copy_lib $ENV libgobject "$dest"
76     universal_copy_lib $ENV libgthread "$dest"
77     universal_copy_lib $ENV libgmodule "$dest"
78     universal_copy_lib $ENV libsigc "$dest"
79     universal_copy_lib $ENV libglib-2 "$dest"
80     universal_copy_lib $ENV libintl "$dest"
81     universal_copy_lib $ENV libsndfile "$dest"
82     universal_copy_lib $ENV libMagick++ "$dest"
83     universal_copy_lib $ENV libMagickCore "$dest"
84     universal_copy_lib $ENV libMagickWand "$dest"
85     universal_copy_lib $ENV libssh "$dest"
86     universal_copy_lib $ENV libwx "$dest"
87     universal_copy_lib $ENV libfontconfig "$dest"
88     universal_copy_lib $ENV libfreetype "$dest"
89     universal_copy_lib $ENV libexpat "$dest"
90     universal_copy_lib $ENV libltdl "$dest"
91     universal_copy_lib $ENV libxmlsec1 "$dest"
92     universal_copy_lib $ENV libzip "$dest"
93     universal_copy_lib $ENV libcurl "$dest"
94     universal_copy_lib $ENV libffi "$dest"
95     universal_copy_lib $ENV libpango "$dest"
96     universal_copy_lib $ENV libcairo "$dest"
97     universal_copy_lib $ENV libpixman "$dest"
98     universal_copy_lib $ENV libharfbuzz "$dest"
99     universal_copy_lib $ENV libsamplerate "$dest"
100     universal_copy_lib $ENV libicui18n "$dest"
101     universal_copy_lib $ENV libicudata "$dest"
102     universal_copy_lib $ENV libicuio "$dest"
103     universal_copy_lib $ENV libicule "$dest"
104     universal_copy_lib $ENV libiculx "$dest"
105     universal_copy_lib $ENV libicutest "$dest"
106     universal_copy_lib $ENV libicutu "$dest"
107     universal_copy_lib $ENV libicuuc "$dest"
108     universal_copy_lib $ENV libFLAC "$dest"
109     universal_copy_lib $ENV libvorbis "$dest"
110     universal_copy_lib $ENV libogg "$dest"
111 }
112
113 # @param #1 directory to copy to
114 function copy_resources {
115     local dest="$1"
116     cp $ROOT/32/src/dcpomatic/graphics/osx/dcpomatic2.icns "$dest"
117     cp $ROOT/32/src/dcpomatic/graphics/osx/dcpomatic2_kdm.icns "$dest"
118     cp $ROOT/32/src/dcpomatic/graphics/osx/dcpomatic2_server.icns "$dest"
119     cp $ROOT/32/src/dcpomatic/graphics/osx/dcpomatic2_batch.icns "$dest"
120     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/colour_conversions.png "$dest"
121     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/defaults.png "$dest"
122     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/kdm_email.png "$dest"
123     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/servers.png "$dest"
124     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/tms.png "$dest"
125     cp $ROOT/32/src/dcpomatic/graphics/osx/preferences/keys.png "$dest"
126     cp $ROOT/32/src/dcpomatic/fonts/LiberationSans-Regular.ttf "$dest"
127     cp $ROOT/32/src/dcpomatic/fonts/LiberationSans-Italic.ttf "$dest"
128     cp $ROOT/32/src/dcpomatic/fonts/LiberationSans-Bold.ttf "$dest"
129     cp $ROOT/32/src/dcpomatic/graphics/splash.png "$dest"
130     cp $ROOT/32/src/dcpomatic/graphics/src/dcpomatic2_server_small.png "$dest"
131
132     # i18n: DCP-o-matic .mo files
133     for lang in de_DE es_ES fr_FR it_IT sv_SE nl_NL ru_RU pl_PL da_DK pt_PT pt_BR sk_SK cs_CZ uk_UA zh_CN; do
134         mkdir -p "$dest/$lang/LC_MESSAGES"
135         cp $ROOT/32/src/dcpomatic/build/src/lib/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
136         cp $ROOT/32/src/dcpomatic/build/src/wx/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
137         cp $ROOT/32/src/dcpomatic/build/src/tools/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
138     done
139
140     # i18n: wxWidgets .mo files
141     for lang in de es fr it sv nl ru pl da cs; do
142         mkdir "$dest/$lang"
143         cp $ENV/64/share/locale/$lang/LC_MESSAGES/wxstd.mo "$dest/$lang"
144     done
145 }
146
147 # param $1 list of things that link to other things
148 function relink {
149     to_relink=`echo $to_relink | sed -e "s/\+//g"`
150     local linkers=("$@")
151
152     for obj in "${linkers[@]}"; do
153         deps=`otool -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu)"`
154         changes=""
155         for dep in $deps; do
156             base=`basename $dep`
157             # $dep will be a path within 64/; make a 32/ path too
158             dep32=`echo $dep | sed -e "s/\/64\//\/32\//g"`
159             changes="$changes -change $dep @executable_path/../lib/$base -change $dep32 @executable_path/../lib/$base"
160         done
161         if test "x$changes" != "x"; then
162             install_name_tool $changes "$obj"
163         fi
164     done
165 }
166
167 # @param #1 .app directory
168 # @param #2 full name e.g. DCP-o-matic Batch Converter
169 function make_dmg {
170     local appdir="$1"
171     local full_name="$2"
172     tmp_dmg=dcpomatic_tmp.dmg
173     dmg="$full_name $version.dmg"
174     vol_name=DCP-o-matic-$version
175
176     mkdir -p $vol_name
177     cp -a "$appdir" $vol_name
178     ln -s /Applications "$vol_name/Applications"
179
180     rm -f $tmp_dmg "$dmg"
181     hdiutil create -srcfolder $vol_name -volname $vol_name -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size $DMG_SIZE $tmp_dmg
182     attach=$(hdiutil attach -readwrite -noverify -noautoopen $tmp_dmg)
183     device=`echo $attach | egrep '^/dev/' | sed 1q | awk '{print $5}'`
184     sleep 5
185
186     echo '
187   tell application "Finder"
188     tell disk "'$vol_name'"
189            open
190            set current view of container window to icon view
191            set toolbar visible of container window to false
192            set statusbar visible of container window to false
193            set the bounds of container window to {400, 200, 650, 370}
194            set theViewOptions to the icon view options of container window
195            set arrangement of theViewOptions to not arranged
196            set icon size of theViewOptions to 64
197            set position of item "'$appdir'" of container window to {90, 80}
198            set position of item "Applications" of container window to {220, 80}
199            close
200            open
201            update without registering applications
202            delay 5
203      end tell
204    end tell
205 ' | osascript
206
207     chmod -Rf go-w /Volumes/"$vol_name"/"$appdir"
208     sync
209
210     hdiutil eject $device
211     hdiutil convert -format UDZO $tmp_dmg -imagekey zlib-level=9 -o "$dmg"
212     sips -i "$appdir/Contents/Resources/dcpomatic2.icns"
213     DeRez -only icns "$appdir/Contents/Resources/dcpomatic2.icns" > "$appdir/Contents/Resources/DCP-o-matic.rsrc"
214     Rez -append "$appdir/Contents/Resources/DCP-o-matic.rsrc" -o "$dmg"
215     SetFile -a C "$dmg"
216     rm $tmp_dmg
217     rm -rf $vol_name
218 }
219
220 # @param #1 appdir
221 function setup {
222     appdir="$1"
223     approot="$appdir/Contents"
224     rm -rf "$appdir"
225     mkdir -p "$approot/MacOS"
226     mkdir -p "$approot/lib"
227     mkdir -p "$approot/Resources"
228
229     to_relink="dcpomatic"
230     copy_libs "$approot/lib"
231     copy_resources "$approot/Resources"
232 }
233
234 # DCP-o-matic main
235 setup "DCP-o-matic 2.app"
236 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2 "$approot/MacOS"
237 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_cli "$approot/MacOS"
238 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_create "$approot/MacOS"
239 universal_copy $ROOT bin/ffprobe "$approot/MacOS"
240 cp $ROOT/32/src/dcpomatic/build/platform/osx/dcpomatic2.Info.plist "$approot/Info.plist"
241 rl=("$approot/MacOS/dcpomatic2" "$approot/MacOS/dcpomatic2_cli" "$approot/MacOS/ffprobe" "$approot/lib/"*.dylib)
242 relink "${rl[@]}"
243 make_dmg "$appdir" "DCP-o-matic"
244
245 # DCP-o-matic KDM Creator
246 setup "DCP-o-matic 2 KDM Creator.app"
247 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_kdm "$approot/MacOS"
248 cp $ROOT/32/src/dcpomatic/build/platform/osx/dcpomatic2_kdm.Info.plist "$approot/Info.plist"
249 rl=("$approot/MacOS/dcpomatic2_kdm" "$approot/lib/"*.dylib)
250 relink "${rl[@]}"
251 make_dmg "$appdir" "DCP-o-matic KDM Creator"
252
253 # DCP-o-matic Encode Server
254 setup "DCP-o-matic 2 Encode Server.app"
255 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_server "$approot/MacOS"
256 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_server_cli "$approot/MacOS"
257 cp $ROOT/32/src/dcpomatic/build/platform/osx/dcpomatic2_server.Info.plist "$approot/Info.plist"
258 rl=("$approot/MacOS/dcpomatic2_server" "$approot/MacOS/dcpomatic2_server_cli" "$approot/lib/"*.dylib)
259 relink "${rl[@]}"
260 make_dmg "$appdir" "DCP-o-matic Encode Server"
261
262 # DCP-o-matic Batch Converter
263 setup "DCP-o-matic 2 Batch converter.app"
264 universal_copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_batch "$approot/MacOS"
265 cp $ROOT/32/src/dcpomatic/build/platform/osx/dcpomatic2_batch.Info.plist "$approot/Info.plist"
266 rl=("$approot/MacOS/dcpomatic2_batch" "$approot/lib/"*.dylib)
267 relink "${rl[@]}"
268 make_dmg "$appdir" "DCP-o-matic Batch Converter"