#!/usr/bin/make -f

PACKAGE=earth3d

#export DH_VERBOSE=1
export DH_OPTIONS

include /usr/share/quilt/quilt.make 

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

debian/earth.xpm: images/webpres.png
	convert -resize 32 $< $@

configure: configure-stamp
configure-stamp: patch
	dh_testdir
	qmake earth3d.pro
	touch configure-stamp

#Architecture 
build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: configure-stamp 

# Add here commands to compile the arch part of the package.
	$(MAKE)

build-indep: build-indep-stamp
build-indep-stamp: configure-stamp 

# Add here commands to compile the indep part of the package.
#$(MAKE) doc

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp build-indep-stamp configure-stamp
	rm -f debian/earth.xpm

# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f Makefile

	dh_clean

install: install-arch #install-indep
install-indep:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -i

#	dh_movefiles -i

install-arch: debian/earth.xpm
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -a
	dh_installman

	$(MAKE) install DESTDIR=$(CURDIR)/debian/$(PACKAGE)

	# The qmake install target is empty.  Do the install here instead.
	install earth3d $(CURDIR)/debian/$(PACKAGE)/usr/bin/earth3d
	install -m644  Changelog \
	  $(CURDIR)/debian/$(PACKAGE)/usr/share/doc/$(PACKAGE)/changelog
	install -D -m 644 debian/earth.xpm $(CURDIR)/debian/$(PACKAGE)/usr/share/pixmaps/earth.xpm
	install -D -m 644 debian/earth3d.desktop $(CURDIR)/debian/$(PACKAGE)/usr/share/applications/kde/earth3d.desktop

#	dh_movefiles -a
# Must not depend on anything. This is to be called by
# binary-arch/binary-multi
# in another 'make' thread.
binary-common:
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs 
	dh_installmenu
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture independant packages using the common target.
binary-indep: build-indep install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

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