Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [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 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 25 | XOS_DIR=/opt/xos |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 26 | PROTO_FILES := $(wildcard *.proto) $(wildcard third_party/google/api/*proto) |
| 27 | PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f))) |
| 28 | PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f))) |
| 29 | |
| 30 | PROTOC_PREFIX := /usr/local |
| 31 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 32 | |
| 33 | PROTOC := $(PROTOC_PREFIX)/bin/protoc |
| 34 | |
| 35 | PROTOC_VERSION := "3.0.2" |
| 36 | PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download" |
| 37 | PROTOC_DIR := protobuf-$(PROTOC_VERSION) |
| 38 | PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz |
| 39 | PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL) |
| 40 | PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')" |
| 41 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 42 | XPROTO_FILES := $(wildcard $(XOS_DIR)/core/models/core.xproto $(XOS_DIR)/services/*/*.xproto) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 43 | XOSGEN_PATH := $(XOS_DIR)/lib/xos-genx/xosgenx |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 44 | |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 45 | build: $(PROTOC) $(PROTO_PB2_FILES) |
| 46 | |
| 47 | %_pb2.py: %.proto Makefile |
| 48 | @echo "Building protocol buffer artifacts from $<" |
| 49 | env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 50 | -I. \ |
| 51 | -I./third_party \ |
| 52 | --python_out=. \ |
| 53 | --grpc_python_out=. \ |
| 54 | --descriptor_set_out=$(basename $<).desc \ |
| 55 | --include_imports \ |
| 56 | --include_source_info \ |
| 57 | $< |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 58 | |
| 59 | clean: |
| 60 | rm -f $(PROTO_PB2_FILES) $(PROTO_DESC_FILES) |
| 61 | |
| 62 | $(PROTOC): |
| 63 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 64 | @echo "It looks like you don't have protocol buffer tools installed." |
| 65 | @echo "To install the protocol buffer toolchain, you can run:" |
| 66 | @echo " make install-protoc" |
| 67 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 68 | |
| 69 | install-protoc: $(PROTOC) |
| 70 | @echo "Downloading and installing protocol buffer support." |
| 71 | @echo "Installation will require sodo priviledges" |
| 72 | @echo "This will take a few minutes." |
| 73 | mkdir -p $(PROTOC_BUILD_TMP_DIR) |
| 74 | @echo "We ask for sudo credentials now so we can install at the end"; \ |
| 75 | sudo echo "Thanks"; \ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 76 | cd $(PROTOC_BUILD_TMP_DIR); \ |
| 77 | wget $(PROTOC_DOWNLOAD_URI); \ |
| 78 | tar xzvf $(PROTOC_TARBALL); \ |
| 79 | cd $(PROTOC_DIR); \ |
| 80 | ./configure --prefix=$(PROTOC_PREFIX); \ |
| 81 | make; \ |
| 82 | sudo make install |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 83 | |
| 84 | uninstall-protoc: |
| 85 | cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 86 | sudo make uninstall |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 87 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 88 | # Note: If you want to generate a new file, you need to do two things: Add a line of the type specified in the following line, |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 89 | # and add the generated file to "AUTOGENERATED" |
| 90 | # <file to be generated>: <xtarget template that it depends on> |
| 91 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 92 | $(XOS_DIR)/coreapi/protos/xos.proto: $(XOSGEN_PATH)/targets/protoapi.xtarget |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 93 | $(XOS_DIR)/coreapi/xos_grpc_api.py: $(XOSGEN_PATH)/targets/grpc_api.xtarget |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 94 | $(XOS_DIR)/coreapi/tests/list_test.py: $(XOSGEN_PATH)/targets/grpc_list_test.xtarget |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 95 | $(XOS_DIR)/coreapi/tests/chameleon_list_test.sh: $(XOSGEN_PATH)/targets/chameleon_list_test.xtarget |
| 96 | $(XOS_DIR)/coreapi/protos/modeldefs.yaml: $(XOSGEN_PATH)/targets/modeldefs.xtarget |
| 97 | |
| 98 | AUTOGENERATED=$(XOS_DIR)/coreapi/protos/xos.proto $(XOS_DIR)/coreapi/xos_grpc_api.py $(XOS_DIR)/coreapi/tests/list_test.py $(XOS_DIR)/coreapi/tests/chameleon_list_test.sh $(XOS_DIR)/coreapi/protos/modeldefs.yaml |
| 99 | |
| 100 | $(AUTOGENERATED): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 101 | xosgenx --target $< $(XPROTO_FILES) > $@ |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 102 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 103 | rebuild-protos: $(AUTOGENERATED) |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 104 | |
Sapan Bhatia | db183c2 | 2017-06-23 02:47:42 -0700 | [diff] [blame^] | 105 | .PHONY: $(AUTOGENERATED) rebuild-protos |