#!/usr/bin/make -f
# -*- makefile -*-

srcpkg = $(shell LC_ALL=C dpkg-parsechangelog | grep '^Source:' | cut -d ' ' -f 2,2)
upstreamver = $(shell LC_ALL=C dpkg-parsechangelog | grep '^Version:' | cut -d ' ' -f 2,2 | cut -d '-' -f 1,1)


export LDFLAGS = -Wl,--as-needed

# one ring to rule them all ...
%:
	dh $@


override_dh_auto_configure:
	dh_auto_configure -- -DSNAP_USE_FLTK_1_1:BOOL=ON


override_dh_auto_install:
	dh_auto_install
	# move data files to /usr/share
	mv $(CURDIR)/debian/itksnap/usr/lib/snap*/ProgramData \
		$(CURDIR)/debian/itksnap/usr/share/itksnap/
	# get rid of application "forwarder"
	mv $(CURDIR)/debian/itksnap/usr/lib/snap*/InsightSNAP \
		$(CURDIR)/debian/itksnap/usr/bin/itksnap
	# remove left-overs
	rm -r $(CURDIR)/debian/itksnap/usr/lib
	# use one of the pix as an icon
	convert $(CURDIR)/ProgramData/Images2D/EdgeForcesExample.png -resize 32x32 \
		$(CURDIR)/debian/itksnap/usr/share/pixmaps/itksnap.xpm
	# strip useless CMakeLists
	find $(CURDIR)/debian/itksnap/usr -name 'CMakeLists.txt' -delete


get-orig-source:
	# orig tarball, turn directory into something nicer
	touch $(srcpkg)_$(upstreamver).orig.tar.gz
	tar --exclude='.git*' --exclude=debian --exclude=.pc \
		--exclude=$(srcpkg)_$(upstreamver).orig.tar.gz \
		--transform 's,^,$(srcpkg)-$(upstreamver)/,' \
		-cvzf $(srcpkg)_$(upstreamver).orig.tar.gz .
