From 2fedceeb40caf50891151afddaeb6de8ab02003a Mon Sep 17 00:00:00 2001 From: peter-tank <30540412+peter-tank@users.noreply.github.com> Date: Sun, 12 Jul 2020 12:00:00 +0000 Subject: [PATCH] build release from Makefile Signed-off-by: peter-tank <30540412+peter-tank@users.noreply.github.com> --- .github/workflows/release-build.yml | 7 +- Makefile | 123 ++++++++++++++++++++++------ release.sh | 44 ---------- 3 files changed, 100 insertions(+), 74 deletions(-) delete mode 100755 release.sh diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 40586f9..beb4d6d 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -21,10 +21,11 @@ jobs: git checkout $tag_name - name: Build run: | - ./release.sh + make geosite.dat geoip.dat + make release -j$(nproc) set -x assets=() - for asset in ./release/*; do + for asset in ./*.zip; do assets+=("-a" "$asset") done tag_name="${GITHUB_REF##*/}" @@ -35,4 +36,4 @@ jobs: uses: actions/upload-artifact@v1 with: name: dist-release - path: ./release \ No newline at end of file + path: ./bin \ No newline at end of file diff --git a/Makefile b/Makefile index c7a8b7f..3cd4489 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,41 @@ -NAME=trojan-go -PACKAGE_NAME=github.com/p4gefau1t/trojan-go -VERSION=`git describe --dirty` -COMMIT=`git rev-parse HEAD` +NAME := trojan-go +PACKAGE_NAME := github.com/p4gefau1t/trojan-go +VERSION := `echo git describe --dirty` +COMMIT := `echo git rev-parse HEAD` -BIN_DIR=bin -VAR_SETTING=-X $(PACKAGE_NAME)/constant.Version=$(VERSION) -X $(PACKAGE_NAME)/constant.Commit=$(COMMIT) -GOBUILD=CGO_ENABLED=0 go build -tags "full" -ldflags="-s -w $(VAR_SETTING)" -o $(BIN_DIR)/$(NAME) +GOPATH ?= +ifneq ($(strip $(GOPATH)), ) + GO_DIR := $(GOPATH)/bin/ +endif -normal: clean - $(GOBUILD) +MAKEDEPEND = $(GODIR)go +GO_MINIMUM := go1.14 +GO_VERSION != $(GO_DIR)go version | cut -d' ' -f3 +GOMETALINTER := $(GO_DIR)gometalinter + +PLATFORM := linux +BIN_DIR := bin +VAR_SETTING := -X $(PACKAGE_NAME)/constant.Version=$(VERSION) -X $(PACKAGE_NAME)/constant.Commit=$(COMMIT) +GOBUILD = env CGO_ENABLED=0 $(GO_DIR)go build -tags "full" -ldflags="-s -w $(VAR_SETTING)" -o $(BIN_DIR) + +.PHONY: depends trojan-go release +normal: clean trojan-go + +depends: geosite.dat geoip.dat + $(info GO_DIR: $(GO_DIR)) + $(info Current Go Verison: $(GO_VERSION)) +ifneq ($(GO_VERSION), $(lastword $(sort $(GO_MINIMUM) $(GO_VERSION)))) + $(error Requires $(GO_MINIMUM) for module fingerprint/tls) +endif + +realclean: distclean + rm -f *.dat + +distclean: clean + rm -f *.zip clean: - -rm -rf $(BIN_DIR) + rm -rf $(BIN_DIR) geoip.dat: wget https://github.com/v2ray/geoip/raw/release/geoip.dat @@ -19,6 +43,18 @@ geoip.dat: geosite.dat: wget https://github.com/v2ray/domain-list-community/raw/release/dlc.dat -O geosite.dat +lint: + $(GO_DIR)go get -u github.com/alecthomas/gometalinter + $(GOMETALINTER) --install &> /dev/null + $(GOMETALINTER) ./... --vendor + +test: depends + @$(GO_DIR)go test ./... + +trojan-go: depends + mkdir -p $(BIN_DIR) + $(GOBUILD) + install: $(BIN_DIR)/$(NAME) geoip.dat geosite.dat mkdir -p /etc/$(NAME) mkdir -p /usr/share/$(NAME) @@ -42,53 +78,86 @@ uninstall: rm /usr/bin/geoip.dat rm /usr/bin/geosite.dat +%.zip: % geosite.dat geoip.dat + @zip -du $(NAME)-$@ -j $(BIN_DIR)/$