Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 1 | # 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 Bhandari | 5faac65 | 2020-05-21 18:56:52 +0530 | [diff] [blame^] | 18 | THIS_MAKEFILE = $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) |
| 19 | MAKEFILE_PATH := $(dir $(realpath $(THIS_MAKEFILE))) |
| 20 | |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 21 | default: build |
| 22 | |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 23 | PROTO_FILES := $(wildcard *.proto) |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 24 | PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f))) |
| 25 | PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f))) |
| 26 | |
| 27 | PROTOC_PREFIX := /usr/local |
| 28 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 29 | |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 30 | build: $(PROTO_PB2_FILES) |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 31 | |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 35 | -I. \ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 36 | --python_out=. \ |
| 37 | --grpc_python_out=. \ |
| 38 | --descriptor_set_out=$(basename $<).desc \ |
| 39 | --include_imports \ |
| 40 | --include_source_info \ |
| 41 | $< |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 42 | |
| 43 | clean: |
| 44 | rm -f $(PROTO_PB2_FILES) $(PROTO_DESC_FILES) |
| 45 | |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 46 | # xproto related targets |
Himanshu Bhandari | 5faac65 | 2020-05-21 18:56:52 +0530 | [diff] [blame^] | 47 | XOS_DIR=$(shell dirname $(shell dirname $(MAKEFILE_PATH))) |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 48 | XOSGEN_PATH := $(XOS_DIR)/lib/xos-genx/xosgenx |
Scott Baker | d1aa2f7 | 2017-01-05 10:58:08 -0800 | [diff] [blame] | 49 | |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 50 | # 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 Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 54 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 55 | $(XOS_DIR)/coreapi/protos/xos.proto: $(XOSGEN_PATH)/targets/protoapi.xtarget |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 56 | $(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] | 57 | $(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] | 58 | $(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 | |
| 61 | 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 |
| 62 | |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 63 | XPROTO_FILES := $(wildcard $(XOS_DIR)/core/models/core.xproto $(XOS_DIR)/services/*/*.xproto $(XOS_DIR)/dynamic_services/*/*.xproto) |
| 64 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 65 | $(AUTOGENERATED): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 66 | xosgenx --target $< $(XPROTO_FILES) > $@ |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 67 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 68 | rebuild-protos: $(AUTOGENERATED) |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 69 | |
Sapan Bhatia | db183c2 | 2017-06-23 02:47:42 -0700 | [diff] [blame] | 70 | .PHONY: $(AUTOGENERATED) rebuild-protos |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 71 | |