#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

ifeq ($(shell test -d /usr/lib/go-1.24/bin && echo yes),yes)
    export PATH := /usr/lib/go-1.24/bin:$(PATH)
endif
export DH_GOLANG_BUILDPKG := github.com/go-gost/gost/cmd/gost/...

LDFLAGS = -s -w
%:
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_configure:
	if [ -f /usr/src/packages/SOURCES/vendor.tar.zst ]; then \
		tar -xf /usr/src/packages/SOURCES/vendor.tar.zst; \
	fi
	dh_auto_configure -O--buildsystem=golang

override_dh_auto_build:
ifneq ($(filter $(DEB_TARGET_ARCH), amd64),)
	GO111MODULE=on GOAMD64=v2 dh_auto_build -O--buildsystem=golang -- -trimpath -ldflags "$(LDFLAGS)"
else
	GO111MODULE=on dh_auto_build -O--buildsystem=golang -- -trimpath -ldflags "$(LDFLAGS)"
endif

override_dh_auto_install:
	dh_auto_install -O--buildsystem=golang -- --no-source

override_dh_golang:
	echo "misc:Static-Built-Using=$(shell dpkg-query -f='$${source:Package} (= $${source:Version})\n' -W $(shell dpkg-query --search $(shell which go) | cut -d: -f1))" >> debian/gost.substvars
	echo "misc:Built-Using=$(shell dpkg-query -f='$${source:Package} (= $${source:Version})\n' -W $(shell dpkg-query --search $(shell which go) | cut -d: -f1))" >> debian/gost.substvars

override_dh_auto_test:
