#!/usr/bin/make -f

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	[ ! -f configure.log ] || $(MAKE) distclean

	find documentation -name "*.png" | xargs rm -f

	dh_clean

configure: configure-stamp
configure-stamp:
	dh_testdir

	./configure \
		--prefix=/usr \
		--bindir=\$${prefix}/bin \
		--docdir=\$${prefix}share/doc \
		--docsubdir=dvdisaster-doc/html \
		--localedir=\$${prefix}/share/locale \
		--mandir=\$${prefix}/share/man

	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) \
		BUILDROOT=$(CURDIR)/debian/tmp \
		install

	# Installing desktop file
	install -D -m 0644 contrib/dvdisaster.desktop debian/dvdisaster/usr/share/applications/dvdisaster.desktop
	sed -i -e 's/dvdisaster48/dvdisaster/' debian/dvdisaster/usr/share/applications/dvdisaster.desktop

	# Installing icon
	install -D -m 0644 contrib/dvdisaster32.png debian/dvdisaster/usr/share/icons/dvdisaster.png

	# Installing pixmaps
	install -D -m 0644 debian/pixmaps/dvdisaster.xpm debian/dvdisaster/usr/share/pixmaps/dvdisaster.xpm

	# Removing double files
	rm -f debian/tmp/usr/bin/dvdisaster-uninstall.sh
	rm -f debian/tmp/usr/share/doc/dvdisaster-doc/html/CHANGELOG
	rm -f debian/tmp/usr/share/doc/dvdisaster-doc/html/COPYING

binary: binary-arch binary-indep

binary-arch: install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a CHANGELOG
	dh_installdocs -a
	dh_installexamples
	dh_install -a --sourcedir=debian/tmp
	dh_installmenu -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary-indep: install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i CHANGELOG
	dh_installdocs -i
	dh_install -i --sourcedir=debian/tmp
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

.PHONY: clean build install binary binary-arch binary-indep
