1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Makefile.{include,base},pkg/nanopb: fix target dependencies & code generation

This commit is contained in:
Daniel Lockau 2024-02-06 07:46:38 +01:00
parent 4d2b2f7ade
commit 9c9d739634
3 changed files with 38 additions and 22 deletions

View File

@ -97,9 +97,6 @@ compile-commands: | $(DIRS:%=COMPILE-COMMANDS--%)
$(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH: $(TARGET_ARCH))
$(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH_LLVM: $(TARGET_ARCH_LLVM))
# include makefile snippets for packages in $(PKG_PATHS) that modify GENSRC:
-include $(PKG_PATHS:%=%Makefile.gensrc)
GENOBJC := $(GENSRC:%.c=%.o)
OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o)
OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)/$(MODULE)/%.o)

View File

@ -709,6 +709,12 @@ BUILDDEPS += $(BUILD_DIR)/CACHEDIR.TAG
# clean removing dependencies that make previously considered as up to date.
$(BUILDDEPS): $(CLEAN)
# include makefile snippets for packages in $(PKG_PATHS) that modify GENSRC:
-include $(PKG_PATHS:%=%Makefile.gensrc)
# remove duplicates & make accessible to subprocesses
GENSRC := $(sort $(GENSRC))
export GENSRC
# Save value to verify it is not modified later
_BASELIBS_VALUE_BEFORE_USAGE := $(BASELIBS)
@ -757,7 +763,7 @@ $(APPLICATION_MODULE).module: FORCE
# Other modules are built by application.inc.mk and packages building
_SUBMAKE_LIBS = $(filter-out $(APPLICATION_MODULE).module $(APPDEPS), $(BASELIBS) $(ARCHIVES))
$(_SUBMAKE_LIBS): $(APPLICATION_MODULE).module pkg-build
$(_SUBMAKE_LIBS): $(APPLICATION_MODULE).module pkg-build $(GENSRC)
# 'print-size' triggers a rebuild. Use 'info-buildsize' if you do not need to rebuild.
print-size: $(ELFFILE)
@ -810,13 +816,15 @@ endif
@$(COLOR_ECHO)
# The `clean` needs to be serialized before everything else.
all $(BASELIBS) $(ARCHIVES) $(BUILDDEPS) ..in-docker-container: | $(CLEAN)
all $(BASELIBS) $(ARCHIVES) $(BUILDDEPS) $(GENSRC) ..in-docker-container: | $(CLEAN)
.PHONY: pkg-prepare pkg-build
pkg-prepare:
-@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) prepare $(NEWLINE))
pkg-build: $(BUILDDEPS)
$(GENSRC): pkg-prepare
pkg-build: $(BUILDDEPS) | $(GENSRC)
$(foreach dir,$(PKG_PATHS),$(QQ)"$(MAKE)" -C $(dir) $(NEWLINE))
clean:

View File

@ -2,29 +2,40 @@ PROTOC ?= protoc
PROTOC_GEN_NANOPB ?= $(PKGDIRBASE)/nanopb/generator/protoc-gen-nanopb
PROTOBUF_FILES ?= $(wildcard *.proto)
PROTOBUF_PATH ?= $(CURDIR)
GENSRC += $(PROTOBUF_FILES:%.proto=$(BINDIR)/$(MODULE)/%.pb.c)
GENOBJC := $(GENSRC:%.c=%.o)
# remove duplicates
PROTOBUF_FILES := $(sort $(PROTOBUF_FILES))
NANOPB_OUT_DIR := $(BINDIR)/nanopb
ifneq (,$(PROTOBUF_FILES))
INCLUDES += -I$(BINDIR)/$(MODULE)
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
PROTO_INCLUDES += -I$(PROTOBUF_PATH)
$(SRC) $(SRCXX): $(GENSRC)
# We need to filter all protobuf files for source generation as pattern
# matching won't work due to the potentially different directory
# prefixes.
$(GENSRC): $(PROTOBUF_FILES)
$(Q)D=$(BINDIR)/$(MODULE) && \
mkdir -p "$$D" && \
cd $(CURDIR) && \
$(MAKE) -C $(PKGDIRBASE)/nanopb/generator/proto && \
for protofile in $(PROTOBUF_FILES); do \
protoc --plugin=protoc-gen-nanopb=$(PROTOC_GEN_NANOPB) \
--nanopb_out="$$D" $(PROTO_INCLUDES) \
$^ \
; done
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,$@))