blob: ede161da77b00b06a78bce0929c685cc7d4957fc [file] [log] [blame]
Scott Bakerd1aa2f72017-01-05 10:58:08 -08001# Copyright 2017 the original author or authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16# Makefile to build all protobuf and gRPC related artifacts
17
Himanshu Bhandari5faac652020-05-21 18:56:52 +053018THIS_MAKEFILE = $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
19MAKEFILE_PATH := $(dir $(realpath $(THIS_MAKEFILE)))
20
Scott Bakerd1aa2f72017-01-05 10:58:08 -080021default: build
22
Zack Williams6bdd3ea2018-03-26 15:21:05 -070023PROTO_FILES := $(wildcard *.proto)
Scott Bakerd1aa2f72017-01-05 10:58:08 -080024PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
25PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f)))
26
27PROTOC_PREFIX := /usr/local
28PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib
29
Zack Williams6bdd3ea2018-03-26 15:21:05 -070030build: $(PROTO_PB2_FILES)
Scott Bakerd1aa2f72017-01-05 10:58:08 -080031
32%_pb2.py: %.proto Makefile
33 @echo "Building protocol buffer artifacts from $<"
34 env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
Matteo Scandolo67654fa2017-06-09 09:33:17 -070035 -I. \
Matteo Scandolo67654fa2017-06-09 09:33:17 -070036 --python_out=. \
37 --grpc_python_out=. \
38 --descriptor_set_out=$(basename $<).desc \
39 --include_imports \
40 --include_source_info \
41 $<
Scott Bakerd1aa2f72017-01-05 10:58:08 -080042
43clean:
44 rm -f $(PROTO_PB2_FILES) $(PROTO_DESC_FILES)
45
Zack Williams6bdd3ea2018-03-26 15:21:05 -070046# xproto related targets
Himanshu Bhandari5faac652020-05-21 18:56:52 +053047XOS_DIR=$(shell dirname $(shell dirname $(MAKEFILE_PATH)))
Zack Williams6bdd3ea2018-03-26 15:21:05 -070048XOSGEN_PATH := $(XOS_DIR)/lib/xos-genx/xosgenx
Scott Bakerd1aa2f72017-01-05 10:58:08 -080049
Zack Williams6bdd3ea2018-03-26 15:21:05 -070050# Note: If you want to generate a new file, you need to do two things: Add a
51# line of the type specified in the following line, and add the generated file
52# to "AUTOGENERATED" <file to be generated>: <xtarget template that it depends
53# on>
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020054
Matteo Scandolo67654fa2017-06-09 09:33:17 -070055$(XOS_DIR)/coreapi/protos/xos.proto: $(XOSGEN_PATH)/targets/protoapi.xtarget
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020056$(XOS_DIR)/coreapi/xos_grpc_api.py: $(XOSGEN_PATH)/targets/grpc_api.xtarget
Matteo Scandolo67654fa2017-06-09 09:33:17 -070057$(XOS_DIR)/coreapi/tests/list_test.py: $(XOSGEN_PATH)/targets/grpc_list_test.xtarget
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020058$(XOS_DIR)/coreapi/tests/chameleon_list_test.sh: $(XOSGEN_PATH)/targets/chameleon_list_test.xtarget
59$(XOS_DIR)/coreapi/protos/modeldefs.yaml: $(XOSGEN_PATH)/targets/modeldefs.xtarget
60
61AUTOGENERATED=$(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
62
Zack Williams6bdd3ea2018-03-26 15:21:05 -070063XPROTO_FILES := $(wildcard $(XOS_DIR)/core/models/core.xproto $(XOS_DIR)/services/*/*.xproto $(XOS_DIR)/dynamic_services/*/*.xproto)
64
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020065$(AUTOGENERATED):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070066 xosgenx --target $< $(XPROTO_FILES) > $@
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020067
Matteo Scandolo67654fa2017-06-09 09:33:17 -070068rebuild-protos: $(AUTOGENERATED)
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020069
Sapan Bhatiadb183c22017-06-23 02:47:42 -070070.PHONY: $(AUTOGENERATED) rebuild-protos
Zack Williams6bdd3ea2018-03-26 15:21:05 -070071