Build with an ffmpeg that includes libdav1d.
[dcpomatic.git] / platform / osx / make_dmg.sh
index 3427bf95a93daa314b4bd75265d2bc986d3b1a95..f997af8175713f2ce2e2cf08b8ae9cb95783acf3 100644 (file)
@@ -1,13 +1,20 @@
 #!/bin/bash
 #
-SYNTAX="make_dmg.sh <environment> <builddir> <apple-id> <apple-password>"
+SYNTAX="make_dmg.sh <environment> <builddir> <apple-id> <apple-password> <arch1> [<arch2>]"
 #
-# e.g. make_dmg.sh /Users/carl/osx-environment /Users/carl/cdist foo@bar.net opensesame
+# e.g. make_dmg.sh /Users/carl/osx-environment /Users/carl/cdist foo@bar.net opensesame x86_64/10.10 arm64/11.0
 
 # Don't set -e here as egrep (used a few times) returns 1 if no matches
 # were found.
 
-version=`git describe --tags --abbrev=0 | sed -e "s/v//"`
+# Use a tag if what we've built is exactly on one
+version=$(git describe --tags --abbrev=0 --match=v2.*.* --exact-match 2> /dev/null)
+if [ "$?" == "0" ]; then
+       version=$(echo $version | sed -e "s/^v//")
+else
+       # Otherwise use <branch>-<commit>
+       version="$(basename $(git name-rev --name-only HEAD))-$(git rev-parse --short HEAD)"
+fi
 
 # DMG size in megabytes
 DMG_SIZE=256
@@ -15,6 +22,11 @@ ENV=$1
 ROOT=$2
 APPLE_ID=$3
 APPLE_PASSWORD=$4
+ARCH1=$5
+ARCH2=$6
+
+APPLICATION_IDENTITY="Developer ID Application: Carl Hetherington (R82DXSR997)"
+INSTALLER_IDENTITY="Developer ID Installer: Carl Hetherington (R82DXSR997)"
 
 # This is our work area for making up the .dmgs
 mkdir -p build/platform/osx
@@ -34,40 +46,70 @@ cat <<EOF > entitlements.plist
 EOF
 
 function copy {
-       for f in $1/arm64/$2; do
-               if [ -h $f ]; then
-                       ln -s $(readlink $f) "$3/`basename $f`"
-               else
-                       g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
-                       mkdir -p "$3"
-                       lipo -create $f $g -output "$3/`basename $f`"
-               fi
-       done
+       if [ "$ARCH2" == "" ]; then
+               for f in $1/$2; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$3/`basename $f`"
+                       else
+                               cp $f "$3/`basename $f`"
+                       fi
+               done
+       else
+               for f in $1/$ARCH2/$2; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$3/`basename $f`"
+                       else
+                               g=`echo $f | sed -e "s@/$ARCH2/@/$ARCH1/@g"`
+                               mkdir -p "$3"
+                               lipo -create $f $g -output "$3/$(basename $f)"
+                       fi
+               done
+       fi
 }
 
 function copy_lib_root {
-       for f in $ROOT/arm64/lib/$1*.dylib; do
-               if [ -h $f ]; then
-                       ln -s $(readlink $f) "$2/`basename $f`"
-               else
-                       g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
-                       mkdir -p "$2"
-                       lipo -create $f $g -output "$2/`basename $f`"
-               fi
-       done
+       if [ "$ARCH2" == "" ]; then
+               for f in $ROOT/lib/$1*.dylib; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$2/`basename $f`"
+                       else
+                               cp $f "$2/`basename $f`"
+                       fi
+               done
+       else
+               for f in $ROOT/$ARCH2/lib/$1*.dylib; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$2/`basename $f`"
+                       else
+                               g=`echo $f | sed -e "s@/$ARCH2/@/$ARCH1/@g"`
+                               mkdir -p "$2"
+                               lipo -create $f $g -output "$2/$(basename $f)"
+                       fi
+               done
+       fi
     to_relink="$to_relink|$1"
 }
 
 function copy_lib_env {
-       for f in $ENV/arm64/lib/$1*.dylib; do
-               if [ -h $f ]; then
-                       ln -s $(readlink $f) "$2/`basename $f`"
-               else
-                       g=`echo $f | sed -e "s/\/arm64\//\/x86_64\//g"`
-                       mkdir -p "$2"
-                       lipo -create $f $g -output "$2/`basename $f`"
-               fi
-       done
+       if [ "$ARCH2" == "" ]; then
+               for f in $ENV/$ARCH1/lib/$1*.dylib; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$2/`basename $f`"
+                       else
+                               cp $f "$2/`basename $f`"
+                       fi
+               done
+       else
+               for f in $ENV/$ARCH2/lib/$1*.dylib; do
+                       if [ -h $f ]; then
+                               ln -s $(readlink $f) "$2/`basename $f`"
+                       else
+                               g=`echo $f | sed -e "s@/$ARCH2/@/$ARCH1/@g"`
+                               mkdir -p "$2"
+                               lipo -create $f $g -output "$2/$(basename $f)"
+                       fi
+               done
+       fi
     to_relink="$to_relink|$1"
 }
 
@@ -139,13 +181,19 @@ function copy_libs {
     copy_lib_env libfribidi "$dest"
     copy_lib_env libgio "$dest"
     copy_lib_env libz "$dest"
+       copy_lib_env libdav1d "$dest"
 }
 
 # @param #1 directory to copy to
 function copy_resources {
     local dest="$1"
-       local prefix=$ROOT/x86_64
-    cp $prefix/src/dcpomatic/graphics/osx/dcpomatic_small.png "$dest"
+       if [ "$ARCH2" == "" ]; then
+               local prefix=$ROOT
+       else
+               local prefix=$ROOT/$ARCH1
+       fi
+    cp $prefix/src/dcpomatic/graphics/osx/dcpomatic_small_white.png "$dest"
+    cp $prefix/src/dcpomatic/graphics/osx/dcpomatic_small_black.png "$dest"
     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2.icns "$dest"
     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_kdm.icns "$dest"
     cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_server.icns "$dest"
@@ -208,7 +256,7 @@ function copy_resources {
     # i18n: wxWidgets .mo files
     for lang in de es fr it sv nl ru pl da cs; do
        mkdir "$dest/$lang"
-       cp $ENV/x86_64/share/locale/$lang/LC_MESSAGES/wxstd.mo "$dest/$lang"
+       cp $ENV/$ARCH1/share/locale/$lang/LC_MESSAGES/wxstd.mo "$dest/$lang"
     done
 }
 
@@ -217,9 +265,12 @@ function relink_relative {
     to_relink=`echo $to_relink | sed -e "s/\+//g"`
     local linkers=("$@")
 
-       for obj in "${linkers[@]}"; do
-               for arch in x86_64 arm64; do
-                       deps=`otool -arch $arch -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu|libssh)"`
+       arch1_name=$(echo $ARCH1 | sed -e s@/.*@@)
+       arch2_name=$(echo $ARCH2 | sed -e s@/.*@@)
+
+       for arch in $arch1_name $arch2_name; do
+               for obj in "${linkers[@]}"; do
+                       deps=`otool -arch $arch -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|@rpath|boost|libicu|libssh)"`
                        changes=""
                        for dep in $deps; do
                                base=`basename $dep`
@@ -240,41 +291,54 @@ function relink_absolute {
     shift
     local linkers=("$@")
 
-    for obj in "${linkers[@]}"; do
-               for arch in x86_64 arm64; do
+       arch1_name=$(echo $ARCH1 | sed -e s@/.*@@)
+       arch2_name=$(echo $ARCH2 | sed -e s@/.*@@)
+
+       for arch in $arch1_name $arch2_name; do
+               for obj in "${linkers[@]}"; do
                        deps=`otool -arch $arch -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu|libssh)"`
                        for dep in $deps; do
                                base=`basename $dep`
                                install_name_tool -change "$dep" "$target"/$base -id `basename "$obj"` "$obj"
                        done
                done
-    done
+       done
 }
 
 function sign {
-    codesign --deep --force --verify --verbose --options runtime --entitlements entitlements.plist --sign "Developer ID Application: Carl Hetherington (R82DXSR997)" "$1"
-    if [ "$?" != "0" ]; then
-       echo "Failed to sign $1"
-       exit 1
-    fi
+       codesign --verify --verbose=4 --options runtime --entitlements entitlements.plist --sign "$APPLICATION_IDENTITY" "$1"
+       if [ "$?" != "0" ]; then
+               echo "Failed to sign $1"
+               exit 1
+       fi
 }
 
-
 # @param #1 .app directory
 # @param #2 .pkg or ""
 # @param #3 full name e.g. DCP-o-matic Batch Converter
+# @param #4 list of executables
 function make_dmg {
     local appdir="$1"
     local pkg="$2"
     local full_name="$3"
-    tmp_dmg=dcpomatic_tmp.dmg
-    dmg="$full_name $version.dmg"
+    local exes="$4"
+       tmp_dmg=dcpomatic_tmp.dmg
+       if [ "$ARCH2" == "" ]; then
+               dmg="$full_name $version macOS10.8+.dmg"
+       else
+               dmg="$full_name $version macOS10.10+.dmg"
+       fi
     vol_name=DCP-o-matic-$version
 
-    sign "$appdir"
+       find "$appdir/Contents/Frameworks" -iname "*.dylib" -type f -print0 | while IFS= read -r -d '' f; do
+               sign "$f"
+       done
+       for f in $exes; do
+               sign "$appdir/Contents/MacOS/$f"
+       done
 
     if [ "$pkg" != "" ]; then
-       productsign --sign "Developer ID Installer: Carl Hetherington (R82DXSR997)" "$pkg" "signed_temp.pkg"
+       productsign --sign "$INSTALLER_IDENTITY" "$pkg" "signed_temp.pkg"
        if [ "$?" != "0" ]; then
            echo "Failed to sign .pkg"
            exit 1
@@ -363,7 +427,7 @@ EOF
     xattr -c "$dmg"
 
     set -e
-    codesign --verify --verbose --options runtime --entitlements entitlements.plist --sign "Developer ID Application: Carl Hetherington (R82DXSR997)" "$dmg"
+    codesign --timestamp --verify --verbose --options runtime --entitlements entitlements.plist --sign "$APPLICATION_IDENTITY" "$dmg"
     set +e
 
     rm $tmp_dmg
@@ -391,7 +455,11 @@ function copy_verify {
        relink_relative "${rl[@]}"
 }
 
-prefix=$ROOT/arm64
+if [ "$ARCH2" == "" ]; then
+       prefix=$ROOT
+else
+       prefix=$ROOT/$ARCH2
+fi
 
 # DCP-o-matic main
 setup "DCP-o-matic 2.app"
@@ -404,7 +472,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2" "$approot/MacOS/dcpomatic2_cli" "$approot/MacOS/dcpomatic2_create" "$approot/MacOS/ffprobe" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic"
+make_dmg "$appdir" "" "DCP-o-matic" "dcpomatic2_verify openssl ffprobe dcpomatic2_cli dcpomatic2_create dcpomatic2"
 
 # DCP-o-matic KDM Creator
 setup "DCP-o-matic 2 KDM Creator.app"
@@ -415,7 +483,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_kdm.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_kdm" "$approot/MacOS/dcpomatic2_kdm_cli" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic KDM Creator"
+make_dmg "$appdir" "" "DCP-o-matic KDM Creator" "dcpomatic2_verify openssl dcpomatic2_kdm_cli dcpomatic2_kdm"
 
 # DCP-o-matic Encode Server
 setup "DCP-o-matic 2 Encode Server.app"
@@ -426,7 +494,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_server.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_server" "$approot/MacOS/dcpomatic2_server_cli" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic Encode Server"
+make_dmg "$appdir" "" "DCP-o-matic Encode Server" "dcpomatic2_verify openssl dcpomatic2_server_cli dcpomatic2_server"
 
 # DCP-o-matic Batch Converter
 setup "DCP-o-matic 2 Batch converter.app"
@@ -436,7 +504,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_batch.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_batch" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic Batch Converter"
+make_dmg "$appdir" "" "DCP-o-matic Batch Converter" "dcpomatic2_verify openssl dcpomatic2_batch"
 
 # DCP-o-matic Player
 setup "DCP-o-matic 2 Player.app"
@@ -446,7 +514,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_player.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_player" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic Player"
+make_dmg "$appdir" "" "DCP-o-matic Player" "dcpomatic2_verify openssl dcpomatic2_player"
 
 # DCP-o-matic Playlist Editor
 setup "DCP-o-matic 2 Playlist Editor.app"
@@ -456,7 +524,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_playlist.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_playlist" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic Playlist Editor"
+make_dmg "$appdir" "" "DCP-o-matic Playlist Editor" "dcpomatic2_verify openssl dcpomatic2_playlist"
 
 # DCP-o-matic Combiner
 setup "DCP-o-matic 2 Combiner.app"
@@ -466,7 +534,7 @@ copy_verify
 cp $prefix/src/dcpomatic/build/platform/osx/dcpomatic2_combiner.Info.plist "$approot/Info.plist"
 rl=("$approot/MacOS/dcpomatic2_combiner" "$approot/Frameworks/"*.dylib)
 relink_relative "${rl[@]}"
-make_dmg "$appdir" "" "DCP-o-matic Combiner"
+make_dmg "$appdir" "" "DCP-o-matic Combiner" "dcpomatic2_verify openssl dcpomatic2_combiner"
 
 # DCP-o-matic Disk Writer .app
 setup "DCP-o-matic 2 Disk Writer.app"
@@ -541,7 +609,7 @@ exit 0
 EOF
 chmod gou+x $pkgbase/scripts/postinstall
 
-find "$pkgbin" -iname "*.dylib" -print0 | while IFS= read -r -d '' f; do
+find "$pkgbin" -iname "*.dylib" -type f -print0 | while IFS= read -r -d '' f; do
     sign "$f"
 done
 sign "$pkgbin/dcpomatic2_disk_writer"
@@ -550,5 +618,5 @@ mkdir -p "$pkgroot/Library/Application Support/com.dcpomatic"
 mv $pkgbin/* "$pkgroot/Library/Application Support/com.dcpomatic/"
 pkgbuild --root $pkgroot --identifier com.dcpomatic.disk.writer --scripts $pkgbase/scripts "DCP-o-matic Disk Writer.pkg"
 
-make_dmg "$appdir" "DCP-o-matic Disk Writer.pkg" "DCP-o-matic Disk Writer"
+make_dmg "$appdir" "DCP-o-matic Disk Writer.pkg" "DCP-o-matic Disk Writer" "dcpomatic2_verify openssl dcpomatic2_disk"