#!/usr/bin/make -f
# Derived from sample debian/rules that uses debhelper, originally written by
# Joey Hess and Craig Small.

export DH_ALWAYS_EXCLUDE=CVS:.cvsignore
#export DH_VERBOSE=1

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CONFFLAGS =
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	CONFFLAGS += --build $(DEB_HOST_GNU_TYPE)
else
	CONFFLAGS += --build $(DEB_HOST_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

CFLAGS = -Wall -g

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

config.status: configure
	dh_testdir
	CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" ./configure $(CONFFLAGS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info

build: build-stamp
build-stamp: config.status
	dh_testdir

	$(MAKE)

	#docbook-to-man debian/wxmacmolplt.sgml > wxmacmolplt.1

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	-$(MAKE) distclean

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

	# This block may need to change
	touch configure.ac && \
	touch aclocal.m4 && \
	touch configure

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/wxmacmolplt
	install -D -m644 resources/wxmacmolplt.desktop $(CURDIR)/debian/wxmacmolplt/usr/share/applications/wxmacmolplt.desktop
	install -D -m664 resources/wxmacmolplt.png $(CURDIR)/debian/wxmacmolplt/usr/share/pixmaps/wxmacmolplt.png
	install -D -m664 resources/wxmacmolplt.appdata.xml $(CURDIR)/debian/wxmacmolplt/usr/share/appdata/wxmacmolplt.appdata.xml


binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
#	dh_install
	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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