#!/usr/bin/make -f

# resolve DEB_VERSION_UPSTREAM
include /usr/share/dpkg/pkg-info.mk

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
endif

# generate manpage with help2man from -h option
_mkman = \
 help2man $(if $3,--name "$(strip $3)") --no-info --help-option -h --no-discard-stderr --version-string $(DEB_VERSION_UPSTREAM) --output $2 $1 \
 || [ $? -eq 254 ] || { $1 -h; false; }

override_dh_auto_build: $(DOCS)
	dh_auto_build -- GDB= OPTS="$(CFLAGS)"
	$(call _mkman, ./whip-client, debian/whip-client.1, \
		simple GStreamer-based WHIP client)

override_dh_installdocs:
	dh_installdocs --all -- $(DOCS)

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

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

%:
	dh $@
