blob: dc7c9732688aeee4bfeeb4c5e58bdbe1eabc722b [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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
Matt Jeanneret18949ae2019-02-09 15:00:14 -050019ifeq ($(VOLTHA_BASE)_set,_set)
20 $(error To get started, please source the env.sh file from Voltha top level directory)
21endif
22
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050023default: third_party build
24
Matt Jeanneret18949ae2019-02-09 15:00:14 -050025PROTO_FILES := $(wildcard *.proto)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050026PROTO_GOOGLE_API := $(wildcard third_party/google/api/*.proto)
27PROTO_ALL_FILES := $(PROTO_FILES) $(PROTO_GOOGLE_API)
28PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
29PROTO_PB2_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2.py,$(f)))
Matt Jeanneret18949ae2019-02-09 15:00:14 -050030PROTO_All_PB2_C_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2.pyc,$(f)))
31PROTO_ALL_PB2_GPRC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2_grpc.py,$(f)))
32PROTO_ALL_DESC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,.desc,$(f)))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050033
34PROTOC_PREFIX := /usr/local
35PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib
36
37PROTOC := $(PROTOC_PREFIX)/bin/protoc
38
39PROTOC_VERSION := "3.3.0"
40PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download"
41PROTOC_DIR := protobuf-$(PROTOC_VERSION)
42PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz
43PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
44PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
45
46# Google API needs to be built from within the third party directory
47#
48third_party: google_api
49google_api:
50 @echo "Building protocol buffer artifacts from third_party google api"
51 cd third_party ; \
52 env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
53 -I. \
54 --python_out=. \
55 --grpc_python_out=. \
56 --descriptor_set_out=google/api/annotations.desc \
57 --include_imports \
58 --include_source_info \
59 google/api/annotations.proto google/api/http.proto
60
61build: $(PROTOC) $(PROTO_PB2_FILES)
62
63%_pb2.py: %.proto Makefile
64 @echo "Building protocol buffer artifacts from $<"
65 env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
Matt Jeanneret18949ae2019-02-09 15:00:14 -050066 -I. \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067 -I./third_party \
68 --python_out=. \
69 --grpc_python_out=. \
Matt Jeanneret18949ae2019-02-09 15:00:14 -050070 --descriptor_set_out=$(basename $<).desc \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050071 --include_imports \
72 --include_source_info \
73 $<
74
75clean:
Matt Jeanneret18949ae2019-02-09 15:00:14 -050076 find . -name '*.pyc' | xargs rm -f
77 rm -f $(PROTO_PB2_FILES) \
78 $(PROTO_ALL_DESC_FILES) \
79 $(PROTO_ALL_PB2_GPRC_FILES) \
80 $(PROTO_All_PB2_C_FILES) \
81 $(PROTO_PB2_GOOGLE_API)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082
83$(PROTOC):
84 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
85 @echo "It looks like you don't have protocol buffer tools installed."
86 @echo "To install the protocol buffer toolchain, you can run:"
87 @echo " make install-protoc"
88 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
89
90install-protoc: $(PROTOC)
91 @echo "Downloading and installing protocol buffer support."
92 @echo "Installation will require sodo priviledges"
93 @echo "This will take a few minutes."
94 mkdir -p $(PROTOC_BUILD_TMP_DIR)
95 @echo "We ask for sudo credentials now so we can install at the end"; \
96 sudo echo "Thanks"; \
97 cd $(PROTOC_BUILD_TMP_DIR); \
98 wget $(PROTOC_DOWNLOAD_URI); \
99 tar xzvf $(PROTOC_TARBALL); \
100 cd $(PROTOC_DIR); \
101 ./configure --prefix=$(PROTOC_PREFIX); \
102 make; \
103 sudo make install
104
105uninstall-protoc:
106 cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \
107 sudo make uninstall