#!/usr/bin/make -f

export DH_VERBOSE = 1
# export PYBUILD_VERBOSE=1
export PYBUILD_NAME=gallia

BUILD_FRAGMENTS := debian/build

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

# autopkgtest is wired up instead with additional bats tests.
override_dh_auto_test:

execute_after_dh_auto_build-indep: export http_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep: export https_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep:
	PYTHONPATH=. python3 -m sphinx -N -bhtml docs/ $(BUILD_FRAGMENTS)/docs/html # HTML generator
	PYTHONPATH=. python3 -m sphinx -N -bman  docs/ $(BUILD_FRAGMENTS)/docs/man  # Manpage generator

	# The register-python-argcomplete command is provided by python3-argcomplete.
	register-python-argcomplete -s bash gallia > $(BUILD_FRAGMENTS)/gallia-completion.bash
	register-python-argcomplete -s  zsh gallia > $(BUILD_FRAGMENTS)/gallia-completion.zsh
	register-python-argcomplete -s fish gallia > $(BUILD_FRAGMENTS)/gallia-completion.fish

execute_after_dh_auto_clean:
	$(RM) -r $(BUILD_FRAGMENTS)

execute_after_dh_auto_install-indep:
	# Install shell completion scripts.
	install -pD -m 0644 $(BUILD_FRAGMENTS)/gallia-completion.bash debian/gallia/usr/share/bash-completion/completions/gallia
	install -pD -m 0644 $(BUILD_FRAGMENTS)/gallia-completion.zsh  debian/gallia/usr/share/zsh/vendor-completions/_gallia
	install -pD -m 0644 $(BUILD_FRAGMENTS)/gallia-completion.fish debian/gallia/usr/share/fish/vendor_completions.d/gallia.fish

	# Install rendered documentation.
	mkdir -p debian/gallia/usr/share/doc/gallia/html
	cp -r $(BUILD_FRAGMENTS)/docs/html/* debian/gallia/usr/share/doc/gallia/html/

	# As of now, gallia does not provide manpages.
	# mkdir -p debian/gallia/usr/share/doc/gallia/man
	# cp -r $(BUILD_FRAGMENTS)/docs/man/*  debian/gallia/usr/share/doc/gallia/man/
