#!/usr/bin/make -f

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

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
manpages = debian/Konclude.1
endif

%:
	dh $@ --parallel

# FIXME: Patch code instead - see bug#853477
override_dh_auto_configure:
	QT_SELECT=5 CXXFLAGS="$(CXXFLAGS) -fpermissive" dh_auto_configure

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	KONCLUDE=Release/Konclude debian/tests/examples
endif

$(manpages): debian/%.1 : debian/% Release/%
	chmod +x $<
	help2man --name="Reasoner for the SROIQV(D) Description Logic" \
		--no-info --version-option=$(DEB_VERSION_UPSTREAM) \
		--output=$@ $< \
		|| { ./$< --help; false; }
	perl -i -0 -p \
		-e 's/^\.PP.*$$/.PP\n/ms;' \
		-e 's/\n(\w+) : /\n.TP\n.B $$1\n/g;' \
		-e 's/\n(\\f.+) ?: /\n.TP\n.B $$1\n/g;' \
		-e 's/(\n.IP)?(\nKonclude)/\n.PP$$2/g;' \
		$@
override_dh_auto_install: $(manpages)
	dh_auto_install

# TODO: drop this with debhelper compat level 11+
override_dh_installman:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_installman
endif

override_dh_compress:
	dh_compress --exclude=.xml

override_dh_clean:
	dh_clean
	rm -f $(manpages)
	rm -f test-response*.xml
