#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
	-DBUILD_MATLAB_BINDINGS:BOOL=OFF \
	-DBUILD_PYTHON_BINDINGS:BOOL=OFF \
	-DUSE_MPI:BOOL=ON \
	-DBUILD_CUDA_LIB:BOOL=OFF

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_auto_test:
	# test download material from the net. Removing them.

override_dh_compress:
	dh_compress --exclude=.pdf

# Let's be smart with building doc
override_dh_auto_build-indep:
	$(MAKE) -C obj-* doc

# No tests needed for docs
override_dh_auto_test-indep:

VER_FULL = $(shell dpkg-parsechangelog | grep '^Version' | cut -d' ' -f2 | cut -f1 -d-)

UPSTREAM_SRC = flann-$(VER_FULL)-src
DEBIAN_SRC_DIR = flann-$(VER_FULL)
DEBIAN_SRC_TAR = flann_$(VER_FULL).orig.tar.gz

$(UPSTREAM_SRC).zip:
	#uscan --verbose --force-download --repack --rename
	wget -c http://people.cs.ubc.ca/~mariusm/uploads/FLANN/$@

get-orig-source: $(UPSTREAM_SRC).zip
	rm -rf $(DEBIAN_SRC_DIR)
	unzip -q $(UPSTREAM_SRC).zip
	mv $(UPSTREAM_SRC) $(DEBIAN_SRC_DIR)
	rm $(DEBIAN_SRC_DIR)/doc/manual.pdf # will be rebuild from latex
	# download changelog:
	links -dump http://people.cs.ubc.ca/~mariusm/index.php/FLANN/Changelog | tail -n +10 | grep -v PmWiki > $(DEBIAN_SRC_DIR)/Changelog
	GZIP="--best --no-name" tar czf $(DEBIAN_SRC_TAR) $(DEBIAN_SRC_DIR)
	rm -rf $(DEBIAN_SRC_DIR)
	rm $(UPSTREAM_SRC).zip
