#!/usr/bin/make -f

# Copyright 2017 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for Mediagoblin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# resolve if release is experimental
include /usr/share/dpkg/pkg-info.mk
EXP_RELEASE = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

# handle Python libraries
# * generate gettext MO locale files
# * add symlink to provide a deterministic path for main package
python3_default = $(shell py3versions -d)
export PYBUILD_NAME = mediagoblin
export PYBUILD_AFTER_BUILD = \
	cd {build_dir} && {dir}/devtools/compile_translations.sh
export PYBUILD_BEFORE_TEST = \
	cp -a alembic.ini {build_dir}/ \
	&& cp -R {dir}/mediagoblin/tests/test_exif \
		{build_dir}/mediagoblin/tests
export PYBUILD_AFTER_TEST = \
	rm -rf {build_dir}/alembic.ini
export PYBUILD_INSTALL_ARGS = \
	--install-scripts='/usr/share/mediagoblin/{interpreter}/bin/'
export PYBUILD_AFTER_INSTALL = \
	if test '$(python3_default)' = '{interpreter}'; then \
		ln -sT '{interpreter}' '{destdir}/usr/share/mediagoblin/python3'; \
	fi
export PYBUILD_TEST_PYTEST = 1

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_build:
	cp -f mediagoblin.example.ini mediagoblin.ini
	dh_auto_build
	$(MAKE) -C docs html info

# ignore testuite failure when targeting experimental
override_dh_auto_test:
	dh_auto_test$(if $(EXP_RELEASE), || true)

override_dh_installchangelogs:
	dh_installchangelogs docs/source/siteadmin/relnotes.rst

override_dh_fixperms:
	dh_fixperms
	chmod +x debian/python3-mediagoblin/usr/lib/python3/dist-packages/mediagoblin/tests/test_submission/evil.*

# Preserve upstream cruft to not upset git-buildpackage
override_dh_clean:
	dh_clean -Xmediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html.orig
