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

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE=Release \
	-DROCM_SYMLINK_LIBS=OFF \
	-DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF \
	-DENABLE_INLINE_ASM=1

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/lib/$(DEB_HOST_MULTIARCH)/librocrand.so.1.1
	patchelf --remove-rpath ./debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libhiprand.so.1.1
