khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | # |
| 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 | default: third_party build |
| 20 | |
| 21 | PROTO_FILES := $(wildcard ../../protos/*.proto) |
| 22 | PROTO_GOOGLE_API := $(wildcard third_party/google/api/*.proto) |
| 23 | PROTO_ALL_FILES := $(PROTO_FILES) $(PROTO_GOOGLE_API) |
| 24 | PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f))) |
| 25 | PROTO_PB2_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2.py,$(f))) |
| 26 | PROTO_PB2_GRPC_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2_grpc.py,$(f))) |
| 27 | PROTO_DESC_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,.desc,$(f))) |
| 28 | |
| 29 | PROTOC_PREFIX := /usr/local |
| 30 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 31 | |
| 32 | PROTOC := $(PROTOC_PREFIX)/bin/protoc |
| 33 | |
| 34 | PROTOC_VERSION := "3.3.0" |
| 35 | PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download" |
| 36 | PROTOC_DIR := protobuf-$(PROTOC_VERSION) |
| 37 | PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz |
| 38 | PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL) |
| 39 | PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')" |
| 40 | |
| 41 | # Google API needs to be built from within the third party directory |
| 42 | # |
| 43 | third_party: google_api |
| 44 | google_api: |
| 45 | @echo "Building protocol buffer artifacts from third_party google api" |
| 46 | cd third_party ; \ |
| 47 | env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \ |
| 48 | -I. \ |
| 49 | --python_out=. \ |
| 50 | --grpc_python_out=. \ |
| 51 | --descriptor_set_out=google/api/annotations.desc \ |
| 52 | --include_imports \ |
| 53 | --include_source_info \ |
| 54 | google/api/annotations.proto google/api/http.proto |
| 55 | |
| 56 | build: $(PROTOC) $(PROTO_PB2_FILES) |
| 57 | |
| 58 | %_pb2.py: %.proto Makefile |
| 59 | @echo "Building protocol buffer artifacts from $<" |
| 60 | env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \ |
| 61 | -I../../protos \ |
| 62 | -I./third_party \ |
| 63 | --python_out=. \ |
| 64 | --grpc_python_out=. \ |
| 65 | --descriptor_set_out=./$(basename $(notdir $<)).desc \ |
| 66 | --include_imports \ |
| 67 | --include_source_info \ |
| 68 | $< |
| 69 | |
| 70 | clean: |
| 71 | rm -f *.desc *_pb2* \ |
| 72 | $(PROTO_PB2_GOOGLE_API) \ |
| 73 | $(PROTO_PB2_GRPC_GOOGLE_API)\ |
| 74 | $(PROTO_DESC_GOOGLE_API) |
| 75 | |
| 76 | $(PROTOC): |
| 77 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 78 | @echo "It looks like you don't have protocol buffer tools installed." |
| 79 | @echo "To install the protocol buffer toolchain, you can run:" |
| 80 | @echo " make install-protoc" |
| 81 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 82 | |
| 83 | install-protoc: $(PROTOC) |
| 84 | @echo "Downloading and installing protocol buffer support." |
| 85 | @echo "Installation will require sodo priviledges" |
| 86 | @echo "This will take a few minutes." |
| 87 | mkdir -p $(PROTOC_BUILD_TMP_DIR) |
| 88 | @echo "We ask for sudo credentials now so we can install at the end"; \ |
| 89 | sudo echo "Thanks"; \ |
| 90 | cd $(PROTOC_BUILD_TMP_DIR); \ |
| 91 | wget $(PROTOC_DOWNLOAD_URI); \ |
| 92 | tar xzvf $(PROTOC_TARBALL); \ |
| 93 | cd $(PROTOC_DIR); \ |
| 94 | ./configure --prefix=$(PROTOC_PREFIX); \ |
| 95 | make; \ |
| 96 | sudo make install |
| 97 | |
| 98 | uninstall-protoc: |
| 99 | cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \ |
| 100 | sudo make uninstall |
| 101 | |