#!/usr/bin/make -f

%:
	dh $@

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

include /usr/share/dpkg/pkg-info.mk
export GOFLAGS=-trimpath

override_dh_auto_build:
	rm -f $(CURDIR)/go.mod
	export GOCACHE=$(CURDIR)/.cache/go-build && \
	export GO111MODULE=on && \
	go mod init abbtr && \
	go mod tidy && \
	go build -trimpath -buildmode=pie -ldflags="-buildid= -X main.version=$(DEB_VERSION)" -o abbtr

override_dh_auto_install:
	mkdir -p debian/abbtr/usr/bin
	install -m 0755 abbtr debian/abbtr/usr/bin/abbtr

override_dh_auto_clean:
	dh_auto_clean
	rm -f abbtr
	rm -rf $(CURDIR)/.cache/go-build
	rm -f $(CURDIR)/go.mod

override_dh_usrlocal:
	true

override_dh_dwz:
	true

override_dh_strip:
	dh_strip --no-automatic-dbgsym

override_dh_gencontrol:
	dh_gencontrol -- -VFStdeps=golang-go -Vmisc:Built-Using="" -Vmisc:Static-Built-Using=""

override_dh_auto_test:
	@echo "DEB_BUILD_OPTIONS: $(DEB_BUILD_OPTIONS)"
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	export GOCACHE=$(CURDIR)/.cache/go-build && \
	cd $(CURDIR) && go test -vet=off -v ./...
endif

override_dh_installtests:
	rsync -av --exclude='debian' $(CURDIR)/ $(CURDIR)/debian/abbtr-tests
