#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PKG=mednafenfe
PREFIX=$(CURDIR)/debian/$(PKG)/usr
DEBVER=$(shell dpkg-parsechangelog |sed -n -e '/^Version:/s/^Version: //p')
DEB_BUILD_PROG:=debuild --preserve-envvar PATH --preserve-envvar CCACHE_DIR -us -uc $(DEB_BUILD_PROG_OPTS)

build: build-stamp

build-stamp:  
	dh_testdir

	# Add here commands to compile the package.
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	rm -rf po/mo
	find . -name "*.pyc" -exec rm -f {} \;

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/mednafenfe.

	install -m 0644 -t $(PREFIX)/share/mfe \
		$(CURDIR)/resources/mfe.ui \
		$(CURDIR)/resources/mfe.ini.spec \
		$(CURDIR)/resources/mednafen.html \
		$(CURDIR)/resources/quit.png \
		$(CURDIR)/resources/help.png \
		$(CURDIR)/resources/engine.png \
		$(CURDIR)/resources/about.png \
		$(CURDIR)/resources/clear.png \
		$(CURDIR)/resources/general.png \
		$(CURDIR)/resources/doc.png \
		$(CURDIR)/resources/license.png \
		$(CURDIR)/resources/stop.png \
		$(CURDIR)/resources/mfe.png \
		$(CURDIR)/resources/save.png \
		$(CURDIR)/resources/play.png

	install -m 0644 -t $(PREFIX)/share/pixmaps \
		$(CURDIR)/resources/mfe.png

	install -m 0644 -t $(PREFIX)/share/applications \
		$(CURDIR)/resources/mfe.desktop

	#find $(CURDIR)/mfe -name "*.py" -exec python -m py_compile {} \;

	install -m 0755 -t $(PREFIX)/bin \
		$(CURDIR)/scripts/mfe

	if test -d /usr/lib/python2.4 ; then \
		install -m 0644 -t $(PREFIX)/lib/python2.4/site-packages/mfe \
			$(CURDIR)/mfe/* ; \
	fi

	if test -d /usr/lib/python2.5 ; then \
		install -m 0644 -t $(PREFIX)/lib/python2.5/site-packages/mfe \
		 	$(CURDIR)/mfe/* ; \
	fi

	if test -d /usr/lib/python2.6 ; then \
		install -m 0644 -t $(PREFIX)/lib/python2.6/dist-packages/mfe \
		 	$(CURDIR)/mfe/* ; \
	fi

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_scrollkeeper
	dh_installmime
	dh_desktop
#	dh_iconcache
#	dh_gconf
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

arch-build:
	rm -rf debian/arch-build
	mkdir -p debian/arch-build/$(PKG)-$(DEBVER)
	tar -c --exclude=arch-build --no-recursion -f - `bzr inventory` | (cd debian/arch-build/$(PKG)-$(DEBVER);tar xf -)
	(cd debian/arch-build/$(PKG)-$(DEBVER) && $(DEB_BUILD_PROG))

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