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

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

# parallel build by default on linux
ifeq ($(DEB_HOST_ARCH_OS),linux)
    ifeq ($(findstring parallel=,$(DEB_BUILD_OPTIONS)),)
        export DEB_BUILD_OPTIONS+=parallel=$(shell getconf _NPROCESSORS_ONLN)
    endif
endif
$(info DEB_BUILD_OPTIONS:$(origin DEB_BUILD_OPTIONS)=$(DEB_BUILD_OPTIONS))

PKD = $(abspath $(dir $(MAKEFILE_LIST)))
PKG = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))

%:
	dh $@ --parallel --max-parallel=3

override_dh_auto_configure:
	@echo "## checking integrity..."
	sha1sum --strict --check debian/files_sha1.txt

DD=$(CURDIR)/debian/$(PKG)/usr/share/games/freespace2-open/mediavps_3612
override_dh_auto_install:
	[ -d "$(DD)" ] || mkdir -v -p "$(DD)"
	for F in *.zip; do unzip -j "$$F" -d "$(DD)" ;done

override_dh_builddeb:
	dh_builddeb -- -Zxz -z4

get-orig-source:
	sha1sum --strict --check debian/files_sha1.txt \
	|| wget --tries=3 --timeout=60 --read-timeout=60 --continue --timestamping \
            --recursive --level=0 --convert-links --relative --no-directories \
            --accept=.zip "http://www.mvp.fsmods.net/3612/"
	@echo "## generating checksums..."
	sha1sum --binary *.zip *.7z | tee debian/files_sha1.txt~NEW
	diff -U0 debian/files_sha1.txt debian/files_sha1.txt~NEW \
        && $(RM) debian/files_sha1.txt~NEW

# see http://www.hard-light.net/forums/index.php?topic=70736.0
# MV_Maximum_3612.7z contains
#			MediaVPs_3612.zip
#			MV_Advanced_3612.zip
#			MV_AnimGlows_3612.zip
#			MV_Assets_3612.zip
#			MV_Effects_3612.zip
#			MV_Music_3612.zip
#			MV_Root_3612.zip
