#!/usr/bin/make -f

# export DH_VERBOSE=1

configure: configure-stamp
configure-stamp:
	dh_testdir
	./autogen.sh
	./configure --prefix=/usr --mandir=/usr/share/man LDFLAGS="-Wl,--as-needed"
	touch configure-stamp

#Architecture
build: build-stamp

build-stamp: configure-stamp  
	dh_testdir
	$(MAKE)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean aclocal.m4 configure Makefile.in src/Makefile.in src/rc/Makefile.in objects/Makefile.in \
	buttons/Makefile.in data/Makefile.in backgrounds/Makefile.in wxVillaLib/Makefile.in docs/Makefile.in \
	templates/Makefile.in \
	build-arch-stamp build-indep-stamp configure-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/dvdstyler
	dh_movefiles --sourcedir=debian/dvdstyler

	# Move the manpage to the main runtime package
	mv debian/dvdstyler-data/usr/share/man/man1/dvdstyler.1 \
		debian/dvdstyler/usr/share/man/man1/dvdstyler.1

	# Compress the manpage file
	# gzip -9fn debian/dvdstyler/usr/share/man/man1/dvdstyler.1

	# Move the desktop file to the main runtime package
	mv debian/dvdstyler-data/usr/share/applications/dvdstyler.desktop \
		debian/dvdstyler/usr/share/applications/dvdstyler.desktop

	# Move the icon to the main runtime package
	mv debian/dvdstyler-data/usr/share/pixmaps/dvdstyler.png \
		debian/dvdstyler/usr/share/pixmaps/dvdstyler.png

	# Copy the templates to dvdstyler-data runtime package
	mkdir debian/dvdstyler-data/usr/share/dvdstyler/templates
	cp templates/*.png templates/*.dvdt \
		debian/dvdstyler-data/usr/share/dvdstyler/templates/
	
	# The files under templates/ aren't executable.
	chmod 0644 debian/dvdstyler-data/usr/share/dvdstyler/templates/*

	# Don't install doc files twice.
	rm -rf debian/dvdstyler-data/usr/share/doc/dvdstyler/

	find debian -type d | xargs rmdir -p --ignore-fail-on-non-empty

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure patch unpatch
