#!/usr/bin/make -f
#export DH_VERBOSE = 1

export GOCACHE=$(shell mktemp -d /tmp/gocache-XXXX)
export GOFLAGS=-ldflags=-X=github.com/ubuntu/zsys/internal/config.Version=$(shell dpkg-parsechangelog -S Version) --mod=vendor

# Tell go generate to only install on-the-fly assets
export ZSYS_GENERATE_ONLY_INSTALL_SHARE_PREFIX=$(CURDIR)/debian/zsys/usr/share

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

override_dh_auto_clean:
	dh_auto_clean
	# create the vendor directory when building the source package
	[ -d vendor/ ] || go mod vendor

override_dh_auto_install:
	dh_auto_install -- --no-source
	# install in /sbin
	mv debian/zsys/usr/bin/ debian/zsys/sbin
	rmdir debian/zsys/usr/
	# create zsysctl command
	ln -s zsysd debian/zsys/sbin/zsysctl
	# run go generate for only installed generated assets
	go generate $(GOFLAGS) ./...
