#!/usr/bin/make -f
# -*- Makefile -*-

#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
# since this package produces shared library, not executable -
# -fPIE, -pie compiler/linker options are turned off.

export PYBUILD_NAME = pymol

%:
	dh $@ --with python3 --buildsystem pybuild

# FIXME: many of these tests
# FIXME: the test suite passes despite tests failing
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	chmod +x test/pymol-test
	PYBUILD_SYSTEM="custom" \
	  PYBUILD_BEFORE_TEST="cp -r {dir}/test {build_dir}" \
	  PYBUILD_AFTER_TEST="rm -rf {build_dir}/test" \
	  PYBUILD_TEST_ARGS="cd {build_dir}/test; PYMOL_PATH={build_dir} python{version} run" \
	  dh_auto_test
endif

override_dh_clean:
	$(RM) -r build test/tmp test/cmp generated
	dh_clean debian/pymol.launch debian/pymol-ref-card.* \
	         Rules.make create_shadertext.pyc

override_dh_install-indep: debian/pymol.launch debian/pymol-ref-card.pdf
	dh_install
	install -m 755 debian/pymol.launch debian/pymol/usr/bin/pymol

override_dh_install-arch:
	dh_numpy3
	dh_install
	rm -rf debian/python*pymol/usr/bin

override_dh_compress:
	dh_compress -Xpdb

debian/pymol-ref-card.pdf: debian/pymolRef.tex
	pdflatex -output-directory $(@D) -jobname pymol-ref-card $<

debian/pymol.launch: debian/pymol.launch.in
	sed -e s/@PYTHON_VERSION@/3/g < $< > $@
