#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

%:
	dh $@ --buildsystem=cmake+ninja --builddirectory=build

override_dh_auto_configure:
	cp -a $(CURDIR)/isotovideo $(CURDIR)/isotovideo.orig
	sed -i 's/my $$thisversion =.*/my $$thisversion = "$(DEB_VERSION)";/' $(CURDIR)/isotovideo
	# Following opensuse .spec : don't require qemu and exclude known flaky tests
	cd t && rm -f 07-commands.t 13-osutils.t 14-isotovideo.t 18-qemu-options.t 18-backend-qemu.t 99-full-stack.t
	dh_auto_configure -- -DOS_AUTOINST_DOC_DIR=/usr/share/doc/$(DEB_SOURCE) \
		-DSYSTEMD_SERVICE_DIR=/lib/systemd/system -DCMAKE_BUILD_TYPE=RelWithDebInfo

override_dh_auto_install:
	dh_auto_install
	find $(CURDIR)/debian/os-autoinst/usr/lib/ -name "*.packlist" -delete

override_dh_auto_test:
	cd build && CI=1 ninja -v check-pkg-build

override_dh_auto_clean:
	cd $(CURDIR) && rm -f snd2png/snd2png ppmclibs/blib/arch/auto/tinycv/tinycv.so \
	       	ppmclibs/blib/lib/tinycv.pm debugviewer/debugviewer videoencoder \
	       	doc/backend_vars.asciidoc.newvars
	if [ -f $(CURDIR)/isotovideo.orig ]; then mv $(CURDIR)/isotovideo.orig $(CURDIR)/isotovideo; fi
	dh_auto_clean
