#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export PATH := /usr/lib/go-1.23/bin:$(PATH)
export DH_GOLANG_BUILDPKG := github.com/xtls/xray-core/main/...
export DH_GOLANG_INSTALL_EXTRA := \
	transport/internet/websocket/dialer.html

LDFLAGS = -s -w -buildid=

%:
	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
	cd obj-$(DEB_TARGET_GNU_TYPE); mv bin/main bin/xray

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/xray.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/xray.substvars

override_dh_auto_test:
