#!/usr/bin/make -f

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

# detect if build targets experimental suite (or is a draft)
DEB_SUITE_EXP = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

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

ESLINT = eslint --format tap
MOCHA = mocha --reporter tap

override_dh_auto_build: $(DOCS)
	node scripts/generate-index.js

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
#	$(ESLINT) lib tests/lib index.js $(if $(DEB_SUITE_EXP),|| true)
	$(MOCHA) tests/lib/**/*.js $(if $(DEB_SUITE_EXP),|| true)
endif

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

dh_clean:
	dh_clean -- $(DOCS)

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

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

%:
	dh $@
