|
11 | 11 | # See the License for the specific language governing permissions and |
12 | 12 | # limitations under the License. |
13 | 13 |
|
14 | | -KEY_ID ?= _DEFINE_ME_ |
| 14 | +all: |
| 15 | + $(MAKE) go |
| 16 | + $(MAKE) build |
15 | 17 |
|
16 | | -all: go |
| 18 | +GO_FILE := go/metrics.pb.go |
| 19 | +PROTO_FILE := io/prometheus/client/metrics.proto |
17 | 20 |
|
18 | | -SUFFIXES: |
| 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 |
19 | 25 |
|
20 | | -go: go/metrics.pb.go |
| 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) |
21 | 54 |
|
22 | | -go/metrics.pb.go: metrics.proto |
23 | | - protoc $< --go_out=import_path=github.com/prometheus/client_model/,paths=source_relative:go/ |
| 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 |
24 | 77 |
|
25 | 78 | clean: |
26 | | - -rm -rf go/* |
| 79 | + -rm -rf go tmp |
27 | 80 |
|
28 | | -.PHONY: all clean go |
| 81 | +.PHONY: all clean go build |
0 commit comments