github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/makefile (about) 1 MODULE := github.com/Asutorufa/yuhaiin 2 3 BUILD_COMMIT := $(shell git rev-parse --short HEAD) 4 BUILD_VERSION := $(shell git describe --tags) 5 ifeq ($(OS),Windows_NT) 6 BUILD_ARCH := Windows_NT 7 BUILD_TIME := $(shell powershell Get-Date) 8 else 9 BUILD_ARCH := $(shell uname -a) 10 BUILD_TIME := $(shell date) 11 endif 12 13 CGO_ENABLED := 0 14 15 GO=$(shell command -v go | head -n1) 16 17 GO_LDFLAGS= -s -w -buildid= 18 GO_LDFLAGS += -X "$(MODULE)/internal/version.Version=$(BUILD_VERSION)" 19 GO_LDFLAGS += -X "$(MODULE)/internal/version.GitCommit=$(BUILD_COMMIT)" 20 GO_LDFLAGS += -X "$(MODULE)/internal/version.BuildArch=$(BUILD_ARCH)" 21 GO_LDFLAGS += -X "$(MODULE)/internal/version.BuildTime=$(BUILD_TIME)" 22 23 GO_GCFLAGS= 24 # GO_GCFLAGS= -m 25 26 GO_BUILD_CMD=CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags='$(GO_LDFLAGS)' -gcflags='$(GO_GCFLAGS)' -trimpath 27 28 # AMD64v3 https://github.com/golang/go/wiki/MinimumRequirements#amd64 29 LINUX_AMD64=GOOS=linux GOARCH=amd64 30 LINUX_AMD64v3=GOOS=linux GOARCH=amd64 GOAMD64=v3 31 DARWIN_AMD64=GOOS=darwin GOARCH=amd64 32 DARWIN_AMD64v3=GOOS=darwin GOARCH=amd64 GOAMD64=v3 33 WINDOWS_AMD64=GOOS=windows GOARCH=amd64 34 WINDOWS_AMD64v3=GOOS=windows GOARCH=amd64 GOAMD64=v3 35 LINUX_MIPSLE=GOOS=linux GOARCH=mipsle GOMIPS=softfloat 36 ANDROID_ARM64=GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang 37 ANDROID_AMD64=GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang 38 39 YUHAIIN=-v ./cmd/yuhaiin/... 40 CLI=-v ./cmd/cli/... 41 DNSRELAY= -v ./cmd/dnsrelay/... 42 43 .PHONY: test 44 test: 45 @echo "test" 46 @echo ${GO_CMD} 47 48 .PHONY: vet 49 vet: 50 $(GO) vet $(shell go list ./... | grep -v '/scripts/' | grep -v 'pkg/net/proxy/tun/tun2socket/checksum') 51 52 .PHONY: yuhaiin 53 yuhaiin: 54 $(GO_BUILD_CMD) -pgo=./cmd/yuhaiin/yuhaiin.pprof -tags "debug" $(YUHAIIN) 55 56 57 .PHONY: yuhaiin_lite 58 yuhaiin_lite: 59 $(GO_BUILD_CMD) -pgo=./cmd/yuhaiin/yuhaiin.pprof -tags "debug,lite" $(YUHAIIN) 60 61 define build 62 $(eval ARGS := $(subst -, ,$@)) 63 $(eval OS := $(word 2, $(ARGS))) 64 $(eval ARCH := $(word 3, $(ARGS))) 65 $(eval MODE := $(word 4, $(ARGS))) 66 67 $(if $(filter amd64v3, $(ARCH)),$(eval AMD64V3 := v3),) 68 $(if $(filter amd64v3, $(ARCH)),$(eval ARCH := amd64),) 69 $(if $(filter mipsle, $(ARCH)),$(eval MIPS := softfloat),) 70 $(if $(filter lite, $(MODE)),$(eval SUFFIX := _lite),) 71 $(if $(filter windows, $(OS)),$(if $(SUFFIX), $(eval SUFFIX := $(addsuffix .exe, $(SUFFIX))), $(eval SUFFIX := .exe)),) 72 73 $(info OS: $(OS), ARCH: $(ARCH), MODE: $(if $(MODE),$(MODE),full), SUFFIX: $(SUFFIX)) 74 endef 75 76 .PHONY: yuhaiin-% 77 yuhaiin-%: 78 $(build) 79 GOOS=$(OS) GOARCH=$(ARCH) GOMIPS=$(MIPS) GOAMD64=$(AMD64V3) $(GO_BUILD_CMD) -pgo=./cmd/yuhaiin/yuhaiin.pprof -tags 'debug,$(MODE)' -o yuhaiin_$(OS)_$(ARCH)$(AMD64V3)$(SUFFIX) $(YUHAIIN) 80 81 .PHONY: yuhaiin_android 82 yuhaiin_android: 83 $(ANDROID_ARM64) $(GO_BUILD_CMD) -pgo=./cmd/yuhaiin/yuhaiin.pprof -o ./cmd/android/main/jniLibs/arm64-v8a/libyuhaiin.so -v ./cmd/android/main/... 84 $(ANDROID_AMD64) $(GO_BUILD_CMD) -pgo=./cmd/yuhaiin/yuhaiin.pprof -o ./cmd/android/main/jniLibs/x86_64/libyuhaiin.so -v ./cmd/android/main/... 85 86 .PHONY: yuhaiin_android_aar 87 yuhaiin_android_aar: 88 gomobile bind -ldflags='$(GO_LDFLAGS)' -gcflags='$(GO_GCFLAGS)' -trimpath -target="android/arm64,android/amd64" -androidapi 21 -o yuhaiin.aar -v ./cmd/android/ 89 90 .PHONY: install 91 install: build cli 92 install -s -b -v -m 644 yuhaiin ${HOME}/.local/bin/yuhaiin 93 install -b -v -m 644 scripts/systemd/yuhaiin.service ${HOME}/.config/systemd/user/yuhaiin.service 94 echo "add ${HOME}/.local/bin to PATH env" 95 96 .PHONY: gofmt 97 gofmt: ## Verify the source code gofmt 98 find . -name '*.go' -type f \ 99 -not \( \ 100 -name '.golangci.yml' -o \ 101 -name 'makefile' -o \ 102 -path './vendor/*' -prune -o \ 103 -path './contrib/*' -prune \ 104 -path './pkg/sysproxy/dll_windows/*' \ 105 \) -exec gofmt -d -e -s -w {} \+ 106 git diff --exit-code