GNU Make:具有类似通配符功能的多个PHONY目标? (将不同的预处理器指令传递给编译器) [英] GNU Make: Multiple PHONY Targets with Wildcard-like Functionality? (Passing different pre-processor directives to compiler)

查看:73
本文介绍了GNU Make:具有类似通配符功能的多个PHONY目标? (将不同的预处理器指令传递给编译器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的标题可能有点令人困惑,因为我很难用一个句子来写这个词.我知道通配符不能与伪造目标一起使用.这个问题是在询问是否有任何变通办法来完成通过make的PHONY目标将不同的预处理器指令传递给编译器.

The title here may be a little confusing because I had a hard time trying to word this in a single sentence. I understand that wildcards cannot be used with phony targets. This question is asking if there is any kind of workaround to accomplish passing different pre-processor directives to the compiler through make's PHONY targets.

例如,如果定义了MODEL_A,MODEL_B或MODEL_C,我的软件将进行不同的编译.因此,如果我将-DMODEL_A传递给编译器,则与我传递-DMODEL_B时的编译方式将有所不同.在我的makefile中,我有以下内容:

For example, I have software that will compile differently if MODEL_A, MODEL_B, or MODEL_C is defined. Therefore, if I pass -DMODEL_A to the compiler, it will compile differently than if I passed -DMODEL_B. In my makefile, I have the following:

AVAILABLE_MODELS=MODEL_A MODEL_B MODEL_C
SELECTED_MODEL=
...
.PHONY: $(AVAILABLE_MODELS)
MODEL_A: SELECTED_MODEL=MODEL_A
MODEL_B: SELECTED_MODEL=MODEL_B
MODEL_C: SELECTED_MODEL=MODEL_C
$(AVAILABLE_MODELS): Build_Image
...
#Build image for selected model (pass "-D$(SELECTED_MODEL)" to compiler)
Build_Image:
...

最理想的情况是,一旦添加了新模型,我就可以将任何新模型添加到AVAILABLE_MODELS变量中.不过,在上述设计中,我还需要确保使用适当的所选模型名称来定义目标.如果我可以执行以下操作,那将是很好的.

It would be most ideal if I could just add any new model to the AVAILABLE_MODELS variable once new models are added. In the above design though, I need to also make sure that I define the target as well with the appropriate selected model name. It would be nice if I could do the following.

MODEL_%: SELECTED_MODEL=MODEL_%

当然,由于它使用通配符,因此将其作为虚假目标候选者而忽略.我有没有这个技巧"?有什么方法可以优化上述内容?

Of course, that is ignored as a phony target candidate since it uses a wildcard. Is there any 'trick' that I am missing for this one? Is there any way to optimize the above?

推荐答案

您可以使用eval做到这一点:

You can do it with eval:

$(foreach M,$(AVAILABLE_MODELS),$(eval $M: SELECTED_MODEL=$M))

应该工作.

这篇关于GNU Make:具有类似通配符功能的多个PHONY目标? (将不同的预处理器指令传递给编译器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆