#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND  = -Wl,--as-needed

export CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
export CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
export CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
export LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

# lkajan: we borrow from libtorrent-rasterbar and pythonmagick here (thank you)
PYVERSIONS=$(shell pyversions -vr)
# lkajan: the below could include debug versions like in python-libtorrent
ALLPY=$(PYVERSIONS) $(PYVERSIONS:%=%-dbg)

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

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

.PHONY: override_dh_auto_build
override_dh_auto_build: override_dh_auto_build-nopy override_dh_auto_build-py

.PHONY: override_dh_auto_build-nopy
override_dh_auto_build-nopy:
	dh_auto_build --parallel
	$(MAKE) doc

.PHONY: override_dh_auto_build-py
override_dh_auto_build-py: override_dh_auto_build-nopy
	dh_auto_build --parallel --sourcedirectory=wrapper/python

.PHONY: override_dh_auto_install
override_dh_auto_install: override_dh_auto_install-nopy override_dh_auto_install-py

.PHONY: override_dh_auto_install-nopy
override_dh_auto_install-nopy:
	# lkajan: there is no real install mechanism in the upstream sources

.PHONY: override_dh_auto_install-py
override_dh_auto_install-py:
	dh_auto_install --sourcedirectory=wrapper/python 

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=librcsb-core-wrapper0-dbg

.PHONY: override_dh_makeshlibs
override_dh_makeshlibs:
	dh_makeshlibs -V

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	dh_auto_clean
	rm -rf wrapper/python/build

.PHONY:
get-orig-source:
	mkdir -p ../tarballs
	uscan --verbose --force-download --destdir=../tarballs
