#!/usr/bin/make -f

#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

build: build-arch build-indep
build-indep:
build-arch: build-stamp

builddir/config.status: configure
	dh_testdir
	mkdir -p builddir
	cp /usr/share/misc/config.sub /usr/share/misc/config.guess .
	cd builddir && ../configure --prefix=/usr \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		CPPFLAGS='$(CPPFLAGS)' CXXFLAGS='$(CXXFLAGS)' \
		LDFLAGS='$(LDFLAGS)'

build-stamp: builddir/config.status
	dh_testdir
	$(MAKE) -C builddir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp config.guess config.sub
	rm -rf builddir
	dh_clean

binary-indep:

binary-arch: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) -C builddir DESTDIR=$(CURDIR)/debian/blm install install-man
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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