#!/usr/bin/make -f
#export DH_VERBOSE = 1

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

CLANG_V=19
V=$(shell dpkg-parsechangelog -S Version | sed 's/-.*$$//')

%:
	dh $@ --with python3

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_PREFIX_PATH=/usr/lib/llvm-$(CLANG_V) \
		-DCLANG_FORMAT=clang-format-$(CLANG_V) \
		-DCMAKE_INSTALL_LIBEXECDIR=lib

override_dh_auto_build:
	dh_auto_build

override_dh_auto_test:
	-dh_auto_test

override_dh_auto_install:
	dh_auto_install

ifeq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
	if which help2man >/dev/null 2>&1; then \
	  DESTDIR=$(CURDIR)/debian/cvise help2man --name='super-parallel Python port of the C-Reduce project' \
	    --version-string=$(V) \
	    --no-info \
	    debian/cvise/usr/bin/cvise > debian/cvise.1; \
	fi
endif
	mkdir -p debian/cvise/usr/share/man/man1
	cp debian/cvise.1 debian/cvise/usr/share/man/man1/cvise.1

override_dh_dwz:
ifeq (,$(filter $(DEB_HOST_ARCH), mipsel))
	dh_dwz
endif

override_dh_shlibdeps:
	chrpath -d debian/cvise/usr/lib/cvise/clang_delta
	dh_shlibdeps

override_dh_auto_clean:
	find -name __pycache__ | xargs -r rm -rf
	dh_auto_clean
