#!/usr/bin/make -f

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8
export GOCACHE=/tmp/gocache
export DH_GOLANG_INSTALL_EXTRA=Makefile gui tests vendor/modules.txt branding providers bitmask.pro test.pro
export BUILDDIR=_build/src/0xacab.org/leap/bitmask-vpn/
export GOPATH = ${CURDIR}/_build:/usr/share/gocode
export GO111MODULE := off

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

VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/+ds1//' -e 's/r/\./')

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

execute_before_dh_auto_configure:
	rm -f $(CURDIR)/pkg/motd/motd_test.go $(CURDIR)/pkg/vpn/bonafide/bonafide_test.go $(CURDIR)/pkg/vpn/bonafide/gateways_test.go

override_dh_auto_build:
	cd $(BUILDDIR) && $(MAKE) build VERSION=$(VERSION)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Qmake test
	cd $(BUILDDIR) && qmake test.pro -o tests/Makefile.test && \
	cd tests && $(MAKE) -f Makefile.test && $(MAKE) -f Makefile.test clean
	# Golang test
	DH_GOLANG_EXCLUDES=gui dh_auto_test
endif

override_dh_auto_install:
	dh_auto_install -- --no-source
