mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
42 lines
1.4 KiB
Makefile
42 lines
1.4 KiB
Makefile
PROTOC ?= protoc
|
|
PROTOC_GEN_NANOPB ?= $(PKGDIRBASE)/nanopb/generator/protoc-gen-nanopb
|
|
|
|
PROTOBUF_FILES ?= $(wildcard *.proto)
|
|
|
|
# remove duplicates
|
|
PROTOBUF_FILES := $(sort $(PROTOBUF_FILES))
|
|
|
|
NANOPB_OUT_DIR := $(BINDIR)/nanopb
|
|
|
|
ifneq (,$(PROTOBUF_FILES))
|
|
INCLUDES += -I$(NANOPB_OUT_DIR)
|
|
endif
|
|
|
|
PROTOBUF_FILES_BASENAMES = $(notdir $(PROTOBUF_FILES))
|
|
|
|
GENSRC += $(PROTOBUF_FILES_BASENAMES:%.proto=$(NANOPB_OUT_DIR)/%.pb.c)
|
|
|
|
# workaround for old protoc
|
|
PROTO_INCLUDES += -I.
|
|
# add nanopb specific includes
|
|
PROTO_INCLUDES += -I$(PKGDIRBASE)/nanopb/generator/proto
|
|
|
|
# We need to filter all protobuf files for source generation as pattern
|
|
# matching won't work due to the potentially different directory
|
|
# prefixes.
|
|
|
|
nanopb_select_proto_from_target = $(firstword $(filter %$(notdir $(basename $(basename $(1)))).proto,$(PROTOBUF_FILES)))
|
|
|
|
$(NANOPB_OUT_DIR)/%.pb.c: $(PROTOBUF_FILES)
|
|
# We have to create the output directory here because properly chaining
|
|
# with the clean target is currently not possible.
|
|
-$(Q)mkdir -p $(NANOPB_OUT_DIR)
|
|
# Change of directory is required here because of protoc shortcomings.
|
|
# Setting --proto_path to the same value will fail under certain
|
|
# conditions.
|
|
$(Q)cd "$(dir $(call nanopb_select_proto_from_target,$@))" \
|
|
&& protoc --plugin=protoc-gen-nanopb=$(PROTOC_GEN_NANOPB) \
|
|
--proto_path=. \
|
|
--nanopb_out="$(NANOPB_OUT_DIR)" $(PROTO_INCLUDES) \
|
|
$(notdir $(call nanopb_select_proto_from_target,$@))
|