#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for Ginkgo CADx

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

%:
	dh $@ --buildsystem=cmake --parallel

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

UPSTREAM_SRC = ginkgocadx-$(VER_FULL)
DEBIAN_SRC_DIR = ginkgocadx-$(VER_FULL)
DEBIAN_SRC_TAR = ginkgocadx_$(VER_FULL).orig.tar.gz

$(UPSTREAM_SRC).tgz:
	wget -c http://voxel.dl.sourceforge.net/sourceforge/ginkgocadx/$@

get-orig-source: $(UPSTREAM_SRC).tgz
	tar xzf $(UPSTREAM_SRC).tgz
	# strip debian subdir
	rm -rf $(UPSTREAM_SRC)/debian
	GZIP="--best --no-name" tar czf $(DEBIAN_SRC_TAR) $(DEBIAN_SRC_DIR)

override_dh_auto_install:
	dh_auto_install
	dh_installchangelogs debian/changelog
	# there are two path in rpath, one to libraries for the package and one
	# for mpi, the later has to be removed
	[ ! -f debian/ginkgocadx/usr/lib/ginkgocadx/Plugins/libvisualizator.so.$(VER_FULL) ] ||  /usr/bin/chrpath -r /usr/lib/ginkgocadx debian/ginkgocadx/usr/lib/ginkgocadx/Plugins/libvisualizator.so.$(VER_FULL)
	[ ! -f debian/ginkgocadx/usr/lib/ginkgocadx/libCADxCore.so.$(VER_FULL) ] || /usr/bin/chrpath -r /usr/lib/ginkgocadx debian/ginkgocadx/usr/lib/ginkgocadx/libCADxCore.so.$(VER_FULL)

