#!/usr/bin/make -f

# DH_VERBOSE := 1
DEB_CMAKE_EXTRA_FLAGS= -DCMAKE_BUILD_TYPE="Release"

# some helpful variables - uncomment them if needed
# shamelessly stolen from http://jmtd.net/log/awk/
#DEBVERS        := $(shell dpkg-parsechangelog | awk '/^Version:/ {print $$2}')
#VERSION        := $(shell echo '$(DEBVERS)' | sed -e 's/^[0-9]*://' -e 's/-.*//')
#DEBFLAVOR      := $(shell dpkg-parsechangelog | awk '/^Distribution:/ {print $$2}')
#DEBPKGNAME     := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')
#DEBIAN_BRANCH  := $(shell awk 'BEGIN{FS="[= ]+"} /debian-branch/ {print $$2}' debian/gbp.conf)
#GIT_TAG        := $(subst ~,_,$(VERSION))

# alternatively to manually set those variables you can
#  include /usr/share/cdbs/1/rules/buildvars.mk
# and use what is set there.  Any hint whether dh might set variables in
# a similar manner are welcome.

%:
	dh $@ --buildsystem=cmake

override_dh_auto_config:

override_dh_auto_build:
	mkdir -p build
	cd build && cmake -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX=$(CURDIR)/debian/tmp ..
	cd build && make
	cd build && make install

override_dh_clean:
	dh_clean
	find . -name "*.lo" -o -name "*.o" -o -name "*.la" -o -name Makefile | xargs -r rm
	rm -f examples/bwt examples/mksary examples/sasearch examples/suftest examples/unbwt
	rm -rf build lib/.libs
	rm -rf config.log config.status include/config.h include/divsufsort.h include/lfs.h include/stamp-h1 libtool


#override_dh_install:
#	dh_install
#	cp build/lib/lib*so.3.0.1 $(CURDIR)/debian/libdivsufsort3/usr/lib/


#get-orig-source:
#	. debian/get-orig-source
