#! /usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed
# LFS support
export DEB_CPPFLAGS_MAINT_APPEND=$(shell getconf LFS_CFLAGS)

DEB_HOST_MULTIARCH=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --parallel --buildsystem=cmake \
		--sourcedirectory=source \
		--builddirectory=x265-8bit

override_dh_auto_clean:
	dh_auto_clean --builddirectory=x265-10bit
	dh_auto_clean
	rm -rf doc/reST/build

override_dh_auto_configure:
	dh_auto_configure --builddirectory=x265-10bit -- \
		-DENABLE_PIC=ON \
		-DHIGH_BIT_DEPTH=ON \
		-DENABLE_CLI=OFF \
		-DLIB_INSTALL_DIR=lib/$(DEB_HOST_MULTIARCH)/x265-10bit
	dh_auto_configure -- \
		-DENABLE_PIC=ON \
		-DLIB_INSTALL_DIR=lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_build-arch:
	dh_auto_build --builddirectory=x265-10bit
	dh_auto_build

override_dh_auto_install-arch:
	dh_auto_install --builddirectory=x265-10bit
	dh_auto_install
	sed -e 's,@DEB_HOST_MULTIARCH@,$(DEB_HOST_MULTIARCH),' \
		debian/x265-10bit.in > debian/tmp/usr/bin/x265-10bit
	chmod a+x debian/tmp/usr/bin/x265-10bit

override_dh_auto_build-indep:
	$(MAKE) -C doc/reST html

override_dh_installdocs-indep:
	dh_installdocs
	dh_sphinxdoc

override_dh_strip:
	dh_strip -plibx265-43 --dbg-package=libx265-43-dbg
	dh_strip --remaining-packages
