#!/usr/bin/make -f

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

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
MAKEFLAGS += -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

DEB_HOST_GNU_TYPE   := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
CXXFLAGS            := $(shell dpkg-buildflags --get CXXFLAGS)
CPPFLAGS            := $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS             := $(shell dpkg-buildflags --get LDFLAGS)

CXXFLAGS += -Wall -Wextra

config.status: configure
	dh_testdir
	./configure --prefix=/usr \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		CPPFLAGS='$(CPPFLAGS)' CXXFLAGS='$(CXXFLAGS)' \
		LDFLAGS='$(LDFLAGS)'

build-arch: build-stamp
build-stamp: config.status
	$(MAKE)
	docbook-to-man debian/pasmo.sgml > debian/pasmo.1
	cp debian/pasmodoc.html ./
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	if test -f Makefile ; then $(MAKE) distclean ; fi
	rm -f debian/pasmo.1 pasmodoc.html
	test ! -f config.log
	test ! -f config.status
	rm -f build-stamp
	dh_clean

build-indep:
binary-indep:

binary-arch: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) install DESTDIR=$(CURDIR)/debian/pasmo
	dh_installchangelogs NEWS
	dh_installdocs
	dh_installman debian/pasmo.1
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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