#!/usr/bin/make -f

export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/architecture.mk
BUILDDIR=debian/build

# The magic debhelper  rule
%:
	dh $@ --builddirectory=$(BUILDDIR) --buildsystem=cmake

execute_before_dh_auto_clean:
	rm -fr $(BUILDDIR) version

# -DWITH_XEUS=yes for Jupyter kernel support
# not currently compiling ?

# _Unwind_GetIP missing on armhf
UNWIND:= $(if $(filter $(DEB_TARGET_ARCH), armhf hurd-i386 sparc64 powerpc alpha hppa ),no,yes  )

override_dh_auto_configure:
	echo $(DEB_VERSION_UPSTREAM) > version
	./build0.sh
	mkdir -p $(BUILDDIR)
	dh_auto_configure --  \
		-DCMAKE_BUILD_TYPE=Debug \
		-DWITH_UNWIND=$(UNWIND) \
		-DWITH_RUNTIME_STACKTRACE=$(UNWIND) \
		-DWITH_STACKTRACE=$(UNWIND) \
		-DWITH_LLVM=$(UNWIND) \
		-DWITH_DWARFDUMP=yes  \
		-DWITH_JSON=yes \
		-DWITH_LSP=yes \
		-DWITH_FMT=yes \
		-DWITH_BFD=yes	\
		-DLLVM_DIR=/usr/lib/llvm-21/cmake \
		-DWITH_KOKKOS=yes \
		-DCMAKE_Fortran_MODULE_DIRECTORY=/usr/lib/$(DEB_HOST_MULTIARCH)/fortran/lfortran-mod-$(DEB_VERSION_UPSTREAM)


override_dh_gencontrol:
	dh_gencontrol -- -VBuilt-Using="`dpkg-query -f'$${source:Package} (= $${source:Version}), ' -W binutils-dev libiberty-dev`"

override_dh_auto_test:
	@echo Bypass tests on this build

override_dh_dwz:
	@echo "DWZ fails on .debug_attr sections in some archs; don't use"
