#!/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 PYMOL_PATH=$(CURDIR)
PACKAGE = pymol
PYTHON_VERSION := $(shell pyversions -dv)

%:
	dh $@ --with python2 --parallel

override_dh_auto_configure:
	dh_auto_configure -Spython_distutils

override_dh_auto_build:
	dh_auto_build -Spython_distutils

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) distclean
	-dh_auto_clean -Spython_distutils

override_dh_auto_test:
	#dh_auto_test
	chmod +x test/pymol-test
	(cd test && python run)

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: debian/pymol-ref-card.pdf debian/pymol.launch
	dh_numpy
	dh_install data/shaders usr/lib/python$(PYTHON_VERSION)/dist-packages/pymol/data/
	-rm -rf debian/pymol/usr/lib/python$(PYTHON_VERSION)/dist-packages/pymol/data/
	-install -m 755 debian/pymol.launch debian/pymol/usr/bin/pymol

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@/$(PYTHON_VERSION)/g < $< > $@

override_dh_fixperms:
	dh_fixperms
	-find debian/*/usr/share/pymol/data/xray/ -type f -name "*.dat" -exec chmod -x \{\} \;
