-WORK=build/platform/osx
-ENV=/Users/carl/Environments/osx/10.6
-ROOT=$1
-
-# Main application
-appdir="DCP-o-matic 2.app"
-approot="$appdir/Contents"
-libs="$approot/lib"
-macos="$approot/MacOS"
-resources="$approot/Resources"
-rm -rf "$WORK/$appdir"
-mkdir -p "$WORK/$macos"
-mkdir -p "$WORK/$libs"
-mkdir -p "$WORK/$resources"
-
-# KDM creator
-appdir_kdm="DCP-o-matic 2 KDM Creator.app"
-approot_kdm="$appdir_kdm/Contents"
-libs_kdm="$approot_kdm/lib"
-macos_kdm="$approot_kdm/MacOS"
-resources_kdm="$approot_kdm/Resources"
-rm -rf "$WORK/$appdir_kdm"
-mkdir -p "$WORK/$macos_kdm"
-
-# Server
-appdir_server="DCP-o-matic 2 Server.app"
-approot_server="$appdir_server/Contents"
-libs_server="$approot_server/lib"
-macos_server="$approot_server/MacOS"
-resources_server="$approot_server/Resources"
-rm -rf "$WORK/$appdir_server"
-mkdir -p "$WORK/$macos_server"
-
-# Batch converter
-appdir_batch="DCP-o-matic 2 Batch Converter.app"
-approot_batch="$appdir_batch/Contents"
-libs_batch="$approot_batch/lib"
-macos_batch="$approot_batch/MacOS"
-resources_batch="$approot_batch/Resources"
-rm -rf "$WORK/$appdir_batch"
-mkdir -p "$WORK/$macos_batch"
-
-relink="dcpomatic"
-
-function universal_copy {
- for f in $1/32/$2; do
- if [ -h $f ]; then
- ln -s $(readlink $f) "$3/`basename $f`"
- else
- g=`echo $f | sed -e "s/\/32\//\/64\//g"`
- mkdir -p "$3"
- lipo -create $f $g -output "$3/`basename $f`"
- fi
+ENV=$1
+ROOT=$2
+TYPE=$3
+APPLE_ID=$4
+APPLE_PASSWORD=$5
+
+if [ "$TYPE" != "universal" -a "$TYPE" != "thin" ]; then
+ echo $SYNTAX
+ echo "where <type> is universal or thin"
+ exit 1
+fi
+
+# This is our work area for making up the .dmgs
+mkdir -p build/platform/osx
+cd build/platform/osx
+
+function copy {
+ case $TYPE in
+ universal)
+ for f in $1/32/$2; do
+ if [ -h $f ]; then
+ ln -s $(readlink $f) "$3/`basename $f`"
+ else
+ g=`echo $f | sed -e "s/\/32\//\/64\//g"`
+ mkdir -p "$3"
+ lipo -create $f $g -output "$3/`basename $f`"
+ fi
+ done
+ ;;
+ thin)
+ if [ -h $1/$2 ]; then
+ ln -s $(readlink $1/$2) "$3/`basename $f`"
+ else
+ cp $1/$2 "$3"
+ fi
+ ;;
+ esac
+}
+
+function copy_lib_root {
+ case $TYPE in
+ universal)
+ for f in $ROOT/32/lib/$1*.dylib; do
+ if [ -h $f ]; then
+ ln -s $(readlink $f) "$2/`basename $f`"
+ else
+ g=`echo $f | sed -e "s/\/32\//\/64\//g"`
+ mkdir -p "$2"
+ lipo -create $f $g -output "$2/`basename $f`"
+ fi
+ done
+ ;;
+ thin)
+ for f in $ROOT/lib/$1*.dylib; do
+ if [ -h $f ]; then
+ ln -s $(readlink $f) "$2/`basename $f`"
+ else
+ mkdir -p "$2"
+ cp $f "$2"
+ fi
+ done
+ ;;
+ esac
+ to_relink="$to_relink|$1"
+}
+
+function copy_lib_env {
+ case $TYPE in
+ universal)
+ for f in $ENV/32/lib/$1*.dylib; do
+ if [ -h $f ]; then
+ ln -s $(readlink $f) "$2/`basename $f`"
+ else
+ g=`echo $f | sed -e "s/\/32\//\/64\//g"`
+ mkdir -p "$2"
+ lipo -create $f $g -output "$2/`basename $f`"
+ fi
+ done
+ ;;
+ thin)
+ for f in $ENV/64/lib/$1*.dylib; do
+ if [ -h $f ]; then
+ ln -s $(readlink $f) "$2/`basename $f`"
+ else
+ mkdir -p "$2"
+ cp $f "$2"
+ fi
+ done
+ ;;
+ esac
+ to_relink="$to_relink|$1"
+}
+
+# @param #1 directory to copy to
+function copy_libs {
+ local dest="$1"
+ copy_lib_root libcxml "$dest"
+ copy_lib_root libdcp-1.0 "$dest"
+ copy_lib_root libasdcp-carl "$dest"
+ copy_lib_root libkumu-carl "$dest"
+ copy_lib_root libsub "$dest"
+ copy_lib_root libopenjp2 "$dest"
+ copy_lib_root libavdevice "$dest"
+ copy_lib_root libavformat "$dest"
+ copy_lib_root libavfilter "$dest"
+ copy_lib_root libavutil "$dest"
+ copy_lib_root libavcodec "$dest"
+ copy_lib_root libswscale "$dest"
+ copy_lib_root libpostproc "$dest"
+ copy_lib_root libswresample "$dest"
+ copy_lib_root liblwext4 "$dest"
+ copy_lib_root libblockdev "$dest"
+ copy_lib_root libleqm_nrt "$dest"
+ copy $ROOT src/dcpomatic/build/src/lib/libdcpomatic2.dylib "$dest"
+ copy $ROOT src/dcpomatic/build/src/wx/libdcpomatic2-wx.dylib "$dest"
+ copy_lib_env libboost_system "$dest"
+ copy_lib_env libboost_filesystem "$dest"
+ copy_lib_env libboost_thread "$dest"
+ copy_lib_env libboost_date_time "$dest"
+ copy_lib_env libboost_locale "$dest"
+ copy_lib_env libboost_regex "$dest"
+ copy_lib_env libxml++ "$dest"
+ copy_lib_env libxslt "$dest"
+ copy_lib_env libxml2 "$dest"
+ copy_lib_env libglibmm-2.4 "$dest"
+ copy_lib_env libgobject "$dest"
+ copy_lib_env libgthread "$dest"
+ copy_lib_env libgmodule "$dest"
+ copy_lib_env libsigc "$dest"
+ copy_lib_env libglib-2 "$dest"
+ copy_lib_env libintl "$dest"
+ copy_lib_env libsndfile "$dest"
+ copy_lib_env libssh "$dest"
+ copy_lib_env libwx "$dest"
+ copy_lib_env libfontconfig "$dest"
+ copy_lib_env libfreetype "$dest"
+ copy_lib_env libexpat "$dest"
+ copy_lib_env libltdl "$dest"
+ copy_lib_env libxmlsec1 "$dest"
+ copy_lib_env libcurl "$dest"
+ copy_lib_env libffi "$dest"
+ copy_lib_env libpango "$dest"
+ copy_lib_env libcairo "$dest"
+ copy_lib_env libpixman "$dest"
+ copy_lib_env libharfbuzz "$dest"
+ copy_lib_env libsamplerate "$dest"
+ copy_lib_env libicui18n "$dest"
+ copy_lib_env libicudata "$dest"
+ copy_lib_env libicuio "$dest"
+ copy_lib_env libicule "$dest"
+ copy_lib_env libiculx "$dest"
+ copy_lib_env libicutest "$dest"
+ copy_lib_env libicutu "$dest"
+ copy_lib_env libicuuc "$dest"
+ copy_lib_env libFLAC "$dest"
+ copy_lib_env libvorbis "$dest"
+ copy_lib_env libogg "$dest"
+ copy_lib_env libxerces-c "$dest"
+}
+
+# @param #1 directory to copy to
+function copy_resources {
+ local dest="$1"
+ case $TYPE in
+ universal)
+ local prefix=$ROOT/32
+ ;;
+ thin)
+ local prefix=$ROOT
+ ;;
+ esac
+ cp $prefix/src/dcpomatic/graphics/osx/dcpomatic_small.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"
+ cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_player.icns "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_batch.icns "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_playlist.icns "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/dcpomatic2_disk.icns "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/colour_conversions.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/defaults.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/kdm_email.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/email.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/servers.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/tms.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/keys.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/cover_sheet.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/notifications.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/locations.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/osx/preferences/sound.png "$dest"
+ cp $prefix/src/dcpomatic/fonts/LiberationSans-Regular.ttf "$dest"
+ cp $prefix/src/dcpomatic/fonts/LiberationSans-Italic.ttf "$dest"
+ cp $prefix/src/dcpomatic/fonts/LiberationSans-Bold.ttf "$dest"
+ cp $prefix/src/dcpomatic/fonts/fonts.conf.osx "$dest"/fonts.conf
+ cp $prefix/src/dcpomatic/graphics/splash.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/zoom.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/zoom_all.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/select.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/snap.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/sequence.png "$dest"
+ cp $prefix/src/dcpomatic/graphics/me.jpg "$dest"
+ cp -r $prefix/share/libdcp/xsd "$dest"
+
+ # i18n: DCP-o-matic .mo files
+ 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
+ mkdir -p "$dest/$lang/LC_MESSAGES"
+ cp $prefix/src/dcpomatic/build/src/lib/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
+ cp $prefix/src/dcpomatic/build/src/wx/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
+ cp $prefix/src/dcpomatic/build/src/tools/mo/$lang/*.mo "$dest/$lang/LC_MESSAGES"
+ done
+
+ # i18n: wxWidgets .mo files
+ for lang in de es fr it sv nl ru pl da cs; do
+ mkdir "$dest/$lang"
+ cp $ENV/64/share/locale/$lang/LC_MESSAGES/wxstd.mo "$dest/$lang"
+ done
+}
+
+# param $1 list of things that link to other things
+function relink_relative {
+ to_relink=`echo $to_relink | sed -e "s/\+//g"`
+ local linkers=("$@")
+
+ for obj in "${linkers[@]}"; do
+ deps=`otool -L "$obj" | awk '{print $1}' | egrep "($to_relink)" | egrep "($ENV|$ROOT|boost|libicu)"`
+ changes=""
+ for dep in $deps; do
+ base=`basename $dep`
+ if [ "$TYPE" == "universal" ]; then
+ # $dep will be a path within 64/; make a 32/ path too
+ dep32=`echo $dep | sed -e "s/\/64\//\/32\//g"`
+ changes="$changes -change $dep @executable_path/../Frameworks/$base -change $dep32 @executable_path/../Frameworks/$base"
+ else
+ changes="$changes -change $dep @executable_path/../Frameworks/$base"
+ fi
+ done
+ if test "x$changes" != "x"; then
+ install_name_tool $changes -id `basename "$obj"` "$obj"
+ fi