#!/usr/bin/make -f

DOMAIN     = github.com
ORG        = kata-containers
PROJECT    = ksm-throttler
IMPORTNAME = $(DOMAIN)/$(ORG)/$(PROJECT)
GO_VERSION = @GO_VERSION@

export DH_VERBOSE=1
export DH_GOPKG:=$(DOMAIN)/$(ORG)/$(PROJECT)
export DEB_BUILD_OPTIONS=nocheck
export GOPATH=/usr/src/packages/BUILD/go
export GOROOT=/tmp/local/go
export PATH:=/tmp/local/go/bin:$(PATH)
export DH_OPTIONS

%:
	dh $@

override_dh_auto_build:
	mkdir -p /tmp/local/
	mkdir -p /usr/src/packages/BUILD/go/src/$(DOMAIN)/$(ORG)
	tar xzf /usr/src/packages/SOURCES/go$(GO_VERSION).linux-@GO_ARCH@.tar.gz -C /tmp/local
	ln -s /usr/src/packages/BUILD /usr/src/packages/BUILD/go/src/$(IMPORTNAME)
	cd $(GOPATH)/src/$(IMPORTNAME); \
	make \
		COMMIT=@HASH@ \
		TARGET=kata-ksm-throttler

override_dh_auto_install:
	mkdir -p debian/$(PROJECT)
	cd $(GOPATH)/src/$(IMPORTNAME); \
	make install \
		COMMIT=@HASH@ \
		DESTDIR=$(shell pwd)/debian/kata-ksm-throttler \
		TARGET=kata-ksm-throttler

