#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

CPUS=$(shell cat /proc/cpuinfo | grep -E ^processor | wc -l)

export HGPYTHON3=1
export PYTHON=python3

%:
	dh $@ --with python3

override_dh_auto_test:
	http_proxy='' dh_auto_test -- TESTFLAGS="-j$(CPUS)"

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3

override_dh_auto_clean:
	$(MAKE) cleanbutpackages
	$(MAKE) -C contrib/chg clean

override_dh_auto_build:
	$(MAKE) all
	$(MAKE) -C contrib/chg all

override_dh_auto_install:
	python3 setup.py install --root "$(CURDIR)"/debian/mercurial --install-layout=deb
	# chg
	make -C contrib/chg \
		DESTDIR="$(CURDIR)"/debian/mercurial \
		PREFIX=/usr \
		install
	make install-doc PREFIX="$(CURDIR)"/debian/mercurial/usr
	cp contrib/hg-ssh "$(CURDIR)"/debian/mercurial/usr/bin
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/mercurial
	cp contrib/hgk "$(CURDIR)"/debian/mercurial/usr/share/mercurial
	mkdir -p "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
	cp contrib/packaging/debian/*.rc "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
	# completions
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions
	cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
	cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
