Makefile 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. NAME = sing-box
  2. COMMIT = $(shell git rev-parse --short HEAD)
  3. TAGS ?= with_gvisor,with_quic,with_wireguard,with_utls,with_reality_server,with_clash_api
  4. TAGS_TEST ?= with_gvisor,with_quic,with_wireguard,with_grpc,with_ech,with_utls,with_reality_server,with_shadowsocksr
  5. GOHOSTOS = $(shell go env GOHOSTOS)
  6. GOHOSTARCH = $(shell go env GOHOSTARCH)
  7. VERSION=$(shell CGO_ENABLED=0 GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) go run ./cmd/internal/read_tag)
  8. PARAMS = -v -trimpath -tags "$(TAGS)" -ldflags "-X 'github.com/sagernet/sing-box/constant.Version=$(VERSION)' -s -w -buildid="
  9. MAIN = ./cmd/sing-box
  10. PREFIX ?= $(shell go env GOPATH)
  11. .PHONY: test release
  12. build:
  13. go build $(PARAMS) $(MAIN)
  14. install:
  15. go build -o $(PREFIX)/bin/$(NAME) $(PARAMS) $(MAIN)
  16. fmt:
  17. @gofumpt -l -w .
  18. @gofmt -s -w .
  19. @gci write --custom-order -s "standard,prefix(github.com/sagernet/),default" .
  20. fmt_install:
  21. go install -v mvdan.cc/gofumpt@latest
  22. go install -v github.com/daixiang0/gci@latest
  23. lint:
  24. GOOS=linux golangci-lint run ./...
  25. GOOS=android golangci-lint run ./...
  26. GOOS=windows golangci-lint run ./...
  27. GOOS=darwin golangci-lint run ./...
  28. GOOS=freebsd golangci-lint run ./...
  29. lint_install:
  30. go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
  31. proto:
  32. @go run ./cmd/internal/protogen
  33. @gofumpt -l -w .
  34. @gofumpt -l -w .
  35. proto_install:
  36. go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
  37. go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
  38. snapshot:
  39. go run ./cmd/internal/build goreleaser release --rm-dist --snapshot || exit 1
  40. mkdir dist/release
  41. mv dist/*.tar.gz dist/*.zip dist/*.deb dist/*.rpm dist/release
  42. ghr --delete --draft --prerelease -p 1 nightly dist/release
  43. rm -r dist
  44. release:
  45. go run ./cmd/internal/build goreleaser release --rm-dist --skip-publish || exit 1
  46. mkdir dist/release
  47. mv dist/*.tar.gz dist/*.zip dist/*.deb dist/*.rpm dist/release
  48. ghr --delete --draft --prerelease -p 3 $(shell git describe --tags) dist/release
  49. rm -r dist
  50. release_install:
  51. go install -v github.com/goreleaser/goreleaser@latest
  52. go install -v github.com/tcnksm/ghr@latest
  53. test:
  54. @go test -v ./... && \
  55. cd test && \
  56. go mod tidy && \
  57. go test -v -tags "$(TAGS_TEST)" .
  58. test_stdio:
  59. @go test -v ./... && \
  60. cd test && \
  61. go mod tidy && \
  62. go test -v -tags "$(TAGS_TEST),force_stdio" .
  63. lib:
  64. go run ./cmd/internal/build_libbox
  65. lib_install:
  66. go get -v -d
  67. go install -v github.com/sagernet/gomobile/cmd/[email protected]
  68. go install -v github.com/sagernet/gomobile/cmd/[email protected]
  69. clean:
  70. rm -rf bin dist sing-box
  71. rm -f $(shell go env GOPATH)/sing-box
  72. update:
  73. git fetch
  74. git reset FETCH_HEAD --hard
  75. git clean -fdx