#!/usr/bin/make -f

export DH_GOLANG_BUILDPKG := github.com/GoogleCloudPlatform/guest-agent/google_guest_agent github.com/GoogleCloudPlatform/guest-agent/google_metadata_script_runner

# use Go 1.18 as golang-any defaults to Go 1.13, which
# doesn't have new features needed by this package.
export PATH := /usr/lib/go-1.18/bin:$(PATH)

# temporary build path; needed by newer Go.
OUR_GOPATH := $(CURDIR)/.gopath
export GOPATH := $(OUR_GOPATH)
export GOCACHE := $(CURDIR)/.gocache

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

override_dh_auto_configure:
	cp -r debian/extra/vendor ./
	dh_auto_configure

override_dh_auto_build:
	dh_auto_build -O--buildsystem=golang -- -ldflags="-s -w -X main.version=$(shell dpkg-parsechangelog -S Version)"

override_dh_auto_install:
	dh_auto_install -- --no-source

override_dh_installsystemd:
	dh_installsystemd google-guest-agent.service
	dh_installsystemd --no-start --no-restart-after-upgrade google-startup-scripts.service google-shutdown-scripts.service

override_dh_clean:
	dh_clean vendor/
