使目标取决于GNU Make中的可选文件
我有一个简单的makefile,可以从.proto文件中生成Protobuf存根。
PROTOC := protoc.exe
PYTHON := python
NANOPB_GEN := ../lib/generator/
NANOPB_PROTO := $(NANOPB_GEN)proto
NANOPB_SCRIPT := $(NANOPB_GEN)nanopb_generator.py
CPP_PATH := ../../Firmware/protobuf/
CS_PATH := ../../Console/Networking/DataExchange/
SRCS := $(wildcard *.proto)
CPP_TARGETS := $(patsubst %.proto, $(CPP_PATH)%.pb.cpp, $(SRCS))
CS_TARGETS := $(patsubst %.proto, $(CS_PATH)%.cs, $(SRCS))
$(CPP_PATH)%.pb.cpp: %.proto
$(PYTHON) $(NANOPB_GEN) -H .h -S .cpp -D $(CPP_PATH) --strip-path $<
$(CS_PATH)%.cs: %.proto
$(PROTOC) -I./ -I=$(NANOPB_GEN) -I=$(NANOPB_PROTO) --csharp_out=$(CS_PATH) $<
all: cpp cs
@echo "making all"
cpp: $(CPP_TARGETS)
@echo "generating C++ stubs"
cs: $(CS_TARGETS)
@echo "generating C# stubs"
它可以正常工作,但是如果相应的 .options 文件更改除了 .proto 文件,我也希望将makefile重建存根。例如, tag.proto 可能具有可选的 tag.options 文件,该文件 nanopb 生成器期望。如果 .options 文件更改,我想修改makefile以重建存根,但如果没有 .options 文件,也可以正常工作。
我尝试了此规则:
$(cpp_path)%。pb.cpp:%.proto $$(patsubst%.proto,%.options,$$&lt;)
但是,这不处理 .proto 没有相应的*。选项
文件。
犯错:
make:***没有规则制作目标
../../ striceware/protobuf/tag.pb.cpp',
cpp'需要。停止。
如何定义可以使用 .ptions 的规则?
谢谢你!
I have a simple Makefile that generates protobuf stubs from .proto files.
PROTOC := protoc.exe
PYTHON := python
NANOPB_GEN := ../lib/generator/
NANOPB_PROTO := $(NANOPB_GEN)proto
NANOPB_SCRIPT := $(NANOPB_GEN)nanopb_generator.py
CPP_PATH := ../../Firmware/protobuf/
CS_PATH := ../../Console/Networking/DataExchange/
SRCS := $(wildcard *.proto)
CPP_TARGETS := $(patsubst %.proto, $(CPP_PATH)%.pb.cpp, $(SRCS))
CS_TARGETS := $(patsubst %.proto, $(CS_PATH)%.cs, $(SRCS))
$(CPP_PATH)%.pb.cpp: %.proto
$(PYTHON) $(NANOPB_GEN) -H .h -S .cpp -D $(CPP_PATH) --strip-path lt;
$(CS_PATH)%.cs: %.proto
$(PROTOC) -I./ -I=$(NANOPB_GEN) -I=$(NANOPB_PROTO) --csharp_out=$(CS_PATH) lt;
all: cpp cs
@echo "making all"
cpp: $(CPP_TARGETS)
@echo "generating C++ stubs"
cs: $(CS_TARGETS)
@echo "generating C# stubs"
It works fine, but I also want the makefile to rebuild the stubs if a corresponding .options file changes in addition to the .proto file. For instance, Tag.proto may have an optional Tag.options file that nanopb generator expects. I want to modify the Makefile to rebuild the stubs if .options file changes, but also works if there is no .options file.
I tried this rule:
$(CPP_PATH)%.pb.cpp: %.proto $$(patsubst %.proto, %.options, $$<)
However, this does not handle .proto files that don't have the corresponding *.options
file.
Err:
make: *** No rule to make target
../../Firmware/protobuf/Tag.pb.cpp', needed by
cpp'. Stop.
How can I define a rule that can use .options ?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最简单的方法是使用
Wildcard
函数,只有在存在时才考虑文件。唯一棘手的事情是您不能在辅助扩展部分内使用%
,但是您可以使用$$*
,它将扩展到已测试的词干,即:这将是 :当存在 .options 文件是否存在时,处理这两个选项,例如:
如果更改 .options 文件,也将重建:
I think the easiest way would be to use
wildcard
function, that will only take a file into account if it exists. The only tricky thing is that you cannot use%
within secondary expanded part, but you can use$$*
instead, which will expand to the tested stem, i.e.:This will handle both options when the .options file exists or not, e.g.:
This will also rebuild if .options file gets changed: