#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# Make sure that gimp doesn't read or write data into $HOME/.gimp-2.6
export GIMP2_DIRECTORY=$(CURDIR)/gimp-data

%:
	dh $@

INSTALL_ROOT=debian/openttd-opengfx
DATA_DIR=usr/share/games/openttd/baseset/opengfx
DOC_DIR=/usr/share/doc/openttd-opengfx


OPTIONS=
OPTIONS += "INSTALL_DIR=$(INSTALL_ROOT)/$(DATA_DIR)"
OPTIONS += "_V="
OPTIONS += "PYTHON=python3"

override_dh_auto_build:
	# Remove all graphics files that can be rebuilt (from gimp xcf
	# files).
	make clean-gfx $(OPTIONS)
	# Then rebuild everything
	make grf doc $(OPTIONS)

override_dh_auto_install:
	make install $(OPTIONS)
	# In the datadir, replace the readme and changelog with symlinks
	# to /usr/share/doc to save space.
	dh_link $(DOC_DIR)/readme.txt $(DATA_DIR)/readme.txt
	dh_link $(DOC_DIR)/changelog $(DATA_DIR)/changelog.txt
	# Verify that the license.txt that was installed is equal to the
	# GPL-2 common license and then just link to that one instead
	diff -q /usr/share/common-licenses/GPL-2 $(INSTALL_ROOT)/$(DATA_DIR)/license.txt
	dh_link usr/share/common-licenses/GPL-2 $(DATA_DIR)/license.txt

override_dh_installdocs:
	dh_installdocs docs/readme.txt

override_dh_installchangelogs:
	dh_installchangelogs docs/changelog.txt

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Check if the md5 sums of the resulting grf files match. This
	# ensures no problems will arise in online play, which uses both
	# version info and md5 sums of files.
	make check $(OPTIONS)
endif

override_dh_auto_clean:
	make distclean $(OPTIONS)
	# Remove any data created by gimp
	rm -rf "$(GIMP2_DIRECTORY)"
