简体   繁体   English

使用自动工具的动态目标

[英]Dynamic targets with autotools

I am trying to achieve something very specific with autotools - dynamic variable names. 我正在尝试使用自动工具实现一些非常特定的功能-动态变量名称。 My goal is to create dynamic targets depending on a certain configuration file, similarly to the Linux kernel. 我的目标是根据特定的配置文件创建动态目标,类似于Linux内核。

The Linux kernel can be configured using make menuconfig, which eventually generates a .config. 可以使用make menuconfig来配置Linux内核,该菜单最终会生成.config。 The Makefiles of the Linux kernel contain targets such as obj-$(CONFIG_DMA) and depending on the value of CONFIG_DMA (y, n or m) , the associated source file will be built in statically, as a module, or not at all. Linux内核的Makefile包含诸如obj-$(CONFIG_DMA)目标,并且取决于obj-$(CONFIG_DMA)的值CONFIG_DMA (y, n or m) ,相关联的源文件将作为模块静态构建,或者根本不作为模块内置。 I am using kconfig-frontends which lets me generate a .config file which I can then include in a standard GNU Makefile and use successfully onwards. 我正在使用kconfig-frontends,它使我可以生成一个.config文件,然后可以将该文件包含在标准GNU Makefile中并成功使用。 I would like to achieve the same level of functionality with automake, but unfortunately automake refuses to set variable names depending on an external environment variable. 我想用automake达到相同的功能水平,但是不幸的是automake拒绝根据外部环境变量设置变量名。 I can think of hacky ways to get around this issue, but I'm sure there must be a way to achieve this in a clear fashion. 我可以想办法解决此问题,但是我敢肯定,必须有一种明确的方法来解决此问题。 Can anyone think of a solution for this? 谁能想到解决方案?

Any help is appreciated, and I'm open to using cmake if it solves my problem. 感谢您的帮助,如果可以解决问题,我愿意使用cmake。

Thanks! 谢谢!

Perhaps you can use EXTRA_foo_SOURCES ? 也许您可以使用EXTRA_foo_SOURCES You might not be able to use variable substitution in the LHS of a variable assignment, but you certainly can do so on the RHS. 您可能无法在变量分配的LHS中使用变量替换,但是您当然可以在RHS上使用。 List all possible sources in EXTRA_foo_SOURCES , and then, based on what the .config defines, set foo_SOURCES - and consider using += for doing to. EXTRA_foo_SOURCES列出所有可能的源,然后根据.config定义,设置foo_SOURCES并考虑使用+=进行操作。

You may have to invent a filename extension convention to get the different behaviour you want based on y/m/n; 您可能需要发明一个文件名扩展名约定,才能根据y / m / n获得所需的不同行为。 perhaps foo_SOURCES = mod.yo for a built-in module (and don't let *.o for a *_SOURCES* variable distract you - just provide the rules and make should figure it out), foo_SOURCES = mod.mo for a loadable module, and foo_SOURCES = mod.no for a disabled module. 对于内置模块,也许foo_SOURCES = mod.yo (不要对* _SOURCES *变量使用* .o来分散您的注意力,只需提供规则,make应当弄清楚), foo_SOURCES = mod.mo可加载模块,而foo_SOURCES = mod.no用于禁用的模块。 Then you need to help make glue the rules together. 然后,您需要帮助将规则粘合在一起。 Something to give you some ideas: 可以给您一些想法的东西:

-include .config
EXTRA_foo_SOURCES = $(obj-y) $(obj-m)
.c.o: # No rule; disables implicit rule
.c.yo:
    $(COMPILE) -o $@ $<
.c.mo:
    $(COMPILE) -DTHIS_IS_A_MODULE -o $@ $<
.c.no:
    touch $@
.yo.o:
    cp $< $@
.mo.o:
    cp $< $@
.no.o:
    cp /path/to/null/object.o $@

Hope you can make something of this. 希望您能从中受益。 I present this as a soup of automake atoms, not as a finished product, in the hope that you can turn it into a beautiful molecule. 我将其作为汽车制造原子的汤而不是最终产品呈现,希望您可以将其变成美丽的分子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM