#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/default.mk
MINOR=$(lastword $(subst ., ,$(DEB_VERSION_UPSTREAM)))
NEXTMINOR=$(shell echo $(MINOR)+1| bc)
NEXTVERSION=$(patsubst %$(MINOR),%$(NEXTMINOR),$(DEB_VERSION_UPSTREAM))

export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-bindnow

# include defs of all DEB_HOST_*/DEB_BUILD_* vars
include /usr/share/dpkg/architecture.mk

ifneq ($(DEB_TARGET_ARCH_BITS),64)
  ENABLEDEPRECATED = --enable-deprecated
endif

# PMIX is now only available on 64-bit systems
PMIX_ARCH:= amd64 arm64 mips64el ppc64el riscv64 s390x alpha ia64 loong64 ppc64
PMIX:=    $(if $(filter $(DEB_TARGET_ARCH), $(PMIX_ARCH)), --with-pmix=/usr/lib/$(DEB_HOST_MULTIARCH)/pmix2, )

%:
	dh $@ --builddirectory --with bash-completion

override_dh_auto_configure:
	dh_auto_configure -- --sysconfdir=/etc/slurm --with-munge --enable-pam --without-rpath --disable-debug --enable-multiple-slurmd $(PMIX) --with-pam_dir=/usr/lib/$(DEB_HOST_MULTIARCH)/security $(ENABLEDEPRECATED) SUCMD=/bin/su SLEEP_CMD=/bin/sleep

override_dh_auto_build:
	dh_auto_build -Dobj-$(DEB_BUILD_GNU_TYPE)/src/plugins/gpu/common
	dh_auto_build -Dobj-$(DEB_BUILD_GNU_TYPE)/src/plugins/gpu/nvml

override_dh_shlibdeps:
	dh_shlibdeps -O--builddirectory -O--parallel -l$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/slurm-wlm/

override_dh_auto_install:
	dh_auto_install -Dobj-$(DEB_BUILD_GNU_TYPE)/src/plugins/gpu/nvml

override_dh_strip:
	dh_strip -pslurm-wlm-nvml-plugin
	strip --verbose --strip-unneeded --remove-section=.comment \
		--remove-section=.note debian/slurm-*-plugin*-dev/usr/lib/*/slurm-wlm/*.a

override_dh_missing:

override_dh_gencontrol:
	dh_gencontrol -- -Vupstream:currentVersion=$(DEB_VERSION_UPSTREAM) -Vupstream:nextVersion=$(NEXTVERSION)
