• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Makefile for Pigweed's RPC module
3#
4# NOTE: In order to use this, you *must* have the following:
5# - Installed mypy-protobuf and protoc
6# - nanopb-c git repo checked out
7#
8
9ifneq ($(PW_RPC_SRCS),)
10
11# Environment Checks ###########################################################
12
13# Location of various Pigweed modules
14PIGWEED_DIR = $(ANDROID_BUILD_TOP)/external/pigweed
15CHRE_UTIL_DIR = $(ANDROID_BUILD_TOP)/system/chre/util
16PIGWEED_CHRE_UTIL_DIR = $(CHRE_UTIL_DIR)/pigweed
17
18ifeq ($(NANOPB_PREFIX),)
19$(error "PW_RPC_SRCS is non-empty. You must supply a NANOPB_PREFIX environment \
20         variable containing a path to the nanopb project. Example: \
21         export NANOPB_PREFIX=$$HOME/path/to/nanopb/nanopb-c")
22endif
23
24ifeq ($(PROTOC),)
25PROTOC=protoc
26endif
27
28PW_RPC_GEN_PATH = $(OUT)/pw_rpc_gen
29
30# Create proto used for header generation ######################################
31
32PW_RPC_PROTO_GENERATOR = $(PIGWEED_DIR)/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py
33PW_RPC_GENERATOR_PROTO_SRCS = $(PIGWEED_DIR)/pw_rpc/internal/packet.proto
34PW_RPC_GENERATOR_COMPILED_PROTO = $(PW_RPC_GEN_PATH)/py/pw_rpc/internal/packet_pb2.py
35
36# Modifies PYTHONPATH so that python can see all of pigweed's modules used by
37# their protoc plugins
38PW_RPC_GENERATOR_CMD = PYTHONPATH=$$PYTHONPATH:$(PW_RPC_GEN_PATH)/py:$\
39  $(PIGWEED_DIR)/pw_status/py:$(PIGWEED_DIR)/pw_protobuf/py:$\
40  $(PIGWEED_DIR)/pw_protobuf_compiler/py python3
41
42$(PW_RPC_GENERATOR_COMPILED_PROTO): $(PW_RPC_GENERATOR_PROTO_SRCS)
43	@echo " [PW_RPC] $<"
44	$(V)mkdir -p $(PW_RPC_GEN_PATH)/py/
45	$(V)cp -R $(PIGWEED_DIR)/pw_rpc/py/pw_rpc $(PW_RPC_GEN_PATH)/py/
46	$(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) --out-dir=$(PW_RPC_GEN_PATH)/py/pw_rpc/internal \
47	  --compile-dir=$(dir $<) --sources $(PW_RPC_GENERATOR_PROTO_SRCS) \
48	  --language python
49	$(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) \
50	  --plugin-path=$(PIGWEED_DIR)/pw_protobuf/py/pw_protobuf/plugin.py \
51	  --compile-dir=$(dir $<) --sources $(PW_RPC_GENERATOR_PROTO_SRCS) \
52	  --language pwpb
53
54# Generated PW RPC Files #######################################################
55
56PW_RPC_GEN_SRCS = $(patsubst %.proto, \
57                             $(PW_RPC_GEN_PATH)/%.pb.c, \
58                             $(PW_RPC_SRCS))
59
60# Include to-be-generated files
61COMMON_CFLAGS += -I$(PW_RPC_GEN_PATH)
62COMMON_CFLAGS += -I$(PW_RPC_GEN_PATH)/$(PIGWEED_DIR)
63COMMON_CFLAGS += $(addprefix -I$(PW_RPC_GEN_PATH)/, $(PW_RPC_INCLUDES))
64
65COMMON_SRCS += $(PW_RPC_GEN_SRCS)
66
67# PW RPC library ###############################################################
68
69# Pigweed RPC include paths
70COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_assert/assert_lite_public_overrides
71COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_assert/public
72COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_assert_log/public
73COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_assert_log/public_overrides
74COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_bytes/public
75COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_containers/public
76COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_function/public
77COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_log/public
78COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_log_null/public
79COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_log_null/public_overrides
80COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/public
81COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/public_overrides
82COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/standard_library_public
83COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_preprocessor/public
84COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_protobuf/public
85COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_result/public
86COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/
87COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/nanopb/public
88COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/public
89COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/raw/public
90COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_span/public
91COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_span/public_overrides
92COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_status/public
93COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_stream/public
94COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_sync/public
95COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_varint/public
96
97# Pigweed RPC sources
98COMMON_SRCS += $(PIGWEED_DIR)/pw_assert_log/assert_log.cc
99COMMON_SRCS += $(PIGWEED_DIR)/pw_containers/intrusive_list.cc
100COMMON_SRCS += $(PIGWEED_DIR)/pw_protobuf/decoder.cc
101COMMON_SRCS += $(PIGWEED_DIR)/pw_protobuf/encoder.cc
102COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/call.cc
103COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/channel.cc
104COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/client.cc
105COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/client_call.cc
106COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/client_server.cc
107COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/endpoint.cc
108COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/packet.cc
109COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/server.cc
110COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/server_call.cc
111COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/service.cc
112COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/common.cc
113COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/method.cc
114COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/server_reader_writer.cc
115COMMON_SRCS += $(PIGWEED_DIR)/pw_stream/memory_stream.cc
116COMMON_SRCS += $(PIGWEED_DIR)/pw_varint/varint.cc
117
118# NanoPB header includes
119COMMON_CFLAGS += -I$(NANOPB_PREFIX)
120
121# NanoPB sources
122COMMON_SRCS += $(NANOPB_PREFIX)/pb_common.c
123COMMON_SRCS += $(NANOPB_PREFIX)/pb_decode.c
124COMMON_SRCS += $(NANOPB_PREFIX)/pb_encode.c
125
126# Add CHRE Pigweed util sources since nanoapps should always use these
127COMMON_SRCS += $(PIGWEED_CHRE_UTIL_DIR)/chre_channel_output.cc
128COMMON_SRCS += $(CHRE_UTIL_DIR)/nanoapp/callbacks.cc
129
130# Generate PW RPC headers ######################################################
131
132$(PW_RPC_GEN_PATH)/%.pb.c \
133        $(PW_RPC_GEN_PATH)/%.pb.h \
134        $(PW_RPC_GEN_PATH)/%.rpc.pb.h \
135        $(PW_RPC_GEN_PATH)/%.raw_rpc.pb.h: %.proto \
136                                           %.options \
137                                           $(NANOPB_GENERATOR_SRCS) \
138                                           $(PW_RPC_GENERATOR_COMPILED_PROTO)
139	@echo " [PW_RPC] $<"
140	$(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \
141	  --plugin-path=$(NANOPB_PROTOC) \
142	  --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb \
143	  --sources $<
144	$(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \
145	  --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_nanopb.py \
146	  --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb_rpc \
147	  --sources $<
148	$(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \
149	  --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_raw.py \
150	  --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language raw_rpc \
151	  --sources $<
152
153endif