Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 1 | # |
Zsolt Haraszti | 3eb27a5 | 2017-01-03 21:56:48 -0800 | [diff] [blame] | 2 | # Copyright 2017 the original author or authors. |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 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 | |
Koray Kokten | efcdf52 | 2018-12-06 00:16:56 +0300 | [diff] [blame^] | 23 | default: openolt third_party build |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 24 | |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 25 | PROTO_FILES := $(wildcard *.proto) |
| 26 | PROTO_GOOGLE_API := $(wildcard third_party/google/api/*.proto) |
| 27 | PROTO_ALL_FILES := $(PROTO_FILES) $(PROTO_GOOGLE_API) |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 28 | PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f))) |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 29 | PROTO_PB2_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2.py,$(f))) |
| 30 | PROTO_All_PB2_C_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2.pyc,$(f))) |
| 31 | PROTO_ALL_PB2_GPRC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2_grpc.py,$(f))) |
| 32 | PROTO_ALL_DESC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,.desc,$(f))) |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 33 | |
| 34 | PROTOC_PREFIX := /usr/local |
| 35 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 36 | |
| 37 | PROTOC := $(PROTOC_PREFIX)/bin/protoc |
| 38 | |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 39 | PROTOC_VERSION := "3.3.0" |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 40 | PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download" |
| 41 | PROTOC_DIR := protobuf-$(PROTOC_VERSION) |
| 42 | PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz |
| 43 | PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL) |
| 44 | PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')" |
| 45 | |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 46 | # Google API needs to be built from within the third party directory |
| 47 | # |
| 48 | third_party: google_api |
| 49 | google_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 Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 61 | build: $(PROTOC) $(PROTO_PB2_FILES) |
| 62 | |
| 63 | %_pb2.py: %.proto Makefile |
| 64 | @echo "Building protocol buffer artifacts from $<" |
Zsolt Haraszti | 823620f | 2016-09-27 08:31:57 -0700 | [diff] [blame] | 65 | 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 Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 74 | |
| 75 | clean: |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 76 | 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 Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 81 | |
Koray Kokten | efcdf52 | 2018-12-06 00:16:56 +0300 | [diff] [blame^] | 82 | openolt: |
| 83 | @echo "Building OpenOlt Proto Files" |
| 84 | cd ../adapters/openolt/protos; make |
| 85 | |
Zsolt Haraszti | a54f2ac | 2016-09-21 15:54:15 -0700 | [diff] [blame] | 86 | $(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 | |
| 93 | install-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 | |
| 108 | uninstall-protoc: |
| 109 | cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \ |
| 110 | sudo make uninstall |