#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1

include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

TARGET_DIR = $(CURDIR)/debian/tmp/usr
TARGET_LIBDIR = $(TARGET_DIR)/lib/$(DEB_HOST_MULTIARCH)

%:
	dh $@

override_dh_auto_clean:
	$(MAKE) clean
	rm -f .config

override_dh_auto_configure:

override_dh_auto_build:
	$(MAKE) CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
	$(MAKE) docs

override_dh_auto_test:
ifeq (,$(filter, nocheck,$(DEB_BUILD_OPTIONS)))
	@echo 'blhc: ignore-line-regexp: .*(qt|Qt|tst).*'
	$(MAKE) check
endif

override_dh_auto_install:
	$(MAKE) install prefix=$(TARGET_DIR) libdir=$(TARGET_LIBDIR)

execute_after_dh_auto_build:
	help2man --version-string=$(DEB_VERSION_UPSTREAM) --name="tinycbor Concise Binary Object Representation (CBOR) library" -N -o cbordump.1 bin/cbordump
	help2man --version-string=$(DEB_VERSION_UPSTREAM) --name="tinycbor Concise Binary Object Representation (CBOR) library" -N -o tinycbor-json2cbor.1 bin/json2cbor

override_dh_installdocs:
ifeq (,$(filter, nodoc,$(DEB_BUILD_OPTIONS)))
	dh_installdocs
	dh_link -plibtinycbor-dev /usr/share/javascript/jquery/jquery.js usr/share/doc/libtinycbor-dev/html/jquery.js
endif
