#!/usr/bin/make -f

export PATH := /tmp/go/bin:$(PATH)
export SHELL := env PATH=$(PATH) /bin/bash

export DH_OPTIONS
export DH_GOPKG := github.com/GoogleCloudPlatform/osconfig
export DH_GOLANG_EXCLUDES := e2e_tests/
export CGO_ENABLED := 0
export GO111MODULE := on
export GOPATH := /usr/share/gocode
export DH_GOLANG_BUILDPKG := github.com/GoogleCloudPlatform/osconfig github.com/GoogleCloudPlatform/osconfig/agentconfig github.com/GoogleCloudPlatform/osconfig/agentendpoint github.com/GoogleCloudPlatform/osconfig/attributes github.com/GoogleCloudPlatform/osconfig/clog github.com/GoogleCloudPlatform/osconfig/external github.com/GoogleCloudPlatform/osconfig/inventory github.com/GoogleCloudPlatform/osconfig/osinfo github.com/GoogleCloudPlatform/osconfig/ospatch github.com/GoogleCloudPlatform/osconfig/packages github.com/GoogleCloudPlatform/osconfig/policies github.com/GoogleCloudPlatform/osconfig/policies/recipes github.com/GoogleCloudPlatform/osconfig/retryutil github.com/GoogleCloudPlatform/osconfig/tasker github.com/GoogleCloudPlatform/osconfig/util github.com/GoogleCloudPlatform/osconfig/util/mocks
export GOPROXY := https://proxy.golang.org
export GOCACHE := /tmp/.cache

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

override_dh_auto_install:
	# Binary-only package.
	dh_auto_install -- --no-source
	mv debian/google-osconfig-agent/usr/bin/osconfig debian/google-osconfig-agent/usr/bin/google_osconfig_agent
	install -d debian/google-osconfig-agent/var/lib/google_osconfig_agent
	install -d debian/google-osconfig-agent/lib/systemd/system
	install -p -m 0644 *.service debian/google-osconfig-agent/lib/systemd/system/

override_dh_golang:
	# We don't use any packaged dependencies, so skip dh_golang step.

override_dh_auto_test:
	# Skip tests as they are already setup as part of the commit process.

override_dh_auto_build:
	dh_auto_build -O--buildsystem=golang -- -ldflags="-s -w -X main.version=$(VERSION)-$(RELEASE)" -mod=readonly

override_dh_installinit:

override_dh_systemd_start:
	dh_systemd_start --no-restart-after-upgrade --no-restart-on-upgrade
