#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS
configure: configure-stamp 
configure-stamp: patch
	dh_testdir
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif	
	chmod +x autogen.sh
	./autogen.sh --prefix=/usr
	touch configure-stamp


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

clean: unpatch
	dh_testdir
	dh_testroot
	$(RM) *-stamp
#	-$(MAKE) distclean
	rm -f activity.info config.sub config.guess
	dh_clean Makefile config.log configure config.status etoys



install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install-etoys  prefix=$(CURDIR)/debian/etoys/usr

	mv $(CURDIR)/debian/etoys/usr/share/etoys/QuickGuides \
	 $(CURDIR)/debian/etoys-doc/usr/share/etoys/
	mv $(CURDIR)/debian/etoys/usr/share/etoys/ExampleEtoys \
	 $(CURDIR)/debian/etoys-doc/usr/share/etoys/
	mv $(CURDIR)/debian/etoys/usr/share/etoys/*.pr \
	 $(CURDIR)/debian/etoys-doc/usr/share/etoys/
	mv $(CURDIR)/debian/etoys/usr/bin/etoys \
	 $(CURDIR)/debian/etoys/usr/games/

	rm -Rf $(CURDIR)/debian/etoys/usr/bin
	rm -Rf $(CURDIR)/debian/etoys/usr/share/mime/

	rm -f  $(CURDIR)/debian/etoys/usr/share/doc/etoys/INSTALL*
	rm -f  $(CURDIR)/debian/etoys/usr/share/doc/etoys/LICENSE*
	rm -f  $(CURDIR)/debian/etoys/usr/share/doc/etoys/mkChangeLog*
	rm -f  $(CURDIR)/debian/etoys/usr/share/doc/etoys/ChangeLog*

	dh_install debian/activity-etoys.xpm usr/share/pixmaps
	dh_install debian/etoys.desktop usr/share/applications

binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installman debian/etoys.6
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture independant packages using the common target.
binary-indep: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	#nothing to do

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