github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/Makefile (about)

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