makefile宏接受参数

Aar*_*ken 6 makefile gnu-make

我想像shell你可以说的宏一样自己制作一些东西$(shell command).

不幸的是,我还没有在网上找到任何关于如何做到这一点.

那可能吗?

Die*_*lla 9

在GNU make中,您可以执行以下操作.想象一下,你想生成.h.cpp从简单的文件名,文件名不带扩展添加一些规则的来源.你可以写:

define h_and_cpp_sources
    $(1).h $(1).cpp
endef
Run Code Online (Sandbox Code Playgroud)

这将生成一个Makefile宏,该宏获取第一个参数$(1),第二个$(2),等等.然后:

target: $(call h_and_cpp_sources,file)
...
Run Code Online (Sandbox Code Playgroud)

这将构建规则:

target: file.h file.cpp
Run Code Online (Sandbox Code Playgroud)


Mat*_*Mat 6

您应该尝试使用调用函数语法。

这不完全是你想要的,但 AFAIK 没有比这更复杂的了。