#!/usr/bin/make -f
%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -O--parallel -- \
		--libdir=/usr/lib \
		--mandir=/usr/share/man \
		--docdir=/usr/share/doc/dosemu \
		--sysconfdir=/etc/dosemu \
		--with-x11fontdir=/usr/share/fonts/X11/misc/dosemu \
		--with-syshdimagedir=/var/lib/dosemu \
		--with-fdtarball=freedos/dosemu-freedos-1.0-bin.tgz \

override_dh_auto_install:
	dh_auto_install -O--parallel
	# create correctly-sized xpm
	[ -e etc/dosemu32x24.xpm ] || \
	convert -resize 32x24 etc/dosemu.xpm etc/dosemu32x24.xpm
	# clean up redundant documentation
	rm -f debian/dosemu/usr/lib/dosemu/drive_z/doc/copying
	rm -f debian/dosemu/usr/lib/dosemu/drive_z/doc/*/copying
	rm -f debian/dosemu/usr/lib/dosemu/drive_z/doc/*/copying.txt
	rm -f debian/dosemu/usr/lib/dosemu/drive_z/doc/*/license.txt
	rm -f debian/dosemu/usr/lib/dosemu/drive_z/doc/exe2bin/exe2bin.txt
	# reloate freedos docs
	mkdir -p debian/dosemu/usr/share/doc/dosemu
	mv debian/dosemu/usr/lib/dosemu/drive_z/doc debian/dosemu/usr/share/doc/dosemu/freedos
	rmdir debian/dosemu/usr/share/doc/dosemu/freedos/exe2bin
	# back to documentation
	ln -s ../../../share/doc/dosemu/freedos debian/dosemu/usr/lib/dosemu/drive_z/doc
	# set up common files and symlinks
	mv debian/dosemu/usr/lib/dosemu/drive_z/autoexec.bat debian/dosemu/etc/dosemu/freedos/
	ln -s ../../../../etc/dosemu/freedos/autoexec.bat debian/dosemu/usr/lib/dosemu/drive_z/autoexec.bat
	mv debian/dosemu/usr/lib/dosemu/drive_z/config.sys debian/dosemu/etc/dosemu/freedos/
	ln -s ../../../../etc/dosemu/freedos/config.sys debian/dosemu/usr/lib/dosemu/drive_z/config.sys

override_dh_clean:
	dh_clean
	find $(CURDIR) -name '*.s.out' -print0 | xargs -0 rm -f
	rm -f etc/dosemu32x24.xpm

VERSION=$(shell dpkg-parsechangelog | grep ^Version | cut -d+ -f1 | cut -d\  -f2)
DATE_RELEASE=$(shell dpkg-parsechangelog | grep ^Version | cut -d+ -f2 | cut -d. -f2 | cut -d- -f1)
VCS_RELEASE=$(shell dpkg-parsechangelog | grep ^Version | cut -d+ -f3 | cut -d. -f2 | cut -d- -f1)
ORIG_FILE=$(CURDIR)/../dosemu_$(VERSION)+$(DATE_RELEASE)+$(VCS_RELEASE).orig.tar.bz2
CO_DIR=$(CURDIR)/dosemu-$(VERSION)+$(DATE_RELEASE)+$(VCS_RELEASE)
get-orig-source:
	test ! -e $(ORIG_FILE)
	test ! -e $(CO_DIR)
	git clone git://git.code.sf.net/p/dosemu/code $(CO_DIR)
	(cd $(CO_DIR) && git reset --hard $(VCS_RELEASE))
	tar cjf $(ORIG_FILE) -C `dirname $(CO_DIR)` --exclude .git `basename $(CO_DIR)`
	rm -rf $(CO_DIR)
