#!/usr/bin/make -f

export PYBUILD_NAME = pygame

# Replace embedded font with system copy
export PYBUILD_AFTER_INSTALL = ln -sf /usr/share/fonts/truetype/freefont/FreeSansBold.ttf \
                                      {destdir}/{install_dir}/pygame/freesansbold.ttf

# setup.py only installs data during install, not build
export PYBUILD_BEFORE_TEST = cp {dir}/lib/pygame_icon.bmp {build_dir}/pygame; \
                             cp /usr/share/fonts/truetype/freefont/FreeSansBold.ttf \
                                {build_dir}/pygame/freesansbold.ttf; \
                             ln -sf {dir}/examples/data {build_dir}/pygame/examples; \
                             ln -sf {dir}/test/fixtures {build_dir}/pygame/tests/

DEB_HOST_MULTIARCH = $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export ORIGLIBDIRS := /lib:/lib/$(DEB_HOST_MULTIARCH)

export DEB_HOST_ARCH_OS := $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_test:
	# buildds don't provide graphical interfaces or audio/video devices
	# to test with, hence some tests won't work properly without:
	SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=disk LC_ALL=C.UTF-8 \
		dh_auto_test -- --system=custom --test-args \
		'/usr/bin/xvfb-run {interpreter} -m pygame.tests.__main__ --exclude opengl'

override_dh_install:
	dh_install
	dh_numpy
	dh_numpy3
	rm -f debian/python*-pygame/usr/lib/python*/dist-packages/pygame/LGPL
	rm -rf debian/python*-pygame/usr/lib/python*/dist-packages/pygame/examples/
	rm -rf debian/python*-pygame/usr/lib/python*/dist-packages/pygame/tests/
	rm -rf debian/python*-pygame/usr/lib/python*/dist-packages/pygame/docs/

override_dh_installdocs:
	python setup.py build_sphinx
	dh_installdocs

override_dh_installchangelogs:
	dh_installchangelogs WHATSNEW

override_dh_compress:
	dh_compress -ppython-pygame-doc -Xexamples/
	dh_compress --remaining-packages
