Debian Codegraph @

Makefile

raw
1 # Copyright 2013 Prometheus Team
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 all:
15 $(MAKE) go
16 $(MAKE) build
17
18 GO_FILE := go/metrics.pb.go
19 PROTO_FILE := io/prometheus/client/metrics.proto
20
21 # Need to be on a previous version that doesn't cause the updated WKT go_package values to be added.
22 PROTOC_VERSION := 3.13.0
23 # This has been around for a while.
24 PROTOC_GEN_GO_VERSION := v1.3.5
25
26 # There are no protobuf releases for Darwin ARM so for
27 # now we always use the x86_64 release through Rosetta.
28 UNAME_OS := $(shell uname -s)
29 UNAME_ARCH := $(shell uname -m)
30 ifeq ($(UNAME_OS),Darwin)
31 PROTOC_OS := osx
32 PROTOC_ARCH := x86_64
33 endif
34 ifeq ($(UNAME_OS),Linux)
35 PROTOC_OS = linux
36 PROTOC_ARCH := $(UNAME_ARCH)
37 endif
38 PROTOC := tmp/versions/protoc/$(PROTOC_VERSION)
39 PROTOC_BIN := tmp/bin/protoc
40 PROTOC_INCLUDE := tmp/include/google
41 $(PROTOC):
42 @if ! command -v curl >/dev/null 2>/dev/null; then echo "error: curl must be installed" >&2; exit 1; fi
43 @if ! command -v unzip >/dev/null 2>/dev/null; then echo "error: unzip must be installed" >&2; exit 1; fi
44 @rm -f $(PROTOC_BIN)
45 @rm -rf $(PROTOC_INCLUDE)
46 @mkdir -p $(dir $(PROTOC_BIN)) $(dir $(PROTOC_INCLUDE))
47 $(eval PROTOC_TMP := $(shell mktemp -d))
48 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
49 cd $(PROTOC_TMP); unzip protoc.zip && mv bin/protoc $(PWD)/$(PROTOC_BIN) && mv include/google $(PWD)/$(PROTOC_INCLUDE)
50 @rm -rf $(PROTOC_TMP)
51 @rm -rf $(dir $(PROTOC))
52 @mkdir -p $(dir $(PROTOC))
53 @touch $(PROTOC)
54
55 PROTOC_GEN_GO := tmp/versions/protoc-gen-go/$(PROTOC_GEN_GO_VERSION)
56 PROTOC_GEN_GO_BIN := tmp/bin/protoc-gen-go
57 $(PROTOC_GEN_GO):
58 @rm -f $(PROTOC_GEN_GO_BIN)
59 @mkdir -p $(dir $(PROTOC_GEN_GO_BIN))
60 $(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d))
61 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)
62 @rm -rf $(PROTOC_GEN_GO_TMP)
63 @rm -rf $(dir $(PROTOC_GEN_GO))
64 @mkdir -p $(dir $(PROTOC_GEN_GO))
65 @touch $(PROTOC_GEN_GO)
66
67 go: $(GO_FILE)
68
69 $(GO_FILE): $(PROTO_FILE) $(PROTOC_GEN_GO) $(PROTOC)
70 @rm -rf $(dir $(GO_FILE)) tmp/go
71 @mkdir -p $(dir $(GO_FILE)) tmp/go
72 PATH=$(PWD)/tmp/bin:$$PATH protoc -I tmp/include -I . --go_out=paths=source_relative:tmp/go $(PROTO_FILE)
73 @mv tmp/go/$(patsubst %.proto,%.pb.go,$(PROTO_FILE)) $(GO_FILE)
74
75 build: $(GO_FILE)
76 go build ./go
77
78 clean:
79 -rm -rf go tmp
80
81 .PHONY: all clean go build