#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

GO_BUILD_DIR := $(CURDIR)/_build/go
REPO := github.com/kata-containers/kata-containers
RUNTIME_BUILD_DIR := $(GO_BUILD_DIR)/src/$(REPO)/src/runtime
CONF := DESTDIR=$(CURDIR)/debian/kata-containers \
	PREFIX=/usr \
	PKGDATADIR=/var/cache/kata-containers \
	DEFAULTSDIR=/usr/share \
	DEFVIRTIOFSDAEMON=/usr/lib/qemu/virtiofsd \
	DEFSANDBOXCGROUPONLY=true \
	SKIP_GO_VERSION_CHECK=y \
	V=1

export DH_GOLANG_EXCLUDES := virtcontainers/hook/mock
export DH_GOLANG_INSTALL_EXTRA := \
	$(wildcard src/runtime/arch/*.mk) \
	$(wildcard src/runtime/config/*.toml.in) \
	VERSION \
	src/runtime/Makefile \
	src/runtime/VERSION \
	src/runtime/data/completions/bash/kata-runtime \
	src/runtime/data/kata-collect-data.sh.in \
	src/runtime/go.mod \
	src/runtime/golang.mk \
	src/runtime/pkg/katautils/config-settings.go.in

%:
	dh $@ --builddirectory=_build

override_dh_auto_configure:
	DH_GOPKG=$(REPO) dh_auto_configure --buildsystem=golang --builddirectory=$(GO_BUILD_DIR)

override_dh_auto_build:
	$(MAKE) -C $(RUNTIME_BUILD_DIR) $(CONF) \
		pkg/katautils/config-settings.go \
		config/configuration-qemu.toml \
		data/kata-collect-data.sh
	dh_auto_build --buildsystem=golang --builddirectory=$(GO_BUILD_DIR)

override_dh_auto_install:
	dh_auto_install --buildsystem=golang --builddirectory=$(GO_BUILD_DIR) -- --no-source
	$(MAKE) -C $(RUNTIME_BUILD_DIR) $(CONF) \
		install-scripts install-completions install-configs

override_dh_auto_test:
	-dh_auto_test --buildsystem=golang --builddirectory=$(GO_BUILD_DIR)

execute_before_dh_gencontrol:
	dh_golang --builddirectory=$(GO_BUILD_DIR)
