forked from fetchai/cosmos-consensus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.mk
125 lines (103 loc) · 3.17 KB
/
tools.mk
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
###
# Find OS and Go environment
# GO contains the Go binary
# FS contains the OS file separator
###
ifeq ($(OS),Windows_NT)
GO := $(shell where go.exe 2> NUL)
FS := "\\"
else
GO := $(shell command -v go 2> /dev/null)
FS := "/"
endif
ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif
GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
###
# Functions
###
go_get = $(if $(findstring Windows_NT,$(OS)),\
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
,\
mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
(test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
)\
cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
###
# Go tools
###
BIN ?= /usr/local/bin
UNAME_S ?= $(shell uname -s)
UNAME_M ?= $(shell uname -m)
TOOLS_DESTDIR ?= $(GOPATH)/bin
BUF_VERSION ?= 0.7.0
CERTSTRAP = $(TOOLS_DESTDIR)/certstrap
PROTOBUF = $(TOOLS_DESTDIR)/protoc
GOODMAN = $(TOOLS_DESTDIR)/goodman
all: tools
.PHONY: all
tools: certstrap protobuf goodman
.PHONY: tools
check: check_tools
.PHONY: check
check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
.PHONY: check_tools
certstrap: $(CERTSTRAP)
$(CERTSTRAP):
@echo "Get Certstrap"
@go get github.com/square/[email protected]
.PHONY: certstrap
protobuf: $(PROTOBUF)
$(PROTOBUF):
@echo "Get GoGo Protobuf"
@go get github.com/gogo/protobuf/[email protected]
.PHONY: protobuf
buf:
@echo "Installing buf..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/buf-$(UNAME_S)-$(UNAME_M)" \
-o "$(BIN)/buf" && \
chmod +x "$(BIN)/buf"
.PHONY: buf
goodman: $(GOODMAN)
$(GOODMAN):
@echo "Get Goodman"
@go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
.PHONY: goodman
tools-clean:
rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
rm -f tools-stamp
rm -rf /usr/local/include/google/protobuf
rm -f /usr/local/bin/protoc
.PHONY: tooks-clean
###
# Non Go tools
###
# Choose protobuf binary based on OS (only works for 64bit Linux and Mac).
# NOTE: On Mac, installation via brew (brew install protoc) might be favorable.
PROTOC_ZIP=""
ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
PROTOC_ZIP="protoc-3.10.1-linux-x86_64.zip"
endif
ifeq ($(UNAME_S),Darwin)
PROTOC_ZIP="protoc-3.10.1-osx-x86_64.zip"
endif
endif
protoc:
@echo "Get Protobuf"
@echo "In case of any errors, please install directly from https://github.com/protocolbuffers/protobuf/releases"
@curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/$(PROTOC_ZIP)
@unzip -o $(PROTOC_ZIP) -d /usr/local bin/protoc
@unzip -o $(PROTOC_ZIP) -d /usr/local 'include/*'
@rm -f $(PROTOC_ZIP)
.PHONY: protoc