| 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 |
PROTOC_VERSION := 3.20.3 |
| 22 |
PROTOC_GEN_GO_VERSION := v1.30.0 |
| 23 |
|
| 24 |
# There are no protobuf releases for Darwin ARM so for |
| 25 |
# now we always use the x86_64 release through Rosetta. |
| 26 |
UNAME_OS := $(shell uname -s) |
| 27 |
UNAME_ARCH := $(shell uname -m) |
| 28 |
ifeq ($(UNAME_OS),Darwin) |
| 29 |
PROTOC_OS := osx |
| 30 |
PROTOC_ARCH := x86_64 |
| 31 |
endif |
| 32 |
ifeq ($(UNAME_OS),Linux) |
| 33 |
PROTOC_OS = linux |
| 34 |
PROTOC_ARCH := $(UNAME_ARCH) |
| 35 |
endif |
| 36 |
PROTOC := tmp/versions/protoc/$(PROTOC_VERSION) |
| 37 |
PROTOC_BIN := tmp/bin/protoc |
| 38 |
PROTOC_INCLUDE := tmp/include/google |
| 39 |
$(PROTOC): |
| 40 |
@if ! command -v curl >/dev/null 2>/dev/null; then echo "error: curl must be installed" >&2; exit 1; fi |
| 41 |
@if ! command -v unzip >/dev/null 2>/dev/null; then echo "error: unzip must be installed" >&2; exit 1; fi |
| 42 |
@rm -f $(PROTOC_BIN) |
| 43 |
@rm -rf $(PROTOC_INCLUDE) |
| 44 |
@mkdir -p $(dir $(PROTOC_BIN)) $(dir $(PROTOC_INCLUDE)) |
| 45 |
$(eval PROTOC_TMP := $(shell mktemp -d)) |
| 46 |
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 |
| 47 |
cd $(PROTOC_TMP); unzip protoc.zip && mv bin/protoc $(PWD)/$(PROTOC_BIN) && mv include/google $(PWD)/$(PROTOC_INCLUDE) |
| 48 |
@rm -rf $(PROTOC_TMP) |
| 49 |
@rm -rf $(dir $(PROTOC)) |
| 50 |
@mkdir -p $(dir $(PROTOC)) |
| 51 |
@touch $(PROTOC) |
| 52 |
|
| 53 |
PROTOC_GEN_GO := tmp/versions/protoc-gen-go/$(PROTOC_GEN_GO_VERSION) |
| 54 |
PROTOC_GEN_GO_BIN := tmp/bin/protoc-gen-go |
| 55 |
$(PROTOC_GEN_GO): |
| 56 |
@rm -f $(PROTOC_GEN_GO_BIN) |
| 57 |
@mkdir -p $(dir $(PROTOC_GEN_GO_BIN)) |
| 58 |
$(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d)) |
| 59 |
cd $(PROTOC_GEN_GO_TMP); GOBIN=$(PWD)/$(dir $(PROTOC_GEN_GO_BIN)) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION) |
| 60 |
@rm -rf $(PROTOC_GEN_GO_TMP) |
| 61 |
@rm -rf $(dir $(PROTOC_GEN_GO)) |
| 62 |
@mkdir -p $(dir $(PROTOC_GEN_GO)) |
| 63 |
@touch $(PROTOC_GEN_GO) |
| 64 |
|
| 65 |
go: $(GO_FILE) |
| 66 |
|
| 67 |
$(GO_FILE): $(PROTO_FILE) $(PROTOC_GEN_GO) $(PROTOC) |
| 68 |
@rm -rf $(dir $(GO_FILE)) tmp/go |
| 69 |
@mkdir -p $(dir $(GO_FILE)) tmp/go |
| 70 |
PATH=$(PWD)/tmp/bin:$$PATH protoc -I tmp/include -I . --go_out=paths=source_relative:tmp/go $(PROTO_FILE) |
| 71 |
@mv tmp/go/$(patsubst %.proto,%.pb.go,$(PROTO_FILE)) $(GO_FILE) |
| 72 |
|
| 73 |
build: $(GO_FILE) |
| 74 |
go build ./go |
| 75 |
|
| 76 |
clean: |
| 77 |
-rm -rf go tmp |
| 78 |
|
| 79 |
.PHONY: all clean go build |