#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export DH_GOLANG_EXCLUDES := example test
export DH_GOLANG_INSTALL_ALL := 1

GOFUSE_VERSION_UPSTREAM=$(shell dpkg-query -f='$${source:Upstream-Version}' -W golang-github-hanwen-go-fuse-dev)
CHANGELOG_TIMESTAMP=$(shell date -u --rfc-3339=date -d@$(SOURCE_DATE_EPOCH))
DEB_LDFLAGS="-X main.GitVersion=$(DEB_VERSION_UPSTREAM) -X main.GitVersionFuse=$(GOFUSE_VERSION_UPSTREAM) -X main.BuildDate=$(CHANGELOG_TIMESTAMP)"

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

override_dh_auto_build:
	env > /tmp/env
	env
	dh_auto_build -- -ldflags $(DEB_LDFLAGS)
	cp -r internal/* obj*/src/github.com/rfjakob/gocryptfs/internal/
	cp -r tests/* obj*/src/github.com/rfjakob/gocryptfs/tests
	cp obj*/bin/gocryptfs obj*/src/github.com/rfjakob/gocryptfs/
	pandoc Documentation/MANPAGE.md -s -t man -o debian/gocryptfs.1
	pandoc Documentation/MANPAGE-XRAY.md -s -t man -o debian/gocryptfs-xray.1
	pandoc Documentation/MANPAGE-STATFS.md -s -t man -o debian/statfs.1

override_dh_auto_clean:
	rm -f debian/gocryptfs.1
	rm -f debian/gocryptfs-xray.1
	rm -f debian/statfs.1
	dh_auto_clean

override_dh_auto_install:
	dh_auto_install
	rm -rf debian/gocryptfs/usr/share/gocode
