#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

cmd = radicale
_ENV_staged = $(strip \
 PATH="$(CURDIR)/debian/tmp/usr/bin:$(PATH)" \
 PYTHONPATH="$(CURDIR)/debian/tmp/usr/lib/$(shell py3versions -d)/dist-packages")

# generate manpage with help2man from --help option of python script
_mkman = $(_ENV_staged) \
 help2man $(if $3,--name "$(strip $3)") --no-info \
 --version-string="$(DEB_VERSION_UPSTREAM_REVISION)" \
 --output $2 $1 \
 || { $(_ENV_staged) $1 --help; false; }

export PYBUILD_BEFORE_TEST=cp -r {dir}/radicale {build_dir}
export PYBUILD_AFTER_TEST=rm -rf {build_dir}/radicale

%:
	dh "$@" --buildsystem=pybuild

# Disable system daemon by default
override_dh_installinit:
	dh_installinit --package=radicale --no-enable

# generate manpage based on --help option of script itself
override_dh_auto_install:
	dh_auto_install
	$(call _mkman, $(cmd), debian/$(cmd).1, \
		a simple calendar server)

# fix unset execution bit on FCGI and WSGI scripts
override_dh_fixperms:
	dh_fixperms
	chmod -x \
		debian/radicale/usr/share/radicale/radicale.fcgi \
		debian/radicale/usr/share/radicale/radicale.wsgi
