#!/usr/bin/make -f

# that will fill DEB_VERSION and DEB_SOURCE variables
include /usr/share/dpkg/pkg-info.mk
export LIB_VERSION := $(shell echo $(DEB_VERSION) | cut -d'-' -f1)

# temporary build path (see http://golang.org/doc/code.html#GOPATH)
export GOPATH := $(CURDIR)/_build
export GOCACHE := $(CURDIR)/_cache
export GO111MODULE := on

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

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--warnings=6

override_dh_auto_build:
	dh_auto_build -v -- \
		-buildmode=pie \
		-mod=vendor \
		-modcacherw \
		-ldflags="-extldflags=-Wl,-z,lazy"

	help2man --name="nvidia-mig-parted" --version-string="$(LIB_VERSION)" ./_build/bin/nvidia-mig-parted > nvidia-mig-parted.1
	help2man --name="nvidia-mig-manager" --version-string="$(LIB_VERSION)" ./_build/bin/nvidia-mig-manager > nvidia-mig-manager.1

override_dh_auto_install:
	# Install binaries only, skip source installation
	dh_auto_install -- --no-source

override_dh_fixperms:
	dh_fixperms
	chmod +x debian/nvidia-mig-manager/etc/nvidia-mig-manager/hooks.sh
	chmod +x debian/nvidia-mig-manager/usr/libexec/nvidia-mig-manager/service.sh
	chmod +x debian/nvidia-mig-manager/usr/share/nvidia-mig-manager/utils.sh

override_dh_installsystemd:
	# Do not start nvidia-mig-manager.service when installing this package
	# Upstream's reasoning from https://github.com/NVIDIA/mig-parted/commit/47c0e738a0695af14f91be18a377d86ab8861f97
	# > We do not want to start the service immediately on after an install because
	# > the user will not have had the chance to configure their system/settings.
	# The fact that it might trigger a one-time reboot is also a very valid reason.
	# Issue open https://github.com/NVIDIA/mig-parted/issues/418
	dh_installsystemd --no-start

override_dh_dwz:
