#!/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 = atlasfiles.tar.gz
upstreamurl = http://brainmap.wisc.edu/assets/$(upstreamtarball)

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

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

maint-clean:
	rm -rf atlasfiles

maint-update-md5sum:
	md5sum $$(find . -type f -path './atlasfiles*') > 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 -xvzf ../$(srcpkg)_$(upstreamver).orig.tar.gz

get-orig-source: $(upstreamtarball)
	# extract the pieces we are interested in (data and license information)
	tar -xvzf ../$(upstreamtarball) atlasfiles
	# clean up
	rm -f atlasfiles/._*
	# check integrity
	md5sum -c debian/origdata.md5sum
	# orig tarball
	tar --transform 's/^\./$(srcpkg)-$(upstreamver)/' --exclude='.git*' \
		--exclude=debian -cvzf ../$(srcpkg)_$(upstreamver).orig.tar.gz .
