#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

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

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	if echo "$(DEB_VERSION)" | grep -q '~git' ; then \
		_git_commit=$$(echo "$(DEB_VERSION)" | cut -d'+' -f2 | cut -d'-' -f1) ; \
	else \
		_git_commit="unknown" ; \
	fi ; \
	dh_auto_configure --parallel -- \
		-GNinja					\
		-DCMAKE_BUILD_TYPE=RelWithDebInfo	\
		-DENABLE_FFMPEG=ON			\
		-DENABLE_MINIAUDIO=ON			\
		-DUSE_ICU=ON				\
		-DENABLE_QT5=ON				\
		-DUSE_WAYLAND=ON			\
		-DENABLE_SDL=ON				\
		-DENABLE_SPICE=ON			\
		-DSPICE_BUILD_SHARED_LIBRARY=OFF	\
		-DENABLE_TESTS=OFF			\
		-DENABLE_TOOLS=ON			\
		-DENABLE_LTO=ON				\
		-DENABLE_LIBAVIF=ON			\
		-DENABLE_WIN=OFF			\
		-DGIT_COMMIT="$$_git_commit"


override_dh_auto_build:
	ninja -v -C obj-$(DEB_HOST_GNU_TYPE)


#override_dh_auto_test:
#	cd obj-$(DEB_HOST_GNU_TYPE) && ctest --output-on-failure


override_dh_install:
	cp -p obj-$(DEB_HOST_GNU_TYPE)/src/tools/spice2xyzv/spice2xyzv debian/tmp/usr/bin/
	find debian/tmp/usr/bin/ -type f ! -name *.pl -exec chrpath --delete {} ';'
	chrpath --delete debian/tmp/usr/lib/*/libcelestia.so.*
	dh_install
	dh_missing --fail-missing
	mv debian/celestia-common/usr/share/celestia/celestia.cfg \
	   debian/celestia-common/etc/celestia.cfg
	ln -s /etc/celestia.cfg debian/celestia-common/usr/share/celestia/
	rm debian/celestia-common/usr/share/celestia/fonts/*
	ln -s /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf \
	      debian/celestia-common/usr/share/celestia/fonts/
	ln -s /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf \
	      debian/celestia-common/usr/share/celestia/fonts/


override_dh_auto_install:
	env DESTDIR=$(shell pwd)/debian/tmp ninja -v -C obj-$(DEB_HOST_GNU_TYPE) install

# No dbgsym packages:
override_dh_strip:
	@echo "NO--THANKS ANYWAY--but not building dbgsym packages for MX Linux"
	dh_strip --no-automatic-dbgsym
