#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.

#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)


CFLAGS = -Wall -g

DESTDIR = $(CURDIR)/debian/fmtx-faker

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

configure: configure-stamp
configure-stamp:
	dh_testdir

	./autogen.sh
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --sysconfdir=/etc --bindir=/usr/bin CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

	touch $@

build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-./antigen.sh

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	$(MAKE) DESTDIR=$(DESTDIR) install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	install -m644 -D $(CURDIR)/debian/schemas $(DESTDIR)/usr/share/gconf/schemas/fmtx-faker.schemas
	#dh_gconf #Causes problems when purging fmtx-faker.
	#install -m644 -D $(CURDIR)/debian/upstart $(DESTDIR)/etc/event.d/fmtx-faker
	install -m644 -D $(CURDIR)/debian/sudoers $(DESTDIR)/etc/sudoers.d/fmtx-faker.sudoers
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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