#!/usr/bin/make -f

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

DEB_BUILD_MAINT_OPTIONS = hardening=+all
DEB_CXXFLAGS_MAINT_PREPEND = -Wall

include /usr/share/dpkg/default.mk

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

ifneq (,$(filter debug,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -DDEBUG
endif

ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -fomit-frame-pointer -ffast-math
endif

debian/po/templates.pot: debian/templates
	@debconf-updatepo

config.status: configure
	dh_testdir
	dh_update_autotools_config
	
	./configure \
	  $(conf_gnu_type) \
	  --disable-silent-rules \
	  --prefix=/usr \
	  --localstatedir=/var \
	  --mandir=\$${prefix}/share/man

build-indep:

build-arch: config.status debian/po/templates.pot
	dh_testdir
	
	$(MAKE) CPPFLAGS="$(CPPFLAGS)" CXXFLAGS="$(CXXFLAGS)" \
	        LDFLAGS="$(LDFLAGS)"

build: build-indep build-arch

.PHONY: build-indep build-arch build

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp
	
	[ ! -f Makefile ] || $(MAKE) clean
	
	dh_clean

.PHONY: clean

install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	
	cp $(CURDIR)/debian/xfstt.insserv \
	   $(CURDIR)/debian/xfstt/etc/insserv.conf.d/xfstt
	
	$(MAKE) install DESTDIR=$(CURDIR)/debian/xfstt

install: install-arch

.PHONY: install-arch install

binary-indep:
	# Nothing to do.

binary-arch: build-arch install-arch
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installinit
	dh_installman
	dh_installchangelogs NEWS
	dh_lintian
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY: binary-indep binary-arch binary
