-
Notifications
You must be signed in to change notification settings - Fork 35
/
Makefile.generate_proto
84 lines (68 loc) · 3.08 KB
/
Makefile.generate_proto
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
# Copyright 2022 The SODA Authors.
#
# 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.
OUT_DIR ?= _output
########################################################################
## PROTOC ##
########################################################################
# Only set PROTOC_VER if it has an empty value.
ifeq (,$(strip $(PROTOC_VER)))
PROTOC_VER := 3.9.1
endif
PROTOC_OS := $(shell uname -s)
ifeq (Darwin,$(PROTOC_OS))
PROTOC_OS := osx
endif
PROTOC_ARCH := $(shell uname -m)
ifeq (i386,$(PROTOC_ARCH))
PROTOC_ARCH := x86_32
endif
HERE := $(shell pwd)
PROTO_DIR := $(HERE)/$(OUT_DIR)/.proto
PROTO_BIN_DIR := $(PROTO_DIR)/bin
PROTOC := $(PROTO_BIN_DIR)/protoc
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
PROTOC_TMP_BIN := $(PROTO_BIN_DIR)/protoc
$(PROTOC):
-mkdir -p "$(PROTO_BIN_DIR)" && \
curl -L $(PROTOC_URL) -o "$(PROTO_DIR)/$(PROTOC_ZIP)" && \
unzip "$(PROTO_DIR)/$(PROTOC_ZIP)" -d "$(PROTO_DIR)" && \
chmod 0755 "$(PROTOC_TMP_BIN)" && \
stat "$@" > /dev/null 2>&1
########################################################################
## PROTOC-GEN-GO ##
########################################################################
# This is the recipe for getting and installing the go plug-in
# for protoc
PROTOC_GEN_GO_PKG := github.com/golang/protobuf/protoc-gen-go
PROTOC_GEN_GO := $(PROTO_BIN_DIR)/protoc-gen-go
$(PROTOC_GEN_GO): PROTOBUF_PKG := $(dir $(PROTOC_GEN_GO_PKG))
$(PROTOC_GEN_GO): PROTOBUF_VERSION := v1.5.2
$(PROTOC_GEN_GO): $(PROTO_DIR)
mkdir -p $(dir $(PROTO_DIR)/src/$(PROTOBUF_PKG))
test -d $(PROTO_DIR)/src/$(PROTOBUF_PKG)/.git || git clone https://$(PROTOBUF_PKG) $(PROTO_DIR)/src/$(PROTOBUF_PKG)
(cd $(PROTO_DIR)/src/$(PROTOBUF_PKG) && \
(test "$$(git describe --tags | head -1)" = "$(PROTOBUF_VERSION)" || \
(git fetch && git checkout tags/$(PROTOBUF_VERSION))))
(cd $(PROTO_DIR)/src/$(PROTOBUF_PKG) && go get -v -d $$(go list -f '{{ .ImportPath }}' ./...)) && \
go build -o "$@" $(PROTOC_GEN_GO_PKG)
build_meta_service_grpc: $(PROTOC) $(PROTOC_GEN_GO)
$(MAKE) -C providerframework/metaservice metaservice.pb.go PROTOC=$(PROTOC) PROTOC_GEN_GO=$(PROTOC_GEN_GO)
build_provider_service_grpc: $(PROTOC) $(PROTOC_GEN_GO)
$(MAKE) -C providers providerservice.pb.go PROTOC=$(PROTOC) PROTOC_GEN_GO=$(PROTOC_GEN_GO)
grpc_interfaces: build_meta_service_grpc build_provider_service_grpc
generated_files: grpc_interfaces
.PHONY: clean
clean:
rm -rf $(PROTO_DIR)