#!/usr/bin/make -f

#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_BUILD_OPTIONS = parallel=1

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
PKG  = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
VER ?= $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{^Version:\s+(?:\d+:)?(\d.*)(?:\-\d+.*)};')


%:
	dh $@ --with autoreconf

## Note! Workaround for the binary-dir present in the source dir -->
.PHONY: binary
binary:
	dh $@
## <--

override_dh_auto_configure:
	dh_auto_configure -- --includedir=/usr/include/libsmpp34
	cat debian/libsmpp34.pc.in | sed 's/$$VERSION/${VER}/' | sed 's/$$PREFIX/\/usr/' \
     | sed 's#$$LIBDIR#/usr/lib/$(DEB_HOST_MULTIARCH)#' > debian/libsmpp34.pc

override_dh_auto_install:
	dh_auto_install
	install -D -m 644 debian/libsmpp34.pc debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libsmpp34.pc


override_dh_clean:
	dh_clean
	rm -f debian/libsmpp34.pc


get-orig-source: $(info I: $(PKG)_$(VER))
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --force-download --download-version $(VER) $(PKD)

