#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

BUILDPKG   := github.com/elves/elvish/buildinfo
BUILDFLAGS := -ldflags\
  "-X $(BUILDPKG).Version=$(DEB_VERSION)"

export DH_GOLANG_EXCLUDES := website

DATE := $(shell date -u --date=@$(SOURCE_DATE_EPOCH) "+%b %d, %Y")
VER := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/+ds[0-9]*//')
PANDOC_ARG := -s -f gfm -t man -V section:7 -V header:"Miscellaneous Information Manual" -V footer:"Elvish $(VER)" -M date:"$(DATE)"

%:
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_configure:
	# e2e_test.go needs a working terminal, it fails in my sbuild env.
	# https://github.com/elves/elvish/issues/708
	-rm -f edit/edcore/e2e_test.go
	dh_auto_configure

override_dh_auto_build:
	for file in builtin bundled edit epm language philosophy re; do \
	  pandoc $(PANDOC_ARG) -M title:"elvish-$$file" -o debian/elvish-$$file.7 website/src/ref/$$file.md; \
	done
	dh_auto_build -- $(BUILDFLAGS)

override_dh_auto_install:
	dh_auto_install -- --no-source
