#! /usr/bin/make -f

#export DH_VERBOSE = 1
export PYBUILD_DESTDIR_python2=debian/python-pycuda/
export PYBUILD_DESTDIR_python2-dbg=debian/python-pycuda-dbg/
export PYBUILD_DESTDIR_python3=debian/python3-pycuda/
export PYBUILD_DESTDIR_python3-dbg=debian/python3-pycuda-dbg/

ifneq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
DEB_CXXFLAGS_MAINT_STRIP=-O2
DEB_CXXFLAGS_MAINT_APPEND=-O0
endif

LAST_CHANGE=$(shell dpkg-parsechangelog -S Date)
BUILD_DATE=$(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")
SPHINXOPTS:=-D today=\"$(BUILD_DATE)\"
SPHINXOPTS+=-D html_last_updated_fmt=\"$(BUILD_DATE)\"

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

override_dh_auto_configure:
	./configure.py --boost-python-libname=boost_python-py \
		--boost-thread-libname=boost_thread \
		--cuda-root=/usr --cuda-enable-gl

override_dh_auto_install:
	dh_auto_install
	dh_numpy
	dh_numpy3

override_dh_installdocs:
	$(MAKE) -C doc html SPHINXOPTS="$(SPHINXOPTS)"
	dh_installdocs

# Sphinx documentation is architecture-independent
override_dh_sphinxdoc-arch:

# Do not run test automatically - they require CUDA-capable hardware
override_dh_auto_test:

override_dh_compress:
	dh_compress --all -X.py -X.txt -X.js -X.rst -X.json -X.doctree -Xobjects.inv

override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	dh_strip -ppython-pycuda --dbg-package=python-pycuda-dbg
	dh_strip -ppython3-pycuda --dbg-package=python3-pycuda-dbg
endif


MODULE_NAME=pycuda
DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog \
	| sed -rne 's/^Version: ([^-]+).*/\1/p')
GIT_REVISION=v2016.1
GIT_SUBMODULES=pycuda/compyte
GIT_URL=http://git.tiker.net/trees/pycuda.git

get-orig-source:
	rm -rf $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION) $(MODULE_NAME)_$(DEB_UPSTREAM_VERSION).orig.tar.gz
	git clone $(GIT_URL) $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)
	cd $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION) && git submodule init $(GIT_SUBMODULES) && git submodule update $(GIT_SUBMODULES) && git checkout $(GIT_REVISION)
	rm -rf $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/.git $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/.gitignore $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/.gitmodules
	rm -rf $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/examples/.gitignore
	rm -rf $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/$(GIT_SUBMODULES)/.git $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)/$(GIT_SUBMODULES)/.gitignore
	tar caf $(MODULE_NAME)_$(DEB_UPSTREAM_VERSION).orig.tar.xz $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)
	rm -rf $(MODULE_NAME)-$(DEB_UPSTREAM_VERSION)

