#!/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 helpers pkg/pickle/helpers providers
export BUILDDIR=_build/src/0xacab.org/leap/bitmask-vpn/
export GOPATH = ${CURDIR}/_build:/usr/share/gocode
export GO111MODULE := off
export CI=1

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

VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/+ds.*//' -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) gen_providers_json PROVIDER=riseup,riseupbeta && $(MAKE) build VERSION=$(VERSION) LRELEASE=/usr/lib/qt6/bin/lrelease QMAKE=/usr/bin/qmake6 PROVIDER=riseup TARGET=riseup-vpn

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Qmake test
	cd $(BUILDDIR) && qmake6 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