【发布时间】:2011-10-14 06:14:54
【问题描述】:
我有一个像
这样的 make 规则app.o: app.c b.c a.c h.h file.list
我正在使用规则$^ 对所有依赖项执行一些操作。
但我想根据依赖项的文件扩展名进行过滤。
我该怎么做?
我想要一个变量
k = (which contain only .c file from dependency list )
【问题讨论】:
我有一个像
这样的 make 规则app.o: app.c b.c a.c h.h file.list
我正在使用规则$^ 对所有依赖项执行一些操作。
但我想根据依赖项的文件扩展名进行过滤。
我该怎么做?
我想要一个变量
k = (which contain only .c file from dependency list )
【问题讨论】:
如果你使用的是GNU Make,那么
$(filter %.c,$^)
可以解决问题(过滤器从列表中返回与给定模式匹配的所有单词,过滤器返回不匹配的单词)。如果你使用一些更原始的make,你将不得不求助于
APP_O_C_DEPS = app.c b.c a.c
APP_O_NONC_DEPS = h.h file.list
app.o: $(APP_O_C_DEPS) $(APP_O_NONC_DEPS)
...
注意: Make 中变量的工作方式允许你说
c_deps = $(filter %.c,$^)
app.o: app.c b.c a.c h.h file.list
something $(c_deps)
它会扩展为当前目标的 .c 依赖项。
【讨论】: