#!/usr/bin/make -f

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
CHANGELOGS = CHANGELOG.html CHANGELOG.txt
MANPAGES = debian/btm.1
endif

# use local fork of dh-cargo and cargo wrapper
PATH := $(CURDIR)/debian/dh-cargo/bin:$(PATH)
PERL5LIB = $(CURDIR)/debian/dh-cargo/lib
export PATH PERL5LIB

# enable building manpage and shell completion scripts
export BTM_GENERATE = 1

%:
	dh $@ --buildsystem=cargo

%.html: %.md
	cmark-gfm $< > $@

%.txt: %.md
	cmark-gfm --to plaintext $< > $@

execute_after_dh_auto_build: $(DOCS) $(CHANGELOGS)

execute_after_dh_auto_install: $(MANPAGES)

override_dh_installdocs:
	dh_installdocs -- $(DOCS)

override_dh_installchangelogs:
	dh_installchangelogs -- $(CHANGELOGS)

# build manpages
debian/btm.1: debian/%.1: debian/btm/usr/bin/%
	mkdir --parents $(dir $@)
	help2man --section 1 --no-info \
		--name "customizable graphical process/system monitor for the terminal" \
		--output $@ $< \
		|| { $1 --help; false; }
