blob: 639151751b6092d3a6fb78efe451f75da4743ab0 [file] [log] [blame]
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -07001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -07003#
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
19ifeq ($(VOLTHA_BASE)_set,_set)
20 $(error To get started, please source the env.sh file from Voltha top level directory)
21endif
22
khenaidoo079a7762017-10-26 21:42:05 -040023default: third_party build
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070024
khenaidoo079a7762017-10-26 21:42:05 -040025PROTO_FILES := $(wildcard *.proto)
26PROTO_GOOGLE_API := $(wildcard third_party/google/api/*.proto)
27PROTO_ALL_FILES := $(PROTO_FILES) $(PROTO_GOOGLE_API)
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070028PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
khenaidoo079a7762017-10-26 21:42:05 -040029PROTO_PB2_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2.py,$(f)))
30PROTO_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)))
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070033
34PROTOC_PREFIX := /usr/local
35PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib
36
37PROTOC := $(PROTOC_PREFIX)/bin/protoc
38
khenaidoo079a7762017-10-26 21:42:05 -040039PROTOC_VERSION := "3.3.0"
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070040PROTOC_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
khenaidoo079a7762017-10-26 21:42:05 -040046# 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
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070061build: $(PROTOC) $(PROTO_PB2_FILES)
62
63%_pb2.py: %.proto Makefile
64 @echo "Building protocol buffer artifacts from $<"
Zsolt Haraszti823620f2016-09-27 08:31:57 -070065 env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
66 -I. \
67 -I./third_party \
68 --python_out=. \
69 --grpc_python_out=. \
70 --descriptor_set_out=$(basename $<).desc \
71 --include_imports \
72 --include_source_info \
73 $<
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070074
75clean:
khenaidoo079a7762017-10-26 21:42:05 -040076 rm -f $(PROTO_PB2_FILES) \
77 $(PROTO_ALL_DESC_FILES) \
78 $(PROTO_ALL_PB2_GPRC_FILES) \
79 $(PROTO_All_PB2_C_FILES) \
80 $(PROTO_PB2_GOOGLE_API)
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070081
82$(PROTOC):
83 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
84 @echo "It looks like you don't have protocol buffer tools installed."
85 @echo "To install the protocol buffer toolchain, you can run:"
86 @echo " make install-protoc"
87 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
88
89install-protoc: $(PROTOC)
90 @echo "Downloading and installing protocol buffer support."
91 @echo "Installation will require sodo priviledges"
92 @echo "This will take a few minutes."
93 mkdir -p $(PROTOC_BUILD_TMP_DIR)
94 @echo "We ask for sudo credentials now so we can install at the end"; \
95 sudo echo "Thanks"; \
96 cd $(PROTOC_BUILD_TMP_DIR); \
97 wget $(PROTOC_DOWNLOAD_URI); \
98 tar xzvf $(PROTOC_TARBALL); \
99 cd $(PROTOC_DIR); \
100 ./configure --prefix=$(PROTOC_PREFIX); \
101 make; \
102 sudo make install
103
104uninstall-protoc:
105 cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \
106 sudo make uninstall
107