#!/usr/bin/make -f

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

# Extra files required for build
DH_GOLANG_INSTALL_EXTRA += Makefile
DH_GOLANG_INSTALL_EXTRA += config
DH_GOLANG_INSTALL_EXTRA += contrib/aerc.desktop
DH_GOLANG_INSTALL_EXTRA += doc
DH_GOLANG_INSTALL_EXTRA += filters
DH_GOLANG_INSTALL_EXTRA += stylesets
DH_GOLANG_INSTALL_EXTRA += templates
export DH_GOLANG_INSTALL_EXTRA

# Installation paths
export DESTDIR=$(CURDIR)/debian/aerc
export PREFIX=/usr

# Go options
export GO111MODULE=off
export GOPROXY=off
export GOCACHE=$(CURDIR)/_build/go-build
export GOPATH=$(CURDIR)/_build
export GOFLAGS=-tags=notmuch -buildmode=pie

# Hardening
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

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

override_dh_auto_build:
	$(MAKE) -C _build/src/git.sr.ht/~rjarry/aerc VERSION=$(DEB_VERSION_UPSTREAM)

override_dh_auto_test:
	mkdir -p debian/test-gnupg
	chmod og-rx debian/test-gnupg
	GNUPGHOME=${CURDIR}/debian/test-gnupg dh_auto_test
	rm -rf debian/test-gnupg

override_dh_auto_install:
	$(MAKE) -C_build/src/git.sr.ht/~rjarry/aerc install VERSION=$(DEB_VERSION_UPSTREAM)
	find $(DESTDIR) -name show-ics-details.py -delete
