#!/usr/bin/make -f
#export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# For DEB_VERSION
include /usr/share/dpkg/pkg-info.mk


# GGML_NATIVE:ON corresponds to -march=native
CMAKE_OPTS  = -DGGML_NATIVE=OFF \
              -DCMAKE_BUILD_TYPE=RelWithDebInfo \
              -DGGML_BUILD_NUMBER=$(DEB_VERSION) \
              -DGGML_BUILD_TESTS=OFF \
              -DGGML_BUILD_EXAMPLES=OFF \
              -DGGML_INSTALL_TESTS=OFF \
              -DGGML_BACKEND_DL=ON \
              -DGGML_BACKEND_DIR=/usr/lib/${DEB_HOST_MULTIARCH}/ggml/backends0

## HIP ##
# These are the targets supported by AMD's ROCm 7.14 as of 2026-07-19, except
# for gfx1250 which is not yet supported by ggml
ROCM7.14_TARGETS = gfx1010 \
		       gfx1011 \
		       gfx1012 \
		       gfx1030 \
		       gfx1031 \
		       gfx1032 \
		       gfx1033 \
		       gfx1034 \
		       gfx1035 \
		       gfx1036 \
		       gfx1100 \
		       gfx1101 \
		       gfx1102 \
		       gfx1103 \
		       gfx1150 \
		       gfx1151 \
		       gfx1152 \
		       gfx1200 \
		       gfx1201
ROCM7.14_DEPENDS = $(shell echo $(foreach i,$(ROCM7.14_TARGETS),amdrocm-blas7.14-$(i) \|) | sed 's/ |$$//')


CMAKE_OPTS += -DGGML_CPU=OFF \
              -DGGML_HIP=ON \
              -DCMAKE_HIP_COMPILER=/opt/rocm/core-7.14/bin/amdclang++ \
              -DCMAKE_PREFIX_PATH=/opt/rocm/core-7.14/lib/cmake \
	      -DCMAKE_INSTALL_RPATH=/opt/rocm/core-7.14/lib \
	      -DGPU_TARGETS="$(shell echo $(ROCM7.14_TARGETS) | tr ' ' ';')"

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_OPTS)

override_dh_auto_install:
	# We don't want dh's single-binary mode to install everything directly
	# to the package, as we only want a single file
	dh_auto_install --destdir=debian/tmp

# No tests for now, needs GPU
override_dh_auto_test:
	:

# dwz doesn't fully support DWARF-5 yet, see #1016936
# The HIP build produces DWARF-5 stuff
override_dh_dwz:
	:

override_dh_makeshlibs:
	# Libraries are private
	dh_makeshlibs --no-scripts

override_dh_gencontrol:
	dh_gencontrol -- -Vvendor-rocm:arch-Depends="$(ROCM7.14_DEPENDS)"
