#!/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
override_dh_auto_install:
	[ -d "$(DD)" ] || mkdir -v -p "$(DD)"
#	for F in *.7z; do unzip -j "$$F" -d "$(DD)" ;done
	for F in *.7z; do 7za e -y -bd -o$(DD)/ "$$F" ;done

override_dh_builddeb:
	dh_builddeb -- -Zxz -z4

# https://www.hard-light.net/forums/index.php?topic=99050.0
get-orig-source:
	sha1sum --strict --check debian/files_sha1.txt \
	|| wget --tries=3 --timeout=60 --read-timeout=60 --wait=1 --random-wait --continue --timestamping \
            --recursive --level=1 --no-directories --no-parent --span-hosts --accept=7z \
            "https://fsnebula.org/mod/MVPS#expert_content"
	@echo "## generating checksums..."
	sha1sum --binary *.7z | tee debian/files_sha1.txt~NEW
	diff -U0 debian/files_sha1.txt debian/files_sha1.txt~NEW \
        && $(RM) debian/files_sha1.txt~NEW

## --recursive --level=1  --relative  --convert-links 