github.com/sagernet/sing-box@v1.9.0-rc.20/Makefile (about)

     1  NAME = sing-box
     2  COMMIT = $(shell git rev-parse --short HEAD)
     3  TAGS_GO118 = with_gvisor,with_dhcp,with_wireguard,with_reality_server,with_clash_api
     4  TAGS_GO120 = with_quic,with_utls
     5  TAGS_GO121 = with_ech
     6  TAGS ?= $(TAGS_GO118),$(TAGS_GO120),$(TAGS_GO121)
     7  TAGS_TEST ?= with_gvisor,with_quic,with_wireguard,with_grpc,with_ech,with_utls,with_reality_server
     8  
     9  GOHOSTOS = $(shell go env GOHOSTOS)
    10  GOHOSTARCH = $(shell go env GOHOSTARCH)
    11  VERSION=$(shell CGO_ENABLED=0 GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) go run ./cmd/internal/read_tag)
    12  
    13  PARAMS = -v -trimpath -ldflags "-X 'github.com/sagernet/sing-box/constant.Version=$(VERSION)' -s -w -buildid="
    14  MAIN_PARAMS = $(PARAMS) -tags $(TAGS)
    15  MAIN = ./cmd/sing-box
    16  PREFIX ?= $(shell go env GOPATH)
    17  
    18  .PHONY: test release docs build
    19  
    20  build:
    21  	go build $(MAIN_PARAMS) $(MAIN)
    22  
    23  ci_build_go118:
    24  	go build $(PARAMS) $(MAIN)
    25  	go build $(PARAMS) -tags "$(TAGS_GO118)" $(MAIN)
    26  
    27  ci_build_go120:
    28  	go build $(PARAMS) $(MAIN)
    29  	go build $(PARAMS) -tags "$(TAGS_GO118),$(TAGS_GO120)" $(MAIN)
    30  
    31  ci_build:
    32  	go build $(PARAMS) $(MAIN)
    33  	go build $(MAIN_PARAMS) $(MAIN)
    34  
    35  install:
    36  	go build -o $(PREFIX)/bin/$(NAME) $(MAIN_PARAMS) $(MAIN)
    37  
    38  fmt:
    39  	@gofumpt -l -w .
    40  	@gofmt -s -w .
    41  	@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" .
    42  
    43  fmt_install:
    44  	go install -v mvdan.cc/gofumpt@latest
    45  	go install -v github.com/daixiang0/gci@latest
    46  
    47  lint:
    48  	GOOS=linux golangci-lint run ./...
    49  	GOOS=android golangci-lint run ./...
    50  	GOOS=windows golangci-lint run ./...
    51  	GOOS=darwin golangci-lint run ./...
    52  	GOOS=freebsd golangci-lint run ./...
    53  
    54  lint_install:
    55  	go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
    56  
    57  proto:
    58  	@go run ./cmd/internal/protogen
    59  	@gofumpt -l -w .
    60  	@gofumpt -l -w .
    61  
    62  proto_install:
    63  	go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
    64  	go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    65  
    66  release:
    67  	go run ./cmd/internal/build goreleaser release --clean --skip publish
    68  	mkdir dist/release
    69  	mv dist/*.tar.gz \
    70  		dist/*.zip \
    71  		dist/*.deb \
    72  		dist/*.rpm \
    73  		dist/*_amd64.pkg.tar.zst \
    74  		dist/*_amd64v3.pkg.tar.zst \
    75  		dist/*_arm64.pkg.tar.zst \
    76  		dist/release
    77  	ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release
    78  	rm -r dist/release
    79  
    80  release_repo:
    81  	go run ./cmd/internal/build goreleaser release -f .goreleaser.fury.yaml --clean
    82  
    83  release_install:
    84  	go install -v github.com/tcnksm/ghr@latest
    85  
    86  update_android_version:
    87  	go run ./cmd/internal/update_android_version
    88  
    89  build_android:
    90  	cd ../sing-box-for-android && ./gradlew :app:clean :app:assemblePlayRelease :app:assembleOtherRelease && ./gradlew --stop
    91  
    92  upload_android:
    93  	mkdir -p dist/release_android
    94  	cp ../sing-box-for-android/app/build/outputs/apk/play/release/*.apk dist/release_android
    95  	cp ../sing-box-for-android/app/build/outputs/apk/other/release/*-universal.apk dist/release_android
    96  	ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release_android
    97  	rm -rf dist/release_android
    98  
    99  release_android: lib_android update_android_version build_android upload_android
   100  
   101  publish_android:
   102  	cd ../sing-box-for-android && ./gradlew :app:publishPlayReleaseBundle
   103  
   104  publish_android_appcenter:
   105  	cd ../sing-box-for-android && ./gradlew :app:appCenterAssembleAndUploadPlayRelease
   106  
   107  build_ios:
   108  	cd ../sing-box-for-apple && \
   109  	rm -rf build/SFI.xcarchive && \
   110  	xcodebuild archive -scheme SFI -configuration Release -archivePath build/SFI.xcarchive
   111  
   112  upload_ios_app_store:
   113  	cd ../sing-box-for-apple && \
   114  	xcodebuild -exportArchive -archivePath build/SFI.xcarchive -exportOptionsPlist SFI/Upload.plist -allowProvisioningUpdates
   115  
   116  release_ios: build_ios upload_ios_app_store
   117  
   118  build_macos:
   119  	cd ../sing-box-for-apple && \
   120  	rm -rf build/SFM.xcarchive && \
   121  	xcodebuild archive -scheme SFM -configuration Release -archivePath build/SFM.xcarchive
   122  
   123  upload_macos_app_store:
   124  	cd ../sing-box-for-apple && \
   125  	xcodebuild -exportArchive -archivePath build/SFM.xcarchive -exportOptionsPlist SFI/Upload.plist  -allowProvisioningUpdates
   126  
   127  release_macos: build_macos upload_macos_app_store
   128  
   129  build_macos_independent:
   130  	cd ../sing-box-for-apple && \
   131  	rm -rf build/SFT.System.xcarchive && \
   132  	xcodebuild archive -scheme SFM.System -configuration Release -archivePath build/SFM.System.xcarchive
   133  
   134  notarize_macos_independent:
   135  	cd ../sing-box-for-apple && \
   136  	xcodebuild -exportArchive -archivePath "build/SFM.System.xcarchive" -exportOptionsPlist SFM.System/Upload.plist  -allowProvisioningUpdates
   137  
   138  wait_notarize_macos_independent:
   139  	sleep 60
   140  
   141  export_macos_independent:
   142  	rm -rf dist/SFM
   143  	mkdir -p dist/SFM
   144  	cd ../sing-box-for-apple && \
   145  	xcodebuild -exportNotarizedApp -archivePath build/SFM.System.xcarchive -exportPath "../sing-box/dist/SFM"
   146  
   147  upload_macos_independent:
   148  	cd dist/SFM && \
   149  	rm -f *.zip && \
   150  	zip -ry "SFM-${VERSION}-universal.zip" SFM.app && \
   151  	ghr --replace --draft --prerelease "v${VERSION}" *.zip
   152  
   153  release_macos_independent: build_macos_independent notarize_macos_independent wait_notarize_macos_independent export_macos_independent upload_macos_independent
   154  
   155  build_tvos:
   156  	cd ../sing-box-for-apple && \
   157  	rm -rf build/SFT.xcarchive && \
   158  	xcodebuild archive -scheme SFT -configuration Release -archivePath build/SFT.xcarchive
   159  
   160  upload_tvos_app_store:
   161  	cd ../sing-box-for-apple && \
   162  	xcodebuild -exportArchive -archivePath "build/SFT.xcarchive" -exportOptionsPlist SFI/Upload.plist  -allowProvisioningUpdates
   163  
   164  release_tvos: build_tvos upload_tvos_app_store
   165  
   166  update_apple_version:
   167  	go run ./cmd/internal/update_apple_version
   168  
   169  release_apple: lib_ios update_apple_version release_ios release_macos release_tvos release_macos_independent
   170  
   171  release_apple_beta: update_apple_version release_ios release_macos release_tvos
   172  
   173  test:
   174  	@go test -v ./... && \
   175  	cd test && \
   176  	go mod tidy && \
   177  	go test -v -tags "$(TAGS_TEST)" .
   178  
   179  test_stdio:
   180  	@go test -v ./... && \
   181  	cd test && \
   182  	go mod tidy && \
   183  	go test -v -tags "$(TAGS_TEST),force_stdio" .
   184  
   185  lib_android:
   186  	go run ./cmd/internal/build_libbox -target android
   187  
   188  lib_ios:
   189  	go run ./cmd/internal/build_libbox -target ios
   190  
   191  lib:
   192  	go run ./cmd/internal/build_libbox -target android
   193  	go run ./cmd/internal/build_libbox -target ios
   194  
   195  lib_install:
   196  	go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.3
   197  	go install -v github.com/sagernet/gomobile/cmd/gobind@v0.1.3
   198  
   199  docs:
   200  	mkdocs serve
   201  
   202  publish_docs:
   203  	mkdocs gh-deploy -m "Update" --force --ignore-version --no-history
   204  
   205  docs_install:
   206  	pip install --force-reinstall mkdocs-material=="9.*" mkdocs-static-i18n=="1.2.*"
   207  clean:
   208  	rm -rf bin dist sing-box
   209  	rm -f $(shell go env GOPATH)/sing-box
   210  
   211  update:
   212  	git fetch
   213  	git reset FETCH_HEAD --hard
   214  	git clean -fdx