#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS := hardening=+all

%:
	dh $@

# Debhelper dropped the autoconf/pybuild clean helpers in compat 12, do the
# upstream clean ourselves.
override_dh_auto_clean:
	dh_clean
	if [ -f Makefile ]; then make distclean; fi
	rm -rf autom4te.cache aclocal.m4 configure config.log config.status

# VapourSynth uses an autotools build system; autogen.sh is a thin wrapper
# around autoreconf, which we run before the configure step.
override_dh_auto_configure:
	./autogen.sh
	./configure --prefix=/usr \
		--libdir=/usr/lib/x86_64-linux-gnu \
		--with-plugindir=/usr/lib/x86_64-linux-gnu/vapoursynth \
		CYTHON=/usr/bin/cython3 \
		docdir=/usr/share/doc/vapoursynth

override_dh_auto_build:
	dh_auto_build

override_dh_auto_install:
	dh_auto_install

	# Drop static archives and libtool files, we only ship shared objects.
	rm -f debian/tmp/usr/lib/*/lib*.a debian/tmp/usr/lib/*/*.la

	# Relocate the CPython extension module into the Debian python3 module
	# location (the module is built for the current interpreter ABI).
	mkdir -p debian/python3-vapoursynth/usr/lib/python3/dist-packages
	if [ -d debian/tmp/usr/lib/python3*/site-packages ]; then \
		mv debian/tmp/usr/lib/python3*/site-packages/vapoursynth.so \
		   debian/python3-vapoursynth/usr/lib/python3/dist-packages/; \
		rm -f debian/tmp/usr/lib/python3*/site-packages/*.la \
		      debian/tmp/usr/lib/python3*/site-packages/*.a; \
	fi

	# Alias for newer consumers that dlopen libvsscript.so.
	mkdir -p debian/libvapoursynth-script0/usr/lib/x86_64-linux-gnu
	ln -sf libvapoursynth-script.so.0 \
		debian/libvapoursynth-script0/usr/lib/x86_64-linux-gnu/libvsscript.so

override_dh_missing:
	dh_missing --fail-missing
