#!/usr/bin/env bash

# pillow 8.2.0 comes with older libtiff.5.dylib (version 12.0.0)
# but proj4 (libproj.19.dylib) needs version 13.0.0
#   -> take libtiff from homebrew
# cd /Users/cuntz/.pyenv/versions/3.8.9/envs/pystd/lib/python3.8/site-packages/PIL/.dylibs/
# mv libtiff.5.dylib libtiff.5.dylib.save
# cp /usr/local/lib/libtiff.5.dylib .

# Background in ncvue_app.spec
# Check with:
#   open dist/ncvue.app/

set -ex

# Create app:
pyinstaller --noconfirm --onefile --windowed ncvue_app.spec

# Create dmg (https://gist.github.com/jadeatucker/5382343)
hdiutil create -volname ncvue -srcfolder dist -ov -format UDRW dist.dmg
hdiutil attach dist.dmg
cd /Volumes/ncvue
ln -s /Applications
cd -
hdiutil detach /Volumes/ncvue
# if the nex line fails with
#   hdiutil: convert failed - Resource temporarily unavailable
# open Disk Utility and eject the Apple read/write Media.
# Then run the two commands below
hdiutil convert dist.dmg -format UDZO -o ncvue.dmg -ov
\rm dist.dmg

exit
