#!/usr/bin/make -f

DEB_HOST_MULTIARCH?=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_BUILD_MAINT_OPTIONS=reproducible=+fixfilepath

export DEB_BUILD_MAINT_OPTIONS=hardening=+all reproducible=+fixfilepath
export PYBUILD_NAME=notcurses
export PYBUILD_DIR=cffi
export PYBUILD_DESTDIR=debian/python3-notcurses

CFLAGS += -ffile-prefix-map=$(CURDIR)=.

# we supply a build directory explicitly so that we can reference it later
BDIR=$(CURDIR)/build

%:
	dh $@ --buildsystem=cmake -B $(BDIR)

# we ought be able to eliminate DCMAKE_BUILD_RPATH_USE_ORIGIN=ON
# with debhelper 14
override_dh_auto_configure:
	dh_auto_configure -- \
		-DBUILD_FFI_LIBRARY=off \
		-DBUILD_TESTING=on \
		-DDFSG_BUILD=on \
		-DUSE_GPM=on \
		-DUSE_POC=off \
		-DUSE_QRCODEGEN=on \
		-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON

override_dh_auto_build:
	dh_auto_build
	CFLAGS="$(CFLAGS) -I$(CURDIR)/include" \
		LDFLAGS="$(LDFLAGS) -L$(BDIR)" \
		pybuild --build

override_dh_auto_install:
	dh_auto_install -B $(BDIR)
	pybuild --install

# debhelper 13+ handles nocheck in DEB_BUILD_OPTIONS for us
override_dh_auto_test:
	ctest --test-dir $(BDIR) --output-on-failure
