blob: cfbaa529b0aba75945995a05fc598ed2f52e4a3b [file] [log] [blame]
Scott Bakerd1aa2f72017-01-05 10:58:08 -08001#
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
23default: build
24
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020025XOS_DIR=/opt/xos
Scott Bakerd1aa2f72017-01-05 10:58:08 -080026PROTO_FILES := $(wildcard *.proto) $(wildcard third_party/google/api/*proto)
27PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
28PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f)))
29
30PROTOC_PREFIX := /usr/local
31PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib
32
33PROTOC := $(PROTOC_PREFIX)/bin/protoc
34
35PROTOC_VERSION := "3.0.2"
36PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download"
37PROTOC_DIR := protobuf-$(PROTOC_VERSION)
38PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz
39PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
40PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
41
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020042XPROTO_FILES := $(wildcard $(XOS_DIR)/core/models/core.xproto $(XOS_DIR)/services/*/*.xproto)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070043XOSGEN_PATH := $(XOS_DIR)/lib/xos-genx/xosgenx
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020044
Scott Bakerd1aa2f72017-01-05 10:58:08 -080045build: $(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 Scandolo67654fa2017-06-09 09:33:17 -070050 -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 Bakerd1aa2f72017-01-05 10:58:08 -080058
59clean:
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
69install-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 Scandolo67654fa2017-06-09 09:33:17 -070076 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 Bakerd1aa2f72017-01-05 10:58:08 -080083
84uninstall-protoc:
85 cd $(PROTOC_BUILD_TMP_DIR)/$(PROTOC_DIR); \
Matteo Scandolo67654fa2017-06-09 09:33:17 -070086 sudo make uninstall
Scott Bakerd1aa2f72017-01-05 10:58:08 -080087
Matteo Scandolo67654fa2017-06-09 09:33:17 -070088# 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 Bhatiacb35e7f2017-05-24 12:17:28 +020089# and add the generated file to "AUTOGENERATED"
90# <file to be generated>: <xtarget template that it depends on>
91
Matteo Scandolo67654fa2017-06-09 09:33:17 -070092$(XOS_DIR)/coreapi/protos/xos.proto: $(XOSGEN_PATH)/targets/protoapi.xtarget
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020093$(XOS_DIR)/coreapi/xos_grpc_api.py: $(XOSGEN_PATH)/targets/grpc_api.xtarget
Matteo Scandolo67654fa2017-06-09 09:33:17 -070094$(XOS_DIR)/coreapi/tests/list_test.py: $(XOSGEN_PATH)/targets/grpc_list_test.xtarget
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020095$(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
98AUTOGENERATED=$(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 Scandolo67654fa2017-06-09 09:33:17 -0700101 xosgenx --target $< $(XPROTO_FILES) > $@
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +0200102
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700103rebuild-protos: $(AUTOGENERATED)
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +0200104
Sapan Bhatiadb183c22017-06-23 02:47:42 -0700105.PHONY: $(AUTOGENERATED) rebuild-protos