2022-08-13 10:36:49 +00:00
|
|
|
NAME = sing-box
|
|
|
|
COMMIT = $(shell git rev-parse --short HEAD)
|
2023-12-09 04:11:21 +00:00
|
|
|
TAGS_GO118 = with_gvisor,with_dhcp,with_wireguard,with_reality_server,with_clash_api
|
2024-02-10 04:01:09 +00:00
|
|
|
TAGS_GO120 = with_quic,with_utls
|
|
|
|
TAGS_GO121 = with_ech
|
|
|
|
TAGS ?= $(TAGS_GO118),$(TAGS_GO120),$(TAGS_GO121)
|
2023-11-13 06:12:22 +00:00
|
|
|
TAGS_TEST ?= with_gvisor,with_quic,with_wireguard,with_grpc,with_ech,with_utls,with_reality_server
|
2023-03-13 11:46:08 +00:00
|
|
|
|
|
|
|
GOHOSTOS = $(shell go env GOHOSTOS)
|
|
|
|
GOHOSTARCH = $(shell go env GOHOSTARCH)
|
|
|
|
VERSION=$(shell CGO_ENABLED=0 GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) go run ./cmd/internal/read_tag)
|
|
|
|
|
2023-08-11 07:44:04 +00:00
|
|
|
PARAMS = -v -trimpath -ldflags "-X 'github.com/sagernet/sing-box/constant.Version=$(VERSION)' -s -w -buildid="
|
2023-08-21 10:14:17 +00:00
|
|
|
MAIN_PARAMS = $(PARAMS) -tags $(TAGS)
|
2022-08-13 10:36:49 +00:00
|
|
|
MAIN = ./cmd/sing-box
|
2023-03-11 11:18:12 +00:00
|
|
|
PREFIX ?= $(shell go env GOPATH)
|
2022-08-12 14:53:46 +00:00
|
|
|
|
2024-03-15 08:22:43 +00:00
|
|
|
.PHONY: test release docs build
|
2022-08-12 14:53:46 +00:00
|
|
|
|
|
|
|
build:
|
2023-08-11 07:44:04 +00:00
|
|
|
go build $(MAIN_PARAMS) $(MAIN)
|
|
|
|
|
|
|
|
ci_build_go118:
|
|
|
|
go build $(PARAMS) $(MAIN)
|
|
|
|
go build $(PARAMS) -tags "$(TAGS_GO118)" $(MAIN)
|
|
|
|
|
2024-02-10 04:01:09 +00:00
|
|
|
ci_build_go120:
|
|
|
|
go build $(PARAMS) $(MAIN)
|
|
|
|
go build $(PARAMS) -tags "$(TAGS_GO118),$(TAGS_GO120)" $(MAIN)
|
|
|
|
|
2023-08-11 07:44:04 +00:00
|
|
|
ci_build:
|
2022-08-12 14:53:46 +00:00
|
|
|
go build $(PARAMS) $(MAIN)
|
2023-08-11 07:44:04 +00:00
|
|
|
go build $(MAIN_PARAMS) $(MAIN)
|
2022-08-12 14:53:46 +00:00
|
|
|
|
2024-09-23 14:12:19 +00:00
|
|
|
generate_completions:
|
|
|
|
go run -v --tags generate,generate_completions $(MAIN)
|
|
|
|
|
2022-08-12 14:53:46 +00:00
|
|
|
install:
|
2023-09-16 13:36:06 +00:00
|
|
|
go build -o $(PREFIX)/bin/$(NAME) $(MAIN_PARAMS) $(MAIN)
|
2022-08-12 14:53:46 +00:00
|
|
|
|
|
|
|
fmt:
|
2022-08-13 10:36:49 +00:00
|
|
|
@gofumpt -l -w .
|
|
|
|
@gofmt -s -w .
|
2023-05-19 07:46:48 +00:00
|
|
|
@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" .
|
2022-08-12 14:53:46 +00:00
|
|
|
|
2022-08-14 16:25:49 +00:00
|
|
|
fmt_install:
|
|
|
|
go install -v mvdan.cc/gofumpt@latest
|
2023-02-09 13:01:48 +00:00
|
|
|
go install -v github.com/daixiang0/gci@latest
|
2022-08-12 14:53:46 +00:00
|
|
|
|
|
|
|
lint:
|
|
|
|
GOOS=linux golangci-lint run ./...
|
2022-08-17 12:15:35 +00:00
|
|
|
GOOS=android golangci-lint run ./...
|
2022-08-12 14:53:46 +00:00
|
|
|
GOOS=windows golangci-lint run ./...
|
|
|
|
GOOS=darwin golangci-lint run ./...
|
|
|
|
GOOS=freebsd golangci-lint run ./...
|
|
|
|
|
2022-08-14 16:25:49 +00:00
|
|
|
lint_install:
|
2022-08-21 05:03:19 +00:00
|
|
|
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
|
|
|
|
2022-08-22 10:53:47 +00:00
|
|
|
proto:
|
|
|
|
@go run ./cmd/internal/protogen
|
|
|
|
@gofumpt -l -w .
|
|
|
|
@gofumpt -l -w .
|
|
|
|
|
|
|
|
proto_install:
|
|
|
|
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
|
|
|
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
|
|
|
|
2022-08-26 08:33:12 +00:00
|
|
|
release:
|
2024-03-21 15:31:38 +00:00
|
|
|
go run ./cmd/internal/build goreleaser release --clean --skip publish
|
2022-08-26 08:33:12 +00:00
|
|
|
mkdir dist/release
|
2024-02-22 13:03:51 +00:00
|
|
|
mv dist/*.tar.gz \
|
|
|
|
dist/*.zip \
|
|
|
|
dist/*.deb \
|
|
|
|
dist/*.rpm \
|
|
|
|
dist/*_amd64.pkg.tar.zst \
|
|
|
|
dist/*_arm64.pkg.tar.zst \
|
|
|
|
dist/release
|
2023-08-27 13:14:10 +00:00
|
|
|
ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release
|
2023-10-21 04:00:00 +00:00
|
|
|
rm -r dist/release
|
2022-08-26 08:33:12 +00:00
|
|
|
|
2024-03-12 14:01:18 +00:00
|
|
|
release_repo:
|
|
|
|
go run ./cmd/internal/build goreleaser release -f .goreleaser.fury.yaml --clean
|
|
|
|
|
2022-08-26 08:33:12 +00:00
|
|
|
release_install:
|
2022-08-21 05:03:19 +00:00
|
|
|
go install -v github.com/tcnksm/ghr@latest
|
2022-08-14 16:25:49 +00:00
|
|
|
|
2023-08-30 09:35:40 +00:00
|
|
|
update_android_version:
|
2023-08-27 13:14:10 +00:00
|
|
|
go run ./cmd/internal/update_android_version
|
2023-08-30 09:35:40 +00:00
|
|
|
|
2023-08-31 06:56:01 +00:00
|
|
|
build_android:
|
2024-03-16 15:27:09 +00:00
|
|
|
cd ../sing-box-for-android && ./gradlew :app:clean :app:assemblePlayRelease :app:assembleOtherRelease && ./gradlew --stop
|
2023-08-31 06:56:01 +00:00
|
|
|
|
|
|
|
upload_android:
|
|
|
|
mkdir -p dist/release_android
|
2023-11-09 06:34:19 +00:00
|
|
|
cp ../sing-box-for-android/app/build/outputs/apk/play/release/*.apk dist/release_android
|
2024-02-16 05:28:58 +00:00
|
|
|
cp ../sing-box-for-android/app/build/outputs/apk/other/release/*-universal.apk dist/release_android
|
2023-08-27 13:14:10 +00:00
|
|
|
ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release_android
|
2023-08-31 06:56:01 +00:00
|
|
|
rm -rf dist/release_android
|
2023-08-27 13:14:10 +00:00
|
|
|
|
2023-08-31 06:56:01 +00:00
|
|
|
release_android: lib_android update_android_version build_android upload_android
|
2023-08-30 09:35:40 +00:00
|
|
|
|
2023-08-27 13:14:10 +00:00
|
|
|
publish_android:
|
2023-11-09 06:34:19 +00:00
|
|
|
cd ../sing-box-for-android && ./gradlew :app:publishPlayReleaseBundle
|
2023-11-02 18:20:35 +00:00
|
|
|
|
|
|
|
publish_android_appcenter:
|
2023-11-09 06:34:19 +00:00
|
|
|
cd ../sing-box-for-android && ./gradlew :app:appCenterAssembleAndUploadPlayRelease
|
2023-08-27 13:14:10 +00:00
|
|
|
|
2024-09-12 03:38:14 +00:00
|
|
|
|
|
|
|
# TODO: find why and remove `-destination 'generic/platform=iOS'`
|
2023-08-27 13:14:10 +00:00
|
|
|
build_ios:
|
|
|
|
cd ../sing-box-for-apple && \
|
|
|
|
rm -rf build/SFI.xcarchive && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild archive -scheme SFI -configuration Release -destination 'generic/platform=iOS' -archivePath build/SFI.xcarchive -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
upload_ios_app_store:
|
|
|
|
cd ../sing-box-for-apple && \
|
2023-10-21 04:00:00 +00:00
|
|
|
xcodebuild -exportArchive -archivePath build/SFI.xcarchive -exportOptionsPlist SFI/Upload.plist -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
release_ios: build_ios upload_ios_app_store
|
|
|
|
|
|
|
|
build_macos:
|
|
|
|
cd ../sing-box-for-apple && \
|
|
|
|
rm -rf build/SFM.xcarchive && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild archive -scheme SFM -configuration Release -archivePath build/SFM.xcarchive -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
upload_macos_app_store:
|
|
|
|
cd ../sing-box-for-apple && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild -exportArchive -archivePath build/SFM.xcarchive -exportOptionsPlist SFI/Upload.plist -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
release_macos: build_macos upload_macos_app_store
|
|
|
|
|
2024-09-12 03:38:14 +00:00
|
|
|
build_macos_standalone:
|
2023-08-27 13:14:10 +00:00
|
|
|
cd ../sing-box-for-apple && \
|
2024-09-17 10:47:20 +00:00
|
|
|
rm -rf build/SFM.System.xcarchive && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild archive -scheme SFM.System -configuration Release -archivePath build/SFM.System.xcarchive -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
2024-09-17 10:47:20 +00:00
|
|
|
build_macos_dmg:
|
2023-08-27 13:14:10 +00:00
|
|
|
rm -rf dist/SFM
|
2023-08-31 06:56:01 +00:00
|
|
|
mkdir -p dist/SFM
|
2023-08-27 13:14:10 +00:00
|
|
|
cd ../sing-box-for-apple && \
|
2024-09-17 10:47:20 +00:00
|
|
|
rm -rf build/SFM.System && \
|
|
|
|
rm -rf build/SFM.dmg && \
|
|
|
|
xcodebuild -exportArchive \
|
|
|
|
-archivePath "build/SFM.System.xcarchive" \
|
|
|
|
-exportOptionsPlist SFM.System/Export.plist -allowProvisioningUpdates \
|
|
|
|
-exportPath "build/SFM.System" && \
|
|
|
|
create-dmg \
|
|
|
|
--volname "sing-box" \
|
|
|
|
--volicon "build/SFM.System/SFM.app/Contents/Resources/AppIcon.icns" \
|
|
|
|
--icon "SFM.app" 0 0 \
|
|
|
|
--hide-extension "SFM.app" \
|
|
|
|
--app-drop-link 0 0 \
|
|
|
|
--skip-jenkins \
|
|
|
|
--notarize "notarytool-password" \
|
|
|
|
"../sing-box/dist/SFM/SFM.dmg" "build/SFM.System/SFM.app"
|
|
|
|
|
|
|
|
upload_macos_dmg:
|
2023-08-27 13:14:10 +00:00
|
|
|
cd dist/SFM && \
|
2024-09-17 10:47:20 +00:00
|
|
|
cp SFM.dmg "SFM-${VERSION}-universal.dmg" && \
|
|
|
|
ghr --replace --draft --prerelease "v${VERSION}" "SFM-${VERSION}-universal.dmg"
|
2023-08-27 13:14:10 +00:00
|
|
|
|
2024-09-17 10:47:20 +00:00
|
|
|
release_macos_standalone: build_macos_standalone build_macos_dmg upload_macos_dmg
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
build_tvos:
|
|
|
|
cd ../sing-box-for-apple && \
|
|
|
|
rm -rf build/SFT.xcarchive && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild archive -scheme SFT -configuration Release -archivePath build/SFT.xcarchive -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
upload_tvos_app_store:
|
|
|
|
cd ../sing-box-for-apple && \
|
2024-09-12 03:38:14 +00:00
|
|
|
xcodebuild -exportArchive -archivePath "build/SFT.xcarchive" -exportOptionsPlist SFI/Upload.plist -allowProvisioningUpdates
|
2023-08-27 13:14:10 +00:00
|
|
|
|
|
|
|
release_tvos: build_tvos upload_tvos_app_store
|
|
|
|
|
|
|
|
update_apple_version:
|
|
|
|
go run ./cmd/internal/update_apple_version
|
|
|
|
|
2024-10-05 02:35:55 +00:00
|
|
|
release_apple: lib_ios update_apple_version release_ios release_macos release_tvos release_macos_standalone
|
2023-08-30 09:35:40 +00:00
|
|
|
|
2023-08-31 06:56:01 +00:00
|
|
|
release_apple_beta: update_apple_version release_ios release_macos release_tvos
|
2023-08-30 09:35:40 +00:00
|
|
|
|
2022-08-12 14:53:46 +00:00
|
|
|
test:
|
2022-09-21 10:46:20 +00:00
|
|
|
@go test -v ./... && \
|
2022-09-14 04:56:45 +00:00
|
|
|
cd test && \
|
2022-08-22 04:02:16 +00:00
|
|
|
go mod tidy && \
|
2022-09-21 10:46:20 +00:00
|
|
|
go test -v -tags "$(TAGS_TEST)" .
|
2022-09-25 14:16:24 +00:00
|
|
|
|
2022-09-21 10:46:20 +00:00
|
|
|
test_stdio:
|
|
|
|
@go test -v ./... && \
|
|
|
|
cd test && \
|
|
|
|
go mod tidy && \
|
|
|
|
go test -v -tags "$(TAGS_TEST),force_stdio" .
|
2022-08-12 14:53:46 +00:00
|
|
|
|
2023-08-27 13:14:10 +00:00
|
|
|
lib_android:
|
2023-04-13 02:36:22 +00:00
|
|
|
go run ./cmd/internal/build_libbox -target android
|
|
|
|
|
2023-08-27 13:14:10 +00:00
|
|
|
lib_ios:
|
2023-04-13 02:36:22 +00:00
|
|
|
go run ./cmd/internal/build_libbox -target ios
|
|
|
|
|
2022-10-25 04:55:00 +00:00
|
|
|
lib:
|
2023-04-13 02:36:22 +00:00
|
|
|
go run ./cmd/internal/build_libbox -target android
|
|
|
|
go run ./cmd/internal/build_libbox -target ios
|
2022-10-25 04:55:00 +00:00
|
|
|
|
|
|
|
lib_install:
|
2024-09-10 15:04:44 +00:00
|
|
|
go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.4
|
|
|
|
go install -v github.com/sagernet/gomobile/cmd/gobind@v0.1.4
|
2022-10-25 04:55:00 +00:00
|
|
|
|
2023-11-09 09:04:08 +00:00
|
|
|
docs:
|
2024-06-24 02:10:49 +00:00
|
|
|
venv/bin/mkdocs serve
|
2023-11-09 09:04:08 +00:00
|
|
|
|
|
|
|
publish_docs:
|
2024-06-24 02:10:49 +00:00
|
|
|
venv/bin/mkdocs gh-deploy -m "Update" --force --ignore-version --no-history
|
2023-11-09 09:04:08 +00:00
|
|
|
|
|
|
|
docs_install:
|
2024-06-24 02:10:49 +00:00
|
|
|
python -m venv venv
|
|
|
|
source ./venv/bin/activate && pip install --force-reinstall mkdocs-material=="9.*" mkdocs-static-i18n=="1.2.*"
|
|
|
|
|
2022-08-12 14:53:46 +00:00
|
|
|
clean:
|
2022-09-25 14:16:24 +00:00
|
|
|
rm -rf bin dist sing-box
|
2022-08-12 14:53:46 +00:00
|
|
|
rm -f $(shell go env GOPATH)/sing-box
|
|
|
|
|
|
|
|
update:
|
|
|
|
git fetch
|
|
|
|
git reset FETCH_HEAD --hard
|
|
|
|
git clean -fdx
|