#!/usr/bin/make -f

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)
upstreamtarball = fsl-$(upstreamver)-feeds.tar.gz
upstreamurl = http://www.fmrib.ox.ac.uk/fsldownloads/$(upstreamtarball)

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

$(upstreamtarball):
	[ -f ../$@ ] || curl -o ../$@ $(upstreamurl)

maint-clean:
	rm -rf data doc RUN

maint-update-md5sum:
	md5sum $$(find . -type f ! -path './debian/*' ! -path './.git*' ! -path './.pc/*' | sort) > debian/origdata.md5sum

maint-check-md5sum:
	# if the check fails it means upstream changed something in the
	# data -- in that case visit upstream webpage, figure out date of
	# change and use it as a new upstream version (simply update Debian
	# changelog)
	md5sum -c debian/origdata.md5sum

maint-populate-srcpkg:
	# extract the pieces we are interested in (data and license information)
	tar --wildcards --strip-components 1 -xvzf ../$(srcpkg)_$(upstreamver).orig.tar.gz

get-orig-source: $(upstreamtarball)
	# extract the pieces we are interested in (data and license information)
	tar --wildcards --strip-components 1 -xvzf ../$(upstreamtarball)
	# cleanup
	-find . -name '*~' -delete
	# check integrity
	md5sum -c debian/origdata.md5sum
	# orig tarball
	tar --exclude='.git*' --exclude='.pc' --exclude=debian \
		--transform 's,^\./,$(srcpkg)-$(upstreamver)/,' \
		-cvzf ../$(srcpkg)_$(upstreamver).orig.tar.gz .
