
all:: QDevelop.dmg

clean::
	rm -rf qdevelop_0.25.2
	rm -rf mkdmg
	rm -rf mac.diff
	# rm -rf .cache

QDevelop.dmg: .cache/qdevelop_0.25.2.zip mkdmg mac.diff
	unzip .cache/qdevelop_0.25.2.zip
	patch -p0 < ./mac.diff
	cd qdevelop_0.25.2 ; qmake ; xcodebuild
	./mkdmg qdevelop_0.25.2/build/Default/qdevelop.app
	mv qdevelop.app.dmg QDevelop.dmg

.cache/qdevelop_0.25.2.zip:
	mkdir -p .cache
	cd .cache ; curl -O http://qdevelop.free.fr/download/qdevelop_0.25.2.zip

mac.diff:
	@echo "--- qdevelop_0.25.2/src/mainimpl.cpp.orig	2007-12-26 12:52:59.000000000 +0800" > mac.diff
	@echo "+++ qdevelop_0.25.2/src/mainimpl.cpp	2007-12-26 12:53:11.000000000 +0800" >> mac.diff
	@echo "@@ -151,6 +151,7 @@" >> mac.diff
	@echo "     //" >> mac.diff
	@echo "     //" >> mac.diff
	@echo "     setCentralWidget( m_tabEditors );" >> mac.diff
	@echo "+    setUnifiedTitleAndToolBarOnMac(true);" >> mac.diff
	@echo "     //" >> mac.diff
	@echo "     m_assistant = new Assistant();" >> mac.diff
	@echo "     m_designer = new Designer();" >> mac.diff

mkdmg:
	@echo "#!/bin/zsh" > ./mkdmg
	@echo "# Original script of this useful tool from here:" >> ./mkdmg
	@echo "# http://www.kernelthread.com/mac/apme/archive/" >> ./mkdmg
	@echo "PATH=/bin:/sbin:/usr/bin:/usr/sbin" >> ./mkdmg
	@echo "SCRATCH=./.mkdmg.\$$\$$" >> ./mkdmg
	@echo "error()" >> ./mkdmg
	@echo "{" >> ./mkdmg
	@echo "    echo \"Error\"" >> ./mkdmg
	@echo "    rm -rf \$$SCRATCH" >> ./mkdmg
	@echo "    exit 1" >> ./mkdmg
	@echo "}" >> ./mkdmg
	@echo "[ \$$ARGC -ne 1 ] && echo \"usage: mkdmg <directory>\" && exit 1" >> ./mkdmg
	@echo "[ ! -e \$$1 ] && echo \"*** \$$1 does not exist.\" && exit 1" >> ./mkdmg
	@echo "NAME=\`basename \$$1\`" >> ./mkdmg
	@echo "NAME=\"\$$NAME\"" >> ./mkdmg
	@echo "ARCH=\"\$$NAME Archive\"" >> ./mkdmg
	@echo "IMAGE=\$$SCRATCH/\$$ARCH.dmg" >> ./mkdmg
	@echo "OUTPUT=\"./\$$NAME.dmg\"" >> ./mkdmg
	@echo "mkdir \$$SCRATCH" >> ./mkdmg
	@echo "echo \"Creating disk image \$$OUTPUT...\"" >> ./mkdmg
	@echo "SIZE=\`du -s -k \$$1 | awk '{print \$$1}'\` || error" >> ./mkdmg
	@echo "hdiutil create \"\$$IMAGE\" -volname \"\$$ARCH\" -megabytes \`expr 5 + \$$SIZE / 1000\` -type SPARSE -fs HFS+ > /dev/null 2>&1 || error" >> ./mkdmg
	@echo "hdid \$$IMAGE.sparseimage > /dev/null 2>&1 || error" >> ./mkdmg
	@echo "ditto -rsrcFork \$$1 \"/Volumes/\$$ARCH/\$$NAME\" > /dev/null 2>&1 || error" >> ./mkdmg
	@echo "hdiutil detach \`mount | grep \"Volumes/\$$ARCH\" | awk '{print \$$1}'\` > /dev/null 2>&1 || error" >> ./mkdmg
	@echo "hdiutil convert \"\$$IMAGE.sparseimage\" -format UDZO -o \$$OUTPUT -imagekey zlib-devel=9 > /dev/null 2>&1 || error" >> ./mkdmg
	@echo "echo \"Disk image \$$OUTPUT ready\"" >> ./mkdmg
	@echo "rm -rf \$$SCRATCH" >> ./mkdmg
	@echo >> ./mkdmg
	chmod a+x ./mkdmg

