#!/usr/bin/make -f

srcname = staticsite
version = $(shell sed -nre 's/.*version[ ]*=[ ]*"([^"]+)".*/\1/p' setup.py)

# See https://wiki.debian.org/Python/Pybuild
export PYBUILD_BEFORE_TEST=cp -r {dir}/example {build_dir}
export PYBUILD_AFTER_TEST=rm -rf {build_dir}/example


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

override_dh_python3:
	dh_python3 --recommends-section=serve

override_dh_auto_build:
	dh_auto_build
	COLUMNS=200 help2man --name='Static site generator' --section=1 --version-string="$(version)" --no-info ./ssite > ssite.1

override_dh_compress:
	dh_compress --exclude=.ico

override_dh_installdocs:
	dh_installdocs
	# Remove vendored front end libraries
	rm -r debian/staticsite/usr/share/doc/staticsite/example/theme/static/jquery
	rm -r debian/staticsite/usr/share/doc/staticsite/example/theme/static/popper.js
	rm -r debian/staticsite/usr/share/doc/staticsite/example/theme/static/bootstrap4
	rm -r debian/staticsite/usr/share/doc/staticsite/example/theme/static/fork-awesome
	# Configure example site to use system versions instead
	echo '---' > debian/staticsite/usr/share/doc/staticsite/example/theme/config
	echo '# System-distributed assets in use' >> debian/staticsite/usr/share/doc/staticsite/example/theme/config
	echo 'system_assets: [jquery, popper.js, bootstrap4, fork-awesome]' >> debian/staticsite/usr/share/doc/staticsite/example/theme/config


debsrc:
	python3 setup.py sdist
	mv dist/$(srcname)-$(version).tar.gz ../$(srcname)_$(version).orig.tar.gz
	gbp buildpackage -S -us -uc
