#!/usr/bin/make -f

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

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = Readme.html Readme.txt
manpages = debian/Konclude.1
endif

export QT_SELECT = 5

override_dh_auto_configure:
	dh_auto_configure -- Konclude.pro

override_dh_auto_test:
	KONCLUDE=Release/Konclude prove --verbose debian/tests/*.t

$(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: $(DOCS) $(manpages)
	dh_auto_install

override_dh_installdocs:
	dh_installdocs -- $(DOCS)

override_dh_compress:
	dh_compress --exclude=.xml

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

%.html: %.md
	pandoc --from gfm-raw_html --to html --standalone --output $@ $<

%.txt: %.md
	pandoc --from gfm-raw_html --to plain --output $@ $<

%:
	dh $@