#!/usr/bin/make -f

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

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# default is first version
DEFAULTPY=$(shell pyversions -v -d)
PYVERSIONS=$(shell pyversions -v -r)
ALLPY=$(PYVERSIONS:%=%-dbg) $(PYVERSIONS)

CMAKE_PARAMS=-DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr
override_dh_strip:
	dh_strip --dbg-package=libgammu-dbg

override_dh_auto_configure-%:
	mkdir build-$*
	set -e -x; cd build-$* ; cmake .. $(CMAKE_PARAMS) -DBUILD_PYTHON=/usr/bin/python$*

override_dh_auto_configure: $(ALLPY:%=override_dh_auto_configure-%)

override_dh_auto_build-$(DEFAULTPY):
	dh_auto_build -- --no-print-directory -C build-$(DEFAULTPY)
	make --no-print-directory -C build-$(DEFAULTPY) manual-html
	rm -rf build-$(DEFAULTPY)/docs/manual/html/.doctrees

override_dh_auto_build-%:	
	dh_auto_build -- --no-print-directory -C build-$*

override_dh_auto_build: $(ALLPY:%=override_dh_auto_build-%)

# We do all test just once
override_dh_auto_test-$(DEFAULTPY):
ifneq (,$(filter nocheck, $(DEB_BUILD_OPTIONS)))
	@echo "Tests disabled"
else
	set -e -x; cd build-$(DEFAULTPY) ; ctest -V
endif

override_dh_auto_test-%:
ifneq (,$(filter nocheck, $(DEB_BUILD_OPTIONS)))
	@echo "Tests disabled"
else
	set -e -x; cd build-$* ; ctest -V -R py-
endif

override_dh_auto_test: $(ALLPY:%=override_dh_auto_test-%)

override_dh_auto_install-%:
	dh_auto_install -- --no-print-directory -C build-$*

override_dh_auto_install: $(ALLPY:%=override_dh_auto_install-%)

override_dh_compress:
	dh_compress -X.js -Xobjects.inv -X.txt -X.py

override_dh_auto_clean:
	rm -rf build-*

override_dh_makeshlibs:
	dh_makeshlibs -V

build: build-stamp
build-arch: build-stamp
build-indep: build-stamp

build-stamp:
	dh --with python2 build
	touch $@

clean:
	dh --with python2 $@

install: build install-stamp
install-stamp:
	dh --with python2 install
	touch $@

# Build architecture-independent files here.
binary-indep: build install
	dh --with python2 $@

# Build architecture-dependent files here.
binary-arch: build install
	dh --with python2 $@

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install 
