forked from prometheus/client_model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (69 loc) · 2.92 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
# Copyright 2013 Prometheus Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
all:
$(MAKE) go
$(MAKE) build
GO_FILE := go/metrics.pb.go
PROTO_FILE := io/prometheus/client/metrics.proto
# Need to be on a previous version that doesn't cause the updated WKT go_package values to be added.
PROTOC_VERSION := 3.13.0
# This has been around for a while.
PROTOC_GEN_GO_VERSION := v1.3.5
# There are no protobuf releases for Darwin ARM so for
# now we always use the x86_64 release through Rosetta.
UNAME_OS := $(shell uname -s)
UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_OS),Darwin)
PROTOC_OS := osx
PROTOC_ARCH := x86_64
endif
ifeq ($(UNAME_OS),Linux)
PROTOC_OS = linux
PROTOC_ARCH := $(UNAME_ARCH)
endif
PROTOC := tmp/versions/protoc/$(PROTOC_VERSION)
PROTOC_BIN := tmp/bin/protoc
PROTOC_INCLUDE := tmp/include/google
$(PROTOC):
@if ! command -v curl >/dev/null 2>/dev/null; then echo "error: curl must be installed" >&2; exit 1; fi
@if ! command -v unzip >/dev/null 2>/dev/null; then echo "error: unzip must be installed" >&2; exit 1; fi
@rm -f $(PROTOC_BIN)
@rm -rf $(PROTOC_INCLUDE)
@mkdir -p $(dir $(PROTOC_BIN)) $(dir $(PROTOC_INCLUDE))
$(eval PROTOC_TMP := $(shell mktemp -d))
cd $(PROTOC_TMP); curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip -o protoc.zip
cd $(PROTOC_TMP); unzip protoc.zip && mv bin/protoc $(PWD)/$(PROTOC_BIN) && mv include/google $(PWD)/$(PROTOC_INCLUDE)
@rm -rf $(PROTOC_TMP)
@rm -rf $(dir $(PROTOC))
@mkdir -p $(dir $(PROTOC))
@touch $(PROTOC)
PROTOC_GEN_GO := tmp/versions/protoc-gen-go/$(PROTOC_GEN_GO_VERSION)
PROTOC_GEN_GO_BIN := tmp/bin/protoc-gen-go
$(PROTOC_GEN_GO):
@rm -f $(PROTOC_GEN_GO_BIN)
@mkdir -p $(dir $(PROTOC_GEN_GO_BIN))
$(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d))
cd $(PROTOC_GEN_GO_TMP); GOBIN=$(PWD)/$(dir $(PROTOC_GEN_GO_BIN)) go get github.com/golang/protobuf/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
@rm -rf $(PROTOC_GEN_GO_TMP)
@rm -rf $(dir $(PROTOC_GEN_GO))
@mkdir -p $(dir $(PROTOC_GEN_GO))
@touch $(PROTOC_GEN_GO)
go: $(GO_FILE)
$(GO_FILE): $(PROTO_FILE) $(PROTOC_GEN_GO) $(PROTOC)
@rm -rf $(dir $(GO_FILE)) tmp/go
@mkdir -p $(dir $(GO_FILE)) tmp/go
PATH=$(PWD)/tmp/bin:$$PATH protoc -I tmp/include -I . --go_out=paths=source_relative:tmp/go $(PROTO_FILE)
@mv tmp/go/$(patsubst %.proto,%.pb.go,$(PROTO_FILE)) $(GO_FILE)
build: $(GO_FILE)
go build ./go
clean:
-rm -rf go tmp
.PHONY: all clean go build