Sergio Slobodrian | 6570c74 | 2017-08-07 23:11:33 -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 | ifeq ($(VOLTHA_BASE)_set,_set) |
| 20 | $(error To get started, please source the env.sh file from Voltha top level directory) |
| 21 | endif |
| 22 | |
| 23 | default: build |
| 24 | |
| 25 | PROTO_PATH := ../voltha/protos |
| 26 | PROTO_FILES := $(PROTO_PATH)/*.proto $(PROTO_PATH)/third_party/google/api/*proto |
| 27 | PROTO_DESC_FILE := proto.pb |
| 28 | |
| 29 | PROTOC_PREFIX := /usr/local |
| 30 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 31 | |
| 32 | PROTOC := $(PROTOC_PREFIX)/bin/protoc |
| 33 | |
| 34 | PROTOC_VERSION := "3.0.2" |
| 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 | build: $(PROTOC) |
| 42 | LD_LIBRARY_PATH=$(PROTOC_LIBDIR) $(PROTOC) -I $(PROTO_PATH)/third_party/ -I $(PROTO_PATH) --include_imports --include_source_info --descriptor_set_out=$(PROTO_DESC_FILE) $(PROTO_FILES) |
| 43 | |
| 44 | |
| 45 | clean: |
| 46 | rm -f $(PROTO_DESC_FILE) |
| 47 | |
| 48 | $(PROTOC): |
| 49 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 50 | @echo "It looks like you don't have protocol buffer tools installed." |
| 51 | @echo "To install the protocol buffer toolchain, you can run:" |
| 52 | @echo " make install-protoc" |
| 53 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 54 | |
| 55 | install-protoc: $(PROTOC) |
| 56 | @echo "Downloading and installing protocol buffer support." |
| 57 | @echo "Installation will require sodo priviledges" |
| 58 | @echo "This will take a few minutes." |
| 59 | mkdir -p $(PROTOC_BUILD_TMP_DIR) |
| 60 | @echo "We ask for sudo credentials now so we can install at the end"; \ |
| 61 | sudo echo "Thanks"; \ |
| 62 | cd $(PROTOC_BUILD_TMP_DIR); \ |
| 63 | wget $(PROTOC_DOWNLOAD_URI); \ |
| 64 | tar xzvf $(PROTOC_TARBALL); \ |
| 65 | cd $(PROTOC_DIR); \ |
| 66 | ./configure --prefix=$(PROTOC_PREFIX); \ |
| 67 | make; \ |
| 68 | sudo make install |
| 69 | |
| 70 | uninstall-protoc: |
| 71 | cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \ |
| 72 | sudo make uninstall |
| 73 | |