#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DH_OPTIONS
# Install everything, for testdata/ directories:
export DH_GOLANG_INSTALL_ALL := 1

# Install only restic binary, other binaries are used to prepare release.
export DH_GOLANG_BUILDPKG := github.com/restic/restic/cmd/restic

# FUSE doesn’t work within schroot
export RESTIC_TEST_FUSE := 0

%:
	dh $@ --buildsystem=golang --with=golang

# Prevent sphinx-build from accessing the internet during build.
override_dh_auto_build: export http_proxy=127.0.0.1:9
override_dh_auto_build: export https_proxy=127.0.0.1:9
override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. sphinx-build -N -bhtml doc/ -d debian/doctrees build/html

# Do not install the restic source code, there are no downstream consumers and
# it is not intended to be used as a library right now.
override_dh_auto_install:
	dh_auto_install -- --no-source
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	install -d debian/restic/usr/share/bash-completion/completions
	debian/restic/usr/bin/restic generate --bash-completion debian/restic/usr/share/bash-completion/completions/restic
	install -d debian/restic/usr/share/zsh/vendor-completions
	debian/restic/usr/bin/restic generate --zsh-completion debian/restic/usr/share/zsh/vendor-completions/_restic
endif

override_dh_compress:
	dh_compress -X.ttf -X.svg -X.eot -X.woff

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/doctrees