#!/usr/bin/make -f

DESTDIR := debian/kworkflow

override_dh_install:
	dh_install
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	sphinx-build -b html documentation/ $(DESTDIR)/usr/share/doc/kw/html
endif
	@sed -i -e "s,##KW_INSTALL_PREFIX_TOKEN##,,g" $(DESTDIR)/usr/bin/kw

# Generate man page for each command
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
ALL_MAN_RST_FILES_PATH := $(wildcard documentation/man/features/*.rst)
ALL_MAN_FILES_PATH := $(patsubst %.rst,%.1, $(ALL_MAN_RST_FILES_PATH))

ALL_FILES_NAME := $(notdir $(ALL_MAN_FILES_PATH))

%.1: %.rst
	rst2man < $^ > $@

override_dh_installman: $(ALL_MAN_FILES_PATH)
	rst2man < documentation/man/kw.rst > documentation/man/kw.1
	dh_installman
	rm documentation/man/*.1
	rm documentation/man/features/*.1
endif

override_dh_auto_test:
	./run_tests.sh

override_dh_auto_clean:
	dh_auto_clean
	rm -rf tests/.tmp
	rm -f documentation/man/*.1 documentation/man/features/*.1

%:
	dh $@ --with sphinxdoc
