blob: 3e5ea799b3761cf161301e81ff1d93186ebd3073 [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
Koray Koktenefcdf522018-12-06 00:16:56 +030023default: openolt 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
Koray Koktenefcdf522018-12-06 00:16:56 +030082openolt:
83 @echo "Building OpenOlt Proto Files"
84 cd ../adapters/openolt/protos; make
85
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070086$(PROTOC):
87 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
88 @echo "It looks like you don't have protocol buffer tools installed."
89 @echo "To install the protocol buffer toolchain, you can run:"
90 @echo " make install-protoc"
91 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
92
93install-protoc: $(PROTOC)
94 @echo "Downloading and installing protocol buffer support."
95 @echo "Installation will require sodo priviledges"
96 @echo "This will take a few minutes."
97 mkdir -p $(PROTOC_BUILD_TMP_DIR)
98 @echo "We ask for sudo credentials now so we can install at the end"; \
99 sudo echo "Thanks"; \
100 cd $(PROTOC_BUILD_TMP_DIR); \
101 wget $(PROTOC_DOWNLOAD_URI); \
102 tar xzvf $(PROTOC_TARBALL); \
103 cd $(PROTOC_DIR); \
104 ./configure --prefix=$(PROTOC_PREFIX); \
105 make; \
106 sudo make install
107
108uninstall-protoc:
109 cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \
110 sudo make uninstall