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

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

export DEB_CXXFLAGS_MAINT_APPEND = -Wno-uninitialized 
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)

include /usr/share/mpi-default-dev/debian_defaults
MPI:=$(LIBDIR)/$(ARCH_DEFAULT_MPI_IMPL)

export HIPCXX=clang++-21
export HIPCC=clang-21

export MPICC=mpicc


ARCH_HIP:= amd64 arm64 ppc64el
ROCM:= $(if $(filter $(DEB_TARGET_ARCH), $(ARCH_HIP)),--with-rocm=/usr,)
HIP:= $(if $(filter $(DEB_TARGET_ARCH), $(ARCH_HIP)),--with-hip=/usr,)

%:
	dh $@ 

# No ibverbs support available on kFreeBSD, Hurd
NO_VERBS_ARCH:= hurd-amd64 s390x
NO_NUMA_ARCH:= 

VERBS:=   $(if $(filter $(DEB_TARGET_ARCH), $(NO_VERBS_ARCH)), , --with-verbs )
NUMA:=   $(if $(filter $(DEB_TARGET_ARCH), $(NO_NUMA_ARCH)),  --disable-numa , )

override_dh_autoreconf:
	./autogen.sh

override_dh_auto_configure:
	CPPFLAGS="-I/usr/include/hsa -I/usr/include/hip" dh_auto_configure --  \
		--enable-mt \
		--with-mpi=/usr \
		$(VERBS) \
		$(NUMA) \
		$(ROCM) \
		$(HIP) \
		--enable-backtrace-detail \
		--enable-logging \


override_dh_auto_clean:
	dh_auto_clean
	find  . -type l -delete
	rm -f config.log

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

override_dh_auto_install:
	dh_auto_install
	# chrpath -d debian/tmp/usr/lib/*/lib*.so.0*

override_dh_dwz:
	@echo "pass; dwz currently breaks"
