-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
86 lines (68 loc) · 2.72 KB
/
Makefile
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright (C) 2022 Jingli Chen (Wine93), NetEase Inc.
.PHONY: build debug init proto clean install_grpc_protobuf
version=2.0.1
GITHUB_PROXY="https://ghproxy.com/"
PROTOC_VERSION= 21.8
PROTOC_GEN_GO_VERSION= "v1.28"
PROTOC_GEN_GO_GRPC_VERSION= "v1.2"
# go env
GOPROXY :=https://goproxy.cn,direct
GOOS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
GOARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
CGO_LDFLAGS := "-static"
CC := musl-gcc
GOENV := GO111MODULE=on
GOENV += GOPROXY=$(GOPROXY)
GOENV += CC=$(CC)
GOENV += CGO_ENABLED=1 CGO_LDFLAGS=$(CGO_LDFLAGS)
GOENV += GOOS=$(GOOS) GOARCH=$(GOARCH)
# go
GO := go
# output
OUTPUT := sbin/dingo
DAEMON_OUTPUT := sbin/daemon
# version
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_DIRTY=$(shell test -n "`git status -s | grep -v third-party`" && echo "+CHANGES" || true)
BUILD_DATE=$(shell date '+%Y-%m-%dT%H:%M:%SZ')
VERSION_FLAG := -X github.com/dingodb/dingofs-tools/pkg/cli/command/version.Version=$(version)
VERSION_FLAG += -X github.com/dingodb/dingofs-tools/pkg/cli/command/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}
VERSION_FLAG += -X github.com/dingodb/dingofs-tools/pkg/cli/command/version.BuildDate=${BUILD_DATE}
# build flags
CGO_BUILD_LDFLAGS := -s -w -linkmode external
CGO_BUILD_LDFLAGS += -extldflags "-static -fpic"
CGO_BUILD_FLAG += -ldflags '$(CGO_BUILD_LDFLAGS) $(VERSION_FLAG)'
BUILD_FLAGS := -a
BUILD_FLAGS += -trimpath
BUILD_FLAGS += $(CGO_BUILD_FLAG)
BUILD_FLAGS += $(EXTRA_FLAGS)
# debug flags
GCFLAGS := "all=-N -l"
CGO_DEBUG_LDFLAGS := -linkmode external
CGO_DEBUG_LDFLAGS += -extldflags "-static -fpic"
CGO_DEBUG_FLAG += -ldflags '$(CGO_DEBUG_LDFLAGS) $(VERSION_FLAG)'
DEBUG_FLAGS := -gcflags=$(GCFLAGS)
DEBUG_FLAGS += $(CGO_DEBUG_FLAG)
# packages
PACKAGES := $(PWD)/cmd/dingo/main.go
DAEMON_PACKAGES := $(PWD)/cmd/daemon/main.go
build: proto
$(GOENV) $(GO) build -o $(OUTPUT) $(BUILD_FLAGS) $(PACKAGES)
$(GOENV) $(GO) build -o $(DAEMON_OUTPUT) $(BUILD_FLAGS) $(DAEMON_PACKAGES)
debug: proto
$(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES)
$(GOENV) $(GO) build -o $(DAEMON_OUTPUT) $(DEBUG_FLAGS) $(DAEMON_PACKAGES)
init: proto
go mod init github.com/dingodb/dingofs-tools
go mod tidy
proto: install_grpc_protobuf
@bash mk-proto.sh
install_grpc_protobuf:
# wget ${GITHUB_PROXY}https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
# && unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip "bin/protoc" -d /usr/ \
# && rm protoc-${PROTOC_VERSION}-linux-x86_64.zip
go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
clean:
rm -rf sbin
rm -rf proto/*