#!/usr/bin/make -f
export CXX=hipcc
export DEB_BUILD_MAINT_OPTIONS = hardening=-all
export VERBOSE=1
#export AMD_LOG_LEVEL=4

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE=Release \
	-DENABLE_INLINE_ASM=1
# TODO: Starting with ROCm 5.2, -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF
# allows us to work from a regular prefix, leading to a much more
# straightforward installation layout.

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
CMAKE_FLAGS += -DBUILD_TEST=ON
endif

%:
	dh $@ -Scmake

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e \
	; if [ -r /dev/kfd ] \
	; then dh_auto_test --no-parallel -- \
	; else echo "W: /dev/kfd unreadable: no available AMD GPU." \
	;      echo "W: tests skipped." \
	; fi
endif

execute_before_dh_install:
	# Note the rpath field setting may cause reproducible build issues.
	# This should be removed earlier in the toolchain if possible.
	patchelf --remove-rpath ./debian/tmp/usr/rocrand/lib/librocrand.so.1.1
	patchelf --remove-rpath ./debian/tmp/usr/hiprand/lib/libhiprand.so.1.1

override_dh_dwz:
	@echo "W: debug symbols unavailable for the moment[1]."
	@echo "W: [1]: https://github.com/ROCm-Developer-Tools/hipamd/issues/17"
