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

baseurl = http://www.bic.mni.mcgill.ca/~vfonov/icbm/2009
basefilename = mni_icbm152_nlin_
destdir = mni-icbm152-nlin-09
srcname = $(shell dpkg-parsechangelog | grep '^Source:' | cut -d ' ' -f 2,2)
upstreamver = $(shell dpkg-parsechangelog | grep '^Version:' | cut -d ' ' -f 2,2 | cut -d '-' -f 1,1)

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

#
# Following rules are only relevant for updating the source package
#

$(destdir):
	-mkdir -p $(destdir)
	for f in asym_09a asym_09b asym_09c sym_09a sym_09b sym_09c; do \
		echo "Download and extract $(basefilename)$${f}" ; \
		wget $(baseurl)/$(basefilename)$${f}_nifti.zip ; \
		unzip -o $(basefilename)$${f}_nifti.zip -d $(destdir) ; \
	done

maint-check-images:
	# 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-update-md5sum:
	md5sum $(basefilename)* > debian/origdata.md5sum

get-orig-source: $(destdir) maint-check-images
	@echo "Compress NIfTI files"
	find $(destdir) -name '*.nii' -exec gzip {} \;
	tar -czf ../$(srcname)_$(upstreamver).orig.tar.gz $(destdir)

maint-populate-srcpkg:
	tar --strip 1 -xzf ../$(srcname)_$(upstreamver).orig.tar.gz

maint-clean:
	-rm -rf *.zip mni* COPYING
