blob: a1c82da5064d0207e570652c54363b99e0ef9171 [file] [log] [blame]
Scott Bakerd1aa2f72017-01-05 10:58:08 -08001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# Makefile to build all protobuf and gRPC related artifacts
18
19#ifeq ($(VOLTHA_BASE)_set,_set)
20# $(error To get started, please source the env.sh file from Voltha top level directory)
21#endif
22
23default: build
24
25PROTO_FILES := $(wildcard *.proto) $(wildcard third_party/google/api/*proto)
26PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
27PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f)))
28
29PROTOC_PREFIX := /usr/local
30PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib
31
32PROTOC := $(PROTOC_PREFIX)/bin/protoc
33
34PROTOC_VERSION := "3.0.2"
35PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download"
36PROTOC_DIR := protobuf-$(PROTOC_VERSION)
37PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz
38PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
39PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
40
41build: $(PROTOC) $(PROTO_PB2_FILES)
42
43%_pb2.py: %.proto Makefile
44 @echo "Building protocol buffer artifacts from $<"
45 env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
46 -I. \
47 -I./third_party \
48 --python_out=. \
49 --grpc_python_out=. \
50 --descriptor_set_out=$(basename $<).desc \
51 --include_imports \
52 --include_source_info \
53 $<
54
55clean:
56 rm -f $(PROTO_PB2_FILES) $(PROTO_DESC_FILES)
57
58$(PROTOC):
59 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
60 @echo "It looks like you don't have protocol buffer tools installed."
61 @echo "To install the protocol buffer toolchain, you can run:"
62 @echo " make install-protoc"
63 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
64
65install-protoc: $(PROTOC)
66 @echo "Downloading and installing protocol buffer support."
67 @echo "Installation will require sodo priviledges"
68 @echo "This will take a few minutes."
69 mkdir -p $(PROTOC_BUILD_TMP_DIR)
70 @echo "We ask for sudo credentials now so we can install at the end"; \
71 sudo echo "Thanks"; \
72 cd $(PROTOC_BUILD_TMP_DIR); \
73 wget $(PROTOC_DOWNLOAD_URI); \
74 tar xzvf $(PROTOC_TARBALL); \
75 cd $(PROTOC_DIR); \
76 ./configure --prefix=$(PROTOC_PREFIX); \
77 make; \
78 sudo make install
79
80uninstall-protoc:
81 cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \
82 sudo make uninstall
83
84rebuild-protos:
85 cd ../../tools/apigen && python ./modelgen -a core protobuf.template.txt > /opt/xos/grpc/protos/xos.proto
86 cd ../../tools/apigen && python ./modelgen -a core grpc_api.template.py > /opt/xos/grpc/xos_grpc_api.py
87 cd ../../tools/apigen && python ./modelgen -a core grpc_list_test.template.py > /opt/xos/grpc/list_test.py
88