#!/usr/bin/make -f
# -*- makefile -*-
DH_VERBOSE=1

# 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)
export REVISION := $(DEB_VERSION)

# Extract nvidia-modprobe version from mk file and watch file to verify that they are aligned.
# This is a build-time check to verify that the nvidia-modprobe version in the upstream tarball is right
MODPROBE_MK_VERSION := $(shell grep '^VERSION' mk/nvidia-modprobe.mk | head -1 | awk '{print $$3}')
MODPROBE_WATCH_VERSION := $(shell grep 'Version-Constraint:' debian/watch | awk '{print $$2}')

# Verify versions match
ifneq ($(MODPROBE_MK_VERSION),$(MODPROBE_WATCH_VERSION))
$(error nvidia-modprobe version mismatch: mk/nvidia-modprobe.mk has $(MODPROBE_MK_VERSION) but debian/watch has $(MODPROBE_WATCH_VERSION))
endif

%:
	dh $@ --buildsystem=makefile

override_dh_auto_install:
	dh_auto_install -- \
		prefix=/usr \
		libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
		includedir=/usr/include/libnvidia-container

override_dh_auto_build:
	dh_auto_build

	# running nvidia-container-cli in a non-installed state requires to load the library first
	ln -sf libnvidia-container.so.$(LIB_VERSION) libnvidia-container.so.1
	LD_LIBRARY_PATH=$(CURDIR) help2man --no-discard-stderr --name="nvidia-container-cli" --version-string="$(LIB_VERSION)" ./nvidia-container-cli > nvidia-container-cli.1

override_dh_dwz:
