#!/usr/bin/make -f

export PYBUILD_NAME = openshot-qt
export PYBUILD_DESTDIR = debian/openshot-qt
PKGDIR = $(CURDIR)/debian/openshot-qt
export PYBUILD_TEST_CUSTOM = 1
export QT_QPA_PLATFORM = offscreen
export OPENSHOT_QT_API = pyqt6
export PYBUILD_TEST_ARGS = cd openshot_qt && PYTHONPATH={build_dir}/openshot_qt:{build_dir} timeout 3600 $(CURDIR)/debian/run-unit-tests {interpreter}

%:
	dh $@ --buildsystem=pybuild

# Binary test fixture of the CVE-2026-134704 patch (quilt cannot carry it)
LEGACY_FIXTURE = src/tests/fixtures/legacy/project-v1-protocol2.osp

execute_before_dh_auto_build:
	cp debian/tests/legacy/project-v1-protocol2.osp $(LEGACY_FIXTURE)

execute_after_dh_auto_build:
	PYTHONPATH=. http_proxy='127.0.0.1:9' python3 -m sphinx -N -b html -d build/doctrees doc build/html
	PYTHONPATH=. http_proxy='127.0.0.1:9' python3 -m sphinx -N -b man  -d build/doctrees doc build/man

execute_after_dh_auto_install:
	# Extra license file must not be removed, otherwise crash will happen
	# Removal line patched out. See https://bugs.debian.org/908320
	#rm $(PKGDIR)/usr/lib/python3*/dist-packages/openshot_qt/resources/license.txt
	chmod -x \
		$(PKGDIR)/usr/lib/python3*/dist-packages/openshot_qt/themes/base.py \
		$(PKGDIR)/usr/lib/python3*/dist-packages/openshot_qt/presets/format_mp4_librav1e.xml \
		$(PKGDIR)/usr/lib/python3*/dist-packages/openshot_qt/presets/format_mp4_libsvtav1.xml

execute_after_dh_auto_clean:
	rm -rf build
	rm -f $(LEGACY_FIXTURE)
