-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (47 loc) · 1.62 KB
/
Copy pathMakefile
File metadata and controls
64 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
.PHONY: build build-all clean test lint fmt vet install
# 二进制名与 cmd/resource-holder 目录一致(Go 社区常见约定)
BINARY := resource-holder
MAIN_PKG := ./cmd/resource-holder
MODULE_PATH := github.com/soraclub/resource-holder
OUTPUT_DIR := ./bin
DIST_DIR := ./dist
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X $(MODULE_PATH)/internal/cli.Version=$(VERSION)
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
build:
@echo "Building $(BINARY) $(VERSION) ($(GOOS)/$(GOARCH))..."
@mkdir -p $(OUTPUT_DIR)
@go build -trimpath -ldflags "$(LDFLAGS)" -o $(OUTPUT_DIR)/$(BINARY) $(MAIN_PKG)
@echo "-> $(OUTPUT_DIR)/$(BINARY)"
# 发布用交叉编译产物:dist/resource-holder_<os>_<arch>[.exe]
build-all: build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 build-windows-amd64
define cross_build
@echo "Building $(BINARY) $(VERSION) ($(1)/$(2))..."
@mkdir -p $(DIST_DIR)
@GOOS=$(1) GOARCH=$(2) go build -trimpath -ldflags "$(LDFLAGS)" \
-o $(DIST_DIR)/$(BINARY)_$(1)_$(2)$(3) $(MAIN_PKG)
endef
build-linux-amd64:
$(call cross_build,linux,amd64,)
build-linux-arm64:
$(call cross_build,linux,arm64,)
build-darwin-amd64:
$(call cross_build,darwin,amd64,)
build-darwin-arm64:
$(call cross_build,darwin,arm64,)
build-windows-amd64:
$(call cross_build,windows,amd64,.exe)
test:
@go test -race -cover ./...
lint:
@golangci-lint run ./...
fmt:
@gofmt -w .
vet:
@go vet ./...
install:
@go install -trimpath -ldflags "$(LDFLAGS)" $(MAIN_PKG)
clean:
@rm -rf $(OUTPUT_DIR) $(DIST_DIR)
@echo "Cleaned $(OUTPUT_DIR) and $(DIST_DIR)"