
bundle_name = Exult.app
studio_name = Exult_Studio.app
exult_studio = $(top_srcdir)/mapedit/exult_studio$(EXEEXT)

$(top_srcdir)/mapedit/exult_studio$(EXEEXT):
	+(cd $(top_srcdir)/mapedit;$(MAKE) exult_studio$(EXEEXT))

bundle: ${EXE_TARGET}
	mkdir -p $(bundle_name)/Contents/MacOS
	mkdir -p $(bundle_name)/Contents/Resources/data/
	mkdir -p $(bundle_name)/Contents/Documents
	echo "APPL????" > $(bundle_name)/Contents/PkgInfo
	$(INSTALL_DATA) Info.plist $(bundle_name)/Contents/
	$(INSTALL_PROGRAM) $< $(bundle_name)/Contents/MacOS/
	$(INSTALL_DATA) $(srcdir)/macosx/exult.icns $(bundle_name)/Contents/Resources/
	$(INSTALL_DATA) $(srcdir)/data/exult.flx $(bundle_name)/Contents/Resources/data
	$(INSTALL_DATA) $(srcdir)/data/exult_bg.flx $(bundle_name)/Contents/Resources/data
	$(INSTALL_DATA) $(srcdir)/data/exult_si.flx $(bundle_name)/Contents/Resources/data
	$(INSTALL_DATA) $(srcdir)/AUTHORS $(bundle_name)/Contents/Documents
	$(INSTALL_DATA) $(srcdir)/COPYING $(bundle_name)/Contents/Documents
	$(INSTALL_DATA) $(srcdir)/FAQ $(bundle_name)/Contents/Documents
	$(INSTALL_DATA) $(srcdir)/NEWS $(bundle_name)/Contents/Documents
	$(INSTALL_DATA) $(srcdir)/README $(bundle_name)/Contents/Documents
	$(INSTALL_DATA) $(srcdir)/README.MacOSX $(bundle_name)/Contents/Documents
if WITH_OSX_CODE_SIGNATURE
	codesign --options runtime --deep --timestamp -f -s "$(OSX_CODE_SIGNATURE)" $(bundle_name)
endif

bundle_shared: bundle
	dylibbundler -ns -od -b -x $(bundle_name)/Contents/MacOS/$(bin_PROGRAMS) -d $(bundle_name)/Contents/Resources/lib -p @executable_path/../Resources/lib -i /usr/lib
if WITH_OSX_CODE_SIGNATURE
	codesign --options runtime --timestamp -f -s "$(OSX_CODE_SIGNATURE)" $(bundle_name)/contents/resources/lib/*.dylib
endif

studiobundle: $(exult_studio)
	SOURCE=$(abs_top_srcdir) gtk-mac-bundler ./macosx/exult_studio.bundle
if WITH_OSX_CODE_SIGNATURE
	codesign --options runtime --timestamp -f -s "$(OSX_CODE_SIGNATURE)" $(studio_name)/contents/resources/lib/*.dylib
	codesign --options runtime --timestamp -f -s "$(OSX_CODE_SIGNATURE)" $(studio_name)/Contents/Resources/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so
	codesign --options runtime --deep --timestamp -f -s "$(OSX_CODE_SIGNATURE)" $(studio_name)
endif

# Don't try to build/install the MacOS bundle if we are building libexult
if !BUILD_LIBEXULT
install-exec-local: bundle
	mkdir -p $(DESTDIR)/Applications/
	cp -r $(bundle_name) $(DESTDIR)/Applications/
endif

osxdmg: bundle
	mkdir -p Exult-snapshot
	mkdir -p ./Exult-snapshot/images
	cp $(srcdir)/AUTHORS ./Exult-snapshot/Authors
	cp $(srcdir)/COPYING ./Exult-snapshot/License
	cp $(srcdir)/NEWS ./Exult-snapshot/News
	cp $(srcdir)/README.MacOSX ./Exult-snapshot/ReadMe.MacOSX
	cp $(srcdir)/docs/ReadMe.html ./Exult-snapshot/ReadMe.html
	cp $(srcdir)/docs/faq.html ./Exult-snapshot/FAQ.html
	cp $(srcdir)/docs/images/docs*.* ./Exult-snapshot/images
	cp $(srcdir)/docs/images/*.gif ./Exult-snapshot/images
	ln -s -f /Applications "./Exult-snapshot/Drag'n'drop here"
	echo "[InternetShortcut]\nURL=https://github.com/exult/exult/commit/$(REVISION)" > "./Exult-snapshot/Git revision.url"
	SetFile -a V ./Exult-snapshot/images
	SetFile -t ttro -c ttxt ./Exult-snapshot/Authors
	SetFile -t ttro -c ttxt ./Exult-snapshot/License
	SetFile -t ttro -c ttxt ./Exult-snapshot/News
	SetFile -t ttro -c ttxt ./Exult-snapshot/ReadMe.MacOSX
	SetFile -a E ./Exult-snapshot/ReadMe.html
	SetFile -a E "./Exult-snapshot/Git revision.url"
	cp -R $(bundle_name) ./Exult-snapshot/
	create-dmg \
	  --volname "Exult 1.10.1" \
	  --volicon "./macosx/exult.icns" \
	  --background "./macosx/diskback.png" \
	  --window-pos 200 120 \
	  --window-size 685 545 \
	  --text-size 14 \
	  --icon-size 100 \
	  --icon "Exult.app" 310 90 \
	  --icon "Drag'n'drop here" 554 90 \
	  --icon "Git revision.url" 80 90 \
	  --icon "ReadMe.html" 80 395 \
	  --icon "FAQ.html" 177 395 \
	  --icon "News" 274 395 \
	  --icon "License" 371 395 \
	  --icon "Authors" 468 395 \
	  --icon "ReadMe.MacOSX" 564 395 \
	  --hdiutil-quiet \
	  --no-internet-enable \
	  "Exult-1.10.1.dmg" \
	  "./Exult-snapshot/"
	rm -rf Exult-snapshot

studiodmg: studiobundle
	mkdir -p Studio-snapshot
	mkdir -p ./Studio-snapshot/images
	cp $(srcdir)/AUTHORS ./Studio-snapshot/Authors
	cp $(srcdir)/COPYING ./Studio-snapshot/License
	cp $(srcdir)/README.MacOSX ./Studio-snapshot/ReadMe.MacOSX
	cp $(srcdir)/docs/exult_studio.html ./Studio-snapshot/Manual.html
	cp $(srcdir)/docs/images/studio*.* ./Studio-snapshot/images
	cp $(srcdir)/docs/images/*.gif ./Studio-snapshot/images
	ln -s -f /Applications "./Studio-snapshot/Drag'n'drop here"
	echo "[InternetShortcut]\nURL=https://github.com/exult/exult/commit/$(REVISION)" > "./Studio-snapshot/Git revision.url"
	SetFile -a V ./Studio-snapshot/images
	SetFile -t ttro -c ttxt ./Studio-snapshot/Authors
	SetFile -t ttro -c ttxt ./Studio-snapshot/License
	SetFile -t ttro -c ttxt ./Studio-snapshot/ReadMe.MacOSX
	SetFile -a E ./Studio-snapshot/Manual.html
	SetFile -a E "./Studio-snapshot/Git revision.url"
	cp -R $(studio_name) ./Studio-snapshot/
	create-dmg \
	  --volname "Exult Studio 1.10.1" \
	  --volicon "./macosx/exult_studio.icns" \
	  --background "./macosx/diskback.png" \
	  --window-pos 200 120 \
	  --window-size 685 545 \
	  --text-size 14 \
	  --icon-size 100 \
	  --icon "Exult_Studio.app" 295 90 \
	  --icon "Drag'n'drop here" 554 90 \
	  --icon "Git revision.url" 80 90 \
	  --icon "Manual.html" 164 395 \
	  --icon "License" 260 395 \
	  --icon "Authors" 356 395 \
	  --icon "ReadMe.MacOSX" 452 395 \
	  --hdiutil-quiet \
	  --no-internet-enable \
	  "ExultStudio-1.10.1.dmg" \
	  "./Studio-snapshot/"
	rm -rf Studio-snapshot

clean-local:
	-rm -f Exult-1.10.0.dmg
	-rm -f ExultStudio-1.10.0.dmg.dmg
	-rm -f tmpicnsE.rsrc
	-rm -f tmpicnsES.rsrc
	-rm -rf $(bundle_name)
	-rm -rf $(studio_name)
