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

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

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

# The GOG installer was previously called setup_freespace2_2.0.0.8.exe.
# As of Sept 2020, it is setup_freespace_2_1.20_v2_(33372).exe, along with
# setup_freespace_2_1.20_v2_(33372)-1.bin.
gog_installer = $(wildcard setup_freespace*.exe)

%:
	dh $@

override_dh_auto_clean:
	$(RM) -r app tmp

override_dh_auto_configure:
	innoextract '$(gog_installer)'

move_files_installer_v2:
	mv MANUAL.PDF *.vp ReadMe.txt refcard.pdf data2/ data3/ app/

#DD=$(CURDIR)/debian/$(PKG)/usr/share/games/freespace2-open
#M=/data/movies

# In the case of installer v2, we need to move around some files so that they
# are where files_sha1.txt expects.
ifeq ($(findstring setup_freespace_2_1.20_v2,$(gog_installer)),)
override_dh_auto_build:
else
override_dh_auto_build: move_files_installer_v2
endif
	@echo "## checking integrity..."
	sha1sum --strict --check debian/files_sha1.txt
	#[ -d "$(DD)$(M)" ] || mkdir -v -p "$(DD)$(M)"
	#mv app/data?/*.MVE "$(DD)$(M)"

override_dh_builddeb:
	dh_builddeb -- -Zxz

get-orig-source:
	sha1sum --binary app/data2/* app/data3/* app/*.vp app/MANUAL.PDF app/ReadMe.txt app/refcard.pdf | tee debian/files_sha1.txt~NEW
