Support for arm64 macOS builds.
[dcpomatic.git] / platform / osx / make_dmg.sh
1 #!/bin/bash
2 #
3 SYNTAX="make_dmg.sh <environment> <builddir> <type> <apple-id> <apple-password>"
4 # where <type> is arm-intel-64, intel-32-64 or arm64
5 #
6 # e.g. make_dmg.sh /Users/carl/osx-environment /Users/carl/cdist arm-intel-64 foo@bar.net opensesame
7
8 # Don't set -e here as egrep (used a few times) returns 1 if no matches
9 # were found.
10
11 version=`git describe --tags --abbrev=0 | sed -e "s/v//"`
12
13 # DMG size in megabytes
14 DMG_SIZE=256
15 ENV=$1
16 ROOT=$2
17 TYPE=$3
18 APPLE_ID=$4
19 APPLE_PASSWORD=$5
20
21 if [ "$TYPE" != "arm-intel-64" -a "$TYPE" != "intel-32-64" -a "$TYPE" != "arm64" ]; then
22     echo $SYNTAX
23     echo "where <type> is arm-intel-64, intel-32-64 or arm64"
24     exit 1
25 fi
26
27 # This is our work area for making up the .dmgs
28 mkdir -p build/platform/osx
29 cd build/platform/osx
30
31 cat <<EOF > entitlements.plist
32 <?xml version="1.0" encoding="UTF-8"?>
33 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
34 <plist version="1.0">
35 <dict>
36   <key>com.apple.security.cs.disable-library-validation</key>
37   <true/>
38 </dict>
39 </plist>
40 EOF
41
42 function copy {
43     case $TYPE in
44         arm-intel-64)
45             for f in $1/arm64/$2; do
46                 if [ -h $f ]; then
47                     ln -s $(readlink $f) "$3/`basename $f`"
48                 else
49                     g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
50                     mkdir -p "$3"
51                     lipo -create $f $g -output "$3/`basename $f`"
52                 fi
53             done
54             ;;
55         intel-32-64)
56             for f in $1/i386/$2; do
57                 if [ -h $f ]; then
58                     ln -s $(readlink $f) "$3/`basename $f`"
59                 else
60                     g=`echo $f | sed -e "s/\/i386\//\/x86_64\//g"`
61                     mkdir -p "$3"
62                     lipo -create $f $g -output "$3/`basename $f`"
63                 fi
64             done
65             ;;
66         arm64)
67             if [ -h $1/$2 ]; then
68                 ln -s $(readlink $1/$2) "$3/`basename $f`"
69             else
70                 cp $1/$2 "$3"
71             fi
72             ;;
73     esac
74 }
75
76 function copy_lib_root {
77     case $TYPE in
78         arm-intel-64)
79             for f in $ROOT/arm64/lib/$1*.dylib; do
80                 if [ -h $f ]; then
81                     ln -s $(readlink $f) "$2/`basename $f`"
82                 else
83                     g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
84                     mkdir -p "$2"
85                     lipo -create $f $g -output "$2/`basename $f`"
86                 fi
87             done
88             ;;
89         intel-32-64)
90             for f in $ROOT/intel-32-64/lib/$1*.dylib; do
91                 if [ -h $f ]; then
92                     ln -s $(readlink $f) "$2/`basename $f`"
93                 else
94                     g=`echo $f | sed -e "s/\/i386\//\/x86_64\//g"`
95                     mkdir -p "$2"
96                     lipo -create $f $g -output "$2/`basename $f`"
97                 fi
98             done
99             ;;
100         arm64)
101             for f in $ROOT/lib/$1*.dylib; do
102                 if [ -h $f ]; then
103                     ln -s $(readlink $f) "$2/`basename $f`"
104                 else
105                     mkdir -p "$2"
106                     cp $f "$2"
107                 fi
108             done
109             ;;
110     esac
111     to_relink="$to_relink|$1"
112 }
113
114 function copy_lib_env {
115     case $TYPE in
116         arm-intel-64)
117             for f in $ENV/arm64/lib/$1*.dylib; do
118                 if [ -h $f ]; then
119                     ln -s $(readlink $f) "$2/`basename $f`"
120                 else
121                     g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
122                     mkdir -p "$2"
123                     lipo -create $f $g -output "$2/`basename $f`"
124                 fi
125             done
126             ;;
127         intel-32-64)
128             for f in $ENV/i386/lib/$1*.dylib; do
129                 if [ -h $f ]; then
130                     ln -s $(readlink $f) "$2/`basename $f`"
131                 else
132                     g=`echo $f | sed -e "s/\/i386\//\/x86_64\//g"`
133                     mkdir -p "$2"
134                     lipo -create $f $g -output "$2/`basename $f`"
135                 fi
136             done
137             ;;
138         arm64)
139             for f in $ENV/arm64/lib/$1*.dylib; do
140                 if [ -h $f ]; then
141                     ln -s $(readlink $f) "$2/`basename $f`"
142                 else
143                     mkdir -p "$2"
144                     cp $f "$2"
145                 fi
146             done
147             ;;
148     esac
149     to_relink="$to_relink|$1"
150 }
151
152 # @param #1 directory to copy to
153 function copy_libs {
154     local dest="$1"
155     copy_lib_root libcxml "$dest"
156     copy_lib_root libdcp-1.0 "$dest"
157     copy_lib_root libasdcp-carl "$dest"
158     copy_lib_root libkumu-carl "$dest"
159     copy_lib_root libsub "$dest"
160     copy_lib_root libopenjp2 "$dest"
161     copy_lib_root libavdevice "$dest"
162     copy_lib_root libavformat "$dest"
163     copy_lib_root libavfilter "$dest"
164     copy_lib_root libavutil "$dest"
165     copy_lib_root libavcodec "$dest"
166     copy_lib_root libswscale "$dest"
167     copy_lib_root libpostproc "$dest"
168     copy_lib_root libswresample "$dest"
169     copy_lib_root liblwext4 "$dest"
170     copy_lib_root libblockdev "$dest"
171     copy_lib_root libleqm_nrt "$dest"
172     copy $ROOT src/dcpomatic/build/src/lib/libdcpomatic2.dylib "$dest"
173     copy $ROOT src/dcpomatic/build/src/wx/libdcpomatic2-wx.dylib "$dest"
174     copy_lib_env libboost_system "$dest"
175     copy_lib_env libboost_filesystem "$dest"
176     copy_lib_env libboost_thread "$dest"
177     copy_lib_env libboost_date_time "$dest"
178     copy_lib_env libboost_locale "$dest"
179     copy_lib_env libboost_regex "$dest"
180     copy_lib_env libxml++ "$dest"
181     copy_lib_env libxslt "$dest"
182     copy_lib_env libxml2 "$dest"
183     copy_lib_env libglibmm-2.4 "$dest"
184     copy_lib_env libgobject "$dest"
185     copy_lib_env libgthread "$dest"
186     copy_lib_env libgmodule "$dest"
187     copy_lib_env libsigc "$dest"
188     copy_lib_env libglib-2 "$dest"
189     copy_lib_env libintl "$dest"
190     copy_lib_env libsndfile "$dest"
191     copy_lib_env libssh "$dest"
192     copy_lib_env libwx "$dest"
193     copy_lib_env libfontconfig "$dest"
194     copy_lib_env libfreetype "$dest"
195     copy_lib_env libexpat "$dest"
196     copy_lib_env libltdl "$dest"
197     copy_lib_env libxmlsec1 "$dest"
198     copy_lib_env libcurl "$dest"
199     copy_lib_env libffi "$dest"
200     copy_lib_env libpango "$dest"
201     copy_lib_env libcairo "$dest"
202     copy_lib_env libpixman "$dest"
203     copy_lib_env libharfbuzz "$dest"
204     copy_lib_env libsamplerate "$dest"
205     copy_lib_env libicui18n "$dest"
206     copy_lib_env libicudata "$dest"
207     copy_lib_env libicuio "$dest"
208     copy_lib_env libicule "$dest"
209     copy_lib_env libiculx "$dest"
210     copy_lib_env libicutest "$dest"
211     copy_lib_env libicutu "$dest"
212     copy_lib_env libicuuc "$dest"
213     copy_lib_env libFLAC "$dest"
214     copy_lib_env libvorbis "$dest"
215     copy_lib_env libogg "$dest"
216     copy_lib_env libxerces-c "$dest"
217 }
218
219 # @param #1 directory to copy to
220 function copy_resources {
221     local dest="$1"
222     case $TYPE in
223         arm-intel-64)
224             local prefix=$ROOT/x86_64
225             ;;
226         intel-32-64)
227             local prefix=$ROOT/x86_64
228             ;;
229         arm64)
230             local prefix=$ROOT
231             ;;
232     esac
233     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic_small.png "$dest"
234     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2.icns "$dest"
235     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_kdm.icns "$dest"
236     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_server.icns "$dest"
237     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_player.icns "$dest"
238     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_batch.icns "$dest"
239     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_playlist.icns "$dest"
240     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_disk.icns "$dest"
241     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_combiner.icns "$dest"
242     cp $prefix/src/dcpomatic/graphics/osx/preferences/defaults.png "$dest"
243     cp $prefix/src/dcpomatic/graphics/osx/preferences/defaults@2x.png "$dest"
244     cp $prefix/src/dcpomatic/graphics/osx/preferences/kdm_email.png "$dest"
245     cp $prefix/src/dcpomatic/graphics/osx/preferences/kdm_email@2x.png "$dest"
246     cp $prefix/src/dcpomatic/graphics/osx/preferences/email.png "$dest"
247     cp $prefix/src/dcpomatic/graphics/osx/preferences/email@2x.png "$dest"
248     cp $prefix/src/dcpomatic/graphics/osx/preferences/servers.png "$dest"
249     cp $prefix/src/dcpomatic/graphics/osx/preferences/servers@2x.png "$dest"
250     cp $prefix/src/dcpomatic/graphics/osx/preferences/tms.png "$dest"
251     cp $prefix/src/dcpomatic/graphics/osx/preferences/tms@2x.png "$dest"
252     cp $prefix/src/dcpomatic/graphics/osx/preferences/keys.png "$dest"
253     cp $prefix/src/dcpomatic/graphics/osx/preferences/keys@2x.png "$dest"
254     cp $prefix/src/dcpomatic/graphics/osx/preferences/cover_sheet.png "$dest"
255     cp $prefix/src/dcpomatic/graphics/osx/preferences/cover_sheet@2x.png "$dest"
256     cp $prefix/src/dcpomatic/graphics/osx/preferences/notifications.png "$dest"
257     cp $prefix/src/dcpomatic/graphics/osx/preferences/notifications@2x.png "$dest"
258     cp $prefix/src/dcpomatic/graphics/osx/preferences/sound.png "$dest"
259     cp $prefix/src/dcpomatic/graphics/osx/preferences/sound@2x.png "$dest"
260     cp $prefix/src/dcpomatic/graphics/osx/preferences/identifiers.png "$dest"
261     cp $prefix/src/dcpomatic/graphics/osx/preferences/identifiers@2x.png "$dest"
262     cp $prefix/src/dcpomatic/graphics/osx/preferences/general.png "$dest"
263     cp $prefix/src/dcpomatic/graphics/osx/preferences/general@2x.png "$dest"
264     cp $prefix/src/dcpomatic/graphics/osx/preferences/advanced.png "$dest"
265     cp $prefix/src/dcpomatic/graphics/osx/preferences/advanced@2x.png "$dest"
266     cp $prefix/src/dcpomatic/graphics/osx/preferences/locations.png "$dest"
267     cp $prefix/src/dcpomatic/graphics/osx/preferences/locations@2x.png "$dest"
268     cp $prefix/src/dcpomatic/fonts/LiberationSans-Regular.ttf "$dest"
269     cp $prefix/src/dcpomatic/fonts/LiberationSans-Italic.ttf "$dest"
270     cp $prefix/src/dcpomatic/fonts/LiberationSans-Bold.ttf "$dest"
271     cp $prefix/src/dcpomatic/fonts/fonts.conf.osx "$dest"/fonts.conf
272     cp $prefix/src/dcpomatic/graphics/splash.png "$dest"
273     cp $prefix/src/dcpomatic/graphics/zoom.png "$dest"
274     cp $prefix/src/dcpomatic/graphics/zoom_all.png "$dest"
275     cp $prefix/src/dcpomatic/graphics/select.png "$dest"
276     cp $prefix/src/dcpomatic/graphics/snap.png "$dest"
277     cp $prefix/src/dcpomatic/graphics/sequence.png "$dest"
278     cp $prefix/src/dcpomatic/graphics/me.jpg "$dest"
279     cp $prefix/src/dcpomatic/graphics/link.png "$dest"
280     cp $prefix/src/dcpomatic/graphics/tick.png "$dest"
281     cp $prefix/src/dcpomatic/graphics/no_tick.png "$dest"
282     cp -r $prefix/share/libdcp/xsd "$dest"
283     cp -r $prefix/share/libdcp/tags "$dest"
284
285     # i18n: DCP-o-matic .mo files
286     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 tr_TR; do
287         mkdir -p "$dest/$lang/LC_MESSAGES"
288         cp $prefix/src/dcpomatic/build/src/lib/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
289         cp $prefix/src/dcpomatic/build/src/wx/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
290         cp $prefix/src/dcpomatic/build/src/tools/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
291     done
292
293     # i18n: wxWidgets .mo files
294     for lang in de es fr it sv nl ru pl da cs; do
295         mkdir "$dest/$lang"
296         cp $ENV/x86_64/share/locale/$lang/LC_MESSAGES/wxstd.mo "$dest/$lang"
297     done
298 }
299
300 # param $1 list of things that link to other things
301 function relink_relative {
302     to_relink=`echo $to_relink | sed -e "s/\+//g"`
303     local linkers=("$@")
304
305     for obj in "${linkers[@]}"; do
306         deps=`otool -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu)"`
307         changes=""
308         for dep in $deps; do
309             base=`basename $dep`
310             if [ "$TYPE" == "universal" ]; then
311                 # $dep will be a path within x86_64/; make i386 and arm64 paths too
312                 dep_i386=`echo $dep | sed -e "s/\/x86_64\//\/i386\//g"`
313                 changes="$changes -change $dep @executable_path/../Frameworks/$base -change $dep_i386 @executable_path/../Frameworks/$base"
314                 dep_arm64=`echo $dep | sed -e "s/\/x86_64\//\/arm64\//g"`
315                 changes="$changes -change $dep @executable_path/../Frameworks/$base -change $dep_arm64 @executable_path/../Frameworks/$base"
316             else
317                 changes="$changes -change $dep @executable_path/../Frameworks/$base"
318             fi
319         done
320         if test "x$changes" != "x"; then
321             install_name_tool $changes -id `basename "$obj"` "$obj"
322         fi
323     done
324 }
325
326 # param $1 directory things should be relinked into
327 #       $2 list of things that link to other things
328 function relink_absolute {
329     to_relink=`echo $to_relink | sed -e "s/\+//g"`
330     target=$1
331     shift
332     local linkers=("$@")
333
334     for obj in "${linkers[@]}"; do
335         deps=`otool -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu)"`
336         for dep in $deps; do
337             base=`basename $dep`
338             install_name_tool -change "$dep" "$target"/$base -id `basename "$obj"` "$obj"
339         done
340     done
341 }
342
343 function sign {
344     codesign --deep --force --verify --verbose --options runtime --entitlements entitlements.plist --sign "Developer ID Application: Carl Hetherington (R82DXSR997)" "$1"
345     if [ "$?" != "0" ]; then
346         echo "Failed to sign $1"
347         exit 1
348     fi
349 }
350
351
352 # @param #1 .app directory
353 # @param #2 .pkg or ""
354 # @param #3 full name e.g. DCP-o-matic Batch Converter
355 function make_dmg {
356     local appdir="$1"
357     local pkg="$2"
358     local full_name="$3"
359     tmp_dmg=dcpomatic_tmp.dmg
360     dmg="$full_name $version.dmg"
361     vol_name=DCP-o-matic-$version
362
363     sign "$appdir"
364
365     if [ "$pkg" != "" ]; then
366         productsign --sign "Developer ID Installer: Carl Hetherington (R82DXSR997)" "$pkg" "signed_temp.pkg"
367         if [ "$?" != "0" ]; then
368             echo "Failed to sign .pkg"
369             exit 1
370         fi
371         mv signed_temp.pkg "$pkg"
372     fi
373
374     mkdir -p $vol_name
375     cp -a "$appdir" $vol_name
376     if [ "$pkg" != "" ]; then
377         cp -a "$pkg" $vol_name
378     fi
379     ln -s /Applications "$vol_name/Applications"
380     cat<<EOF > "$vol_name/READ ME.txt"
381 Welcome to DCP-o-matic!  The first time you run the program there may be
382 a long (several-minute) delay while OS X checks the code for viruses and
383 other malware.  Please be patient!
384 EOF
385     cat<<EOF > "$vol_name/READ ME.de_DE.txt"
386 Beim erstmaligen Start der DCP-o-matic Anwendungen kann ein längerer
387 Verifikationsvorgang auftreten.  Dies ist von der OS X Sicherheitsumgebung
388 'Gatekeeper' verursacht.  Dieser je nach Rechner teils minutenlange
389 Verifikationsvorgang ist gegenwärtig normal und nicht zu umgehen,
390 es ist kein Programmfehler.  Warten sie die Verifikation für jede der
391 DCP-o-matic Anwendungen ab, bei weiteren Programmstarts wird sie nicht
392 mehr auftreten.
393 EOF
394
395     if [ "$pkg" != "" ]; then
396         cat<<EOF > "$vol_name/READ ME.txt"
397
398 To run this software successfully you must install $pkg before running
399 the .app
400 EOF
401     fi
402
403     if [ "$pkg" != "" ]; then
404         cat<<EOF > "$vol_name/READ ME.de_DE.txt"
405
406 To run this software successfully you must install $pkg before running
407 the .app
408 EOF
409
410     fi
411     rm -f $tmp_dmg "$dmg"
412     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
413     attach=$(hdiutil attach -readwrite -noverify -noautoopen $tmp_dmg)
414     device=`echo $attach | egrep '^/dev/' | sed 1q | awk '{print $5}'`
415     sleep 5
416
417     echo '
418   tell application "Finder"
419     tell disk "'$vol_name'"
420            open
421            set current view of container window to icon view
422            set toolbar visible of container window to false
423            set statusbar visible of container window to false
424            set the bounds of container window to {400, 200, 1160, 600}
425            set the bounds of container window to {400, 200, 1160, 600}
426            set the bounds of container window to {400, 200, 1160, 600}
427            set theViewOptions to the icon view options of container window
428            set arrangement of theViewOptions to not arranged
429            set icon size of theViewOptions to 64
430            set position of item "'$appdir'" of container window to {90, 80}
431            set position of item "Applications" of container window to {265, 80}
432            set position of item "READ ME.txt" of container window to {430, 80}
433            set position of item "READ ME.de_DE.txt" of container window to {595, 80}
434            set position of item "DCP-o-matic Disk Writer.pkg" of container window to {90, 255}
435            close
436            open
437            update without registering applications
438            delay 5
439      end tell
440    end tell
441 ' | osascript
442
443     chmod -Rf go-w /Volumes/"$vol_name"/"$appdir"
444     sync
445
446     hdiutil eject $device
447     hdiutil convert -format UDZO $tmp_dmg -imagekey zlib-level=9 -o "$dmg"
448     sips -i "$appdir/Contents/Resources/dcpomatic2.icns"
449     DeRez -only icns "$appdir/Contents/Resources/dcpomatic2.icns" > "$appdir/Contents/Resources/DCP-o-matic.rsrc"
450     Rez -append "$appdir/Contents/Resources/DCP-o-matic.rsrc" -o "$dmg"
451     SetFile -a C "$dmg"
452     xattr -c "$dmg"
453
454     set -e
455     codesign --verify --verbose --options runtime --entitlements entitlements.plist --sign "Developer ID Application: Carl Hetherington (R82DXSR997)" "$dmg"
456     set +e
457
458     rm $tmp_dmg
459     rm -rf $vol_name
460 }
461
462 # @param #1 appdir
463 function setup {
464     appdir="$1"
465     approot="$appdir/Contents"
466     rm -rf "$appdir"
467     mkdir -p "$approot/MacOS"
468     mkdir -p "$approot/Frameworks"
469     mkdir -p "$approot/Resources"
470
471     to_relink="dcpomatic"
472     copy_libs "$approot/Frameworks"
473     copy_resources "$approot/Resources"
474 }
475
476 case $TYPE in
477     arm-intel-64)
478         # copy() writes the universal binary to arm64
479         prefix=$ROOT/arm64
480         ;;
481     intel-32-64)
482         # copy() writes the universal binary to i386
483         prefix=$ROOT/i386
484         ;;
485     arm64)
486         prefix=$ROOT
487         ;;
488 esac
489
490 # DCP-o-matic main
491 setup "DCP-o-matic 2.app"
492 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2 "$approot/MacOS"
493 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_cli "$approot/MacOS"
494 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_create "$approot/MacOS"
495 copy $ROOT bin/ffprobe "$approot/MacOS"
496 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
497 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2.Info.plist "$approot/Info.plist"
498 rl=("$approot/MacOS/dcpomatic2" "$approot/MacOS/dcpomatic2_cli" "$approot/MacOS/dcpomatic2_create" "$approot/MacOS/ffprobe" "$approot/Frameworks/"*.dylib)
499 relink_relative "${rl[@]}"
500 make_dmg "$appdir" "" "DCP-o-matic"
501
502 # DCP-o-matic KDM Creator
503 setup "DCP-o-matic 2 KDM Creator.app"
504 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_kdm "$approot/MacOS"
505 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_kdm_cli "$approot/MacOS"
506 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
507 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_kdm.Info.plist "$approot/Info.plist"
508 rl=("$approot/MacOS/dcpomatic2_kdm" "$approot/MacOS/dcpomatic2_kdm_cli" "$approot/Frameworks/"*.dylib)
509 relink_relative "${rl[@]}"
510 make_dmg "$appdir" "" "DCP-o-matic KDM Creator"
511
512 # DCP-o-matic Encode Server
513 setup "DCP-o-matic 2 Encode Server.app"
514 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_server "$approot/MacOS"
515 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_server_cli "$approot/MacOS"
516 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
517 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_server.Info.plist "$approot/Info.plist"
518 rl=("$approot/MacOS/dcpomatic2_server" "$approot/MacOS/dcpomatic2_server_cli" "$approot/Frameworks/"*.dylib)
519 relink_relative "${rl[@]}"
520 make_dmg "$appdir" "" "DCP-o-matic Encode Server"
521
522 # DCP-o-matic Batch Converter
523 setup "DCP-o-matic 2 Batch converter.app"
524 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_batch "$approot/MacOS"
525 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
526 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_batch.Info.plist "$approot/Info.plist"
527 rl=("$approot/MacOS/dcpomatic2_batch" "$approot/Frameworks/"*.dylib)
528 relink_relative "${rl[@]}"
529 make_dmg "$appdir" "" "DCP-o-matic Batch Converter"
530
531 # DCP-o-matic Player
532 setup "DCP-o-matic 2 Player.app"
533 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_player "$approot/MacOS"
534 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
535 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_player.Info.plist "$approot/Info.plist"
536 rl=("$approot/MacOS/dcpomatic2_player" "$approot/Frameworks/"*.dylib)
537 relink_relative "${rl[@]}"
538 make_dmg "$appdir" "" "DCP-o-matic Player"
539
540 # DCP-o-matic Playlist Editor
541 setup "DCP-o-matic 2 Playlist Editor.app"
542 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_playlist "$approot/MacOS"
543 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
544 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_playlist.Info.plist "$approot/Info.plist"
545 rl=("$approot/MacOS/dcpomatic2_playlist" "$approot/Frameworks/"*.dylib)
546 relink_relative "${rl[@]}"
547 make_dmg "$appdir" "" "DCP-o-matic Playlist Editor"
548
549 # DCP-o-matic Combiner
550 setup "DCP-o-matic 2 Combiner.app"
551 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_combiner "$approot/MacOS"
552 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
553 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_combiner.Info.plist "$approot/Info.plist"
554 rl=("$approot/MacOS/dcpomatic2_combiner" "$approot/Frameworks/"*.dylib)
555 relink_relative "${rl[@]}"
556 make_dmg "$appdir" "" "DCP-o-matic Combiner"
557
558 # DCP-o-matic Disk Writer .app
559 setup "DCP-o-matic 2 Disk Writer.app"
560 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_disk "$approot/MacOS"
561 copy $ROOT src/openssl/apps/openssl "$approot/MacOS"
562 cp $prefix/src/dcpomatic/platform/osx/uninstall_disk.applescript "$approot/Resources"
563 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_disk.Info.plist "$approot/Info.plist"
564 rl=("$approot/MacOS/dcpomatic2_disk" "$approot/Frameworks/"*.dylib)
565 relink_relative "${rl[@]}"
566
567 # DCP-o-matic Disk Writer daemon .pkg
568
569 pkgbase=tmp-disk-writer
570 rm -rf $pkgbase
571 mkdir $pkgbase
572 pkgbin=$pkgbase/bin
573 pkgroot=$pkgbase/root
574
575 mkdir -p $pkgroot/Library/LaunchDaemons
576 cat > $pkgroot/Library/LaunchDaemons/com.dcpomatic.disk.writer.plist <<EOF
577 <?xml version="1.0" encoding="UTF-8"?>
578 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
579 <plist version="1.0">
580 <dict>
581     <key>Label</key>
582     <string>com.dcpomatic.disk.writer</string>
583     <key>ProgramArguments</key>
584     <array>
585         <string>/Library/Application Support/com.dcpomatic/dcpomatic2_disk_writer</string>
586     </array>
587     <key>EnvironmentVariables</key>
588     <dict>
589         <key>DYLD_LIBRARY_PATH</key>
590         <string><![CDATA[/Library/Application Support/com.dcpomatic]]></string>
591     </dict>
592     <key>StandardOutPath</key>
593     <string>/var/log/dcpomatic_disk_writer_out.log</string>
594     <key>StandardErrorPath</key>
595     <string>/var/log/dcpomatic_disk_writer_err.log</string>
596     <key>LaunchEvents</key>
597     <dict>
598         <key>com.apple.notifyd.matching</key>
599         <dict>
600             <key>com.dcpomatic.disk.writer.start</key>
601             <dict>
602                 <key>Notification</key>
603                 <string>com.dcpomatic.disk.writer.start</string>
604             </dict>
605         </dict>
606     </dict>
607 </dict>
608 </plist>
609 EOF
610
611 # Get the binaries together in $pkgbin then move them to the
612 # place with spaces in the filename to avoid some of the pain of escaping
613
614 mkdir $pkgbin
615 copy $ROOT src/dcpomatic/build/src/tools/dcpomatic2_disk_writer "$pkgbin"
616 copy_libs "$pkgbin"
617
618 rl=("$pkgbin/dcpomatic2_disk_writer" "$pkgbin/"*.dylib)
619 relink_absolute "/Library/Application Support/com.dcpomatic" "${rl[@]}"
620
621 mkdir $pkgbase/scripts
622 cat > $pkgbase/scripts/postinstall <<EOF
623 #!/bin/sh
624 /bin/launchctl unload "/Library/LaunchDaemons/com.dcpomatic.disk.writer.plist"
625 /bin/launchctl load "/Library/LaunchDaemons/com.dcpomatic.disk.writer.plist"
626 exit 0
627 EOF
628 chmod gou+x $pkgbase/scripts/postinstall
629
630 find "$pkgbin" -iname "*.dylib" -print0 | while IFS= read -r -d '' f; do
631     sign "$f"
632 done
633 sign "$pkgbin/dcpomatic2_disk_writer"
634
635 mkdir -p "$pkgroot/Library/Application Support/com.dcpomatic"
636 mv $pkgbin/* "$pkgroot/Library/Application Support/com.dcpomatic/"
637 pkgbuild --root $pkgroot --identifier com.dcpomatic.disk.writer --scripts $pkgbase/scripts "DCP-o-matic Disk Writer.pkg"
638
639 make_dmg "$appdir" "DCP-o-matic Disk Writer.pkg" "DCP-o-matic Disk Writer"
640