# Contributor: Anon <danilagdn.2004@gmail.com>
# Maintainer: Lindsay Zhou <i@lin.moe>
pkgname=sing-box
pkgver=1.10.1
pkgrel=0
pkgdesc="The universal proxy platform"
url="https://sing-box.sagernet.org/"
arch="all"
license="GPL-3.0-or-later with name use or association addition"
makedepends="go"
subpackages="$pkgname-openrc $pkgname-bash-completion $pkgname-fish-completion $pkgname-zsh-completion"
options="net" # go modules
source="$pkgname-$pkgver.tar.gz::https://github.com/SagerNet/sing-box/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"
_tags="with_gvisor,with_quic,with_wireguard,with_utls,with_reality_server,with_clash_api,with_ech,with_dhcp,with_acme"

build() {
	export CGO_CPPFLAGS="$CPPFLAGS"
	export CGO_CFLAGS="$CFLAGS"
	export CGO_CXXFLAGS="$CXXFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"

	go build -v -tags "$_tags" \
	-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$pkgver\" -s -w
	-buildid= -linkmode=external" ./cmd/sing-box

	install -d completions
	go run ./cmd/sing-box completion bash   > completions/bash
	go run ./cmd/sing-box completion fish   > completions/fish
	go run ./cmd/sing-box completion zsh    > completions/zsh
}

check() {
	go test -v ./...
	# require docker to run test cases in the "test" submodule,
	# so we don't use `make test`.
}

package() {
	install -Dm644 LICENSE                      -t "$pkgdir/usr/share/licenses/$pkgname"
	install -Dm755 "$pkgname"                   -t "$pkgdir/usr/bin"
	install -Dm644 "release/config/config.json" -t "$pkgdir/etc/$pkgname"
	install -Dm755 "$srcdir/$pkgname.initd" 		"$pkgdir/etc/init.d/$pkgname"
	install -Dm755 "$srcdir/$pkgname.confd" 		"$pkgdir/etc/conf.d/$pkgname"

	install -Dm644 completions/bash "$pkgdir/usr/share/bash-completion/completions/$pkgname.bash"
	install -Dm644 completions/fish "$pkgdir/usr/share/fish/vendor_completions.d/$pkgname.fish"
	install -Dm644 completions/zsh  "$pkgdir/usr/share/zsh/site-functions/_$pkgname"

}

sha512sums="
def0f28901a9f432c5a43bfd2b8cd9f83832a2f4487abcc786c6c046ec1c66ac7b8dbe4db6f89eecefd042152056181b3006f4c1e61af814761d105e8625d76a  sing-box-1.10.1.tar.gz
1fd26edaeefb94d3fbf53a8310efad1776c2a90c6497481def603667e565bbca9f75ef670bb1e3c06488ab8a68ff27943f2f828fdb2b869ee6c2da95425cbccb  sing-box.initd
448184b1ea062f93854c61c86b591681b35767bf475c2643e416e41f84da5b1a793351613470909b17c533ddf964ccbf438aa3454073e8e84d0f4d3ef0385654  sing-box.confd
"
