问题描述
我想使语言成为目标.特别是:我有一个源文件,我想创建不同的对象,然后将它们添加到相应的语言文件夹中.编译器将获得该单一源文件在C-Flags中的不同.只要我以静态方式使用它,它就可以正常工作.
I want to make a language depend target. In Particular: I have one source-file and I want to create different Objects which where add to the corresponding language folder. That single source file will differ in the C-Flags, the compiler will get. As long as I used it in a static way, it works quite fine.
de/info.o en/info.o es/info.o : info.c
$(ECHO) (DEP) $< for $@
现在我想,如果它更具动态性,那将很棒,以防万一我要添加新的语言依赖文件.因此,我使用通配符,如下所示:
Now I thought, it would be great if it is a bit more dynamic, in case i'll add a new language depending file. So I used a wildcard as followed:
de/%.o en/%.o es/%.o : %.c
$(ECHO) (DEP) $< for $@
但是现在它只是确定第一个目标,而忽略其余目标. Make-Debug打印以下内容:
But now it just make the first target and ignores the rest. The Make-Debug prints the following thing:
Successfully remade target file `de/info.o'.
Considering target file `en/info.o'.
File `en/info.o' was considered already.
以防万一:不,对象不存在.因此,没有目标,而是现有的依赖关系,因此make应该执行规则.
Just in case: No, the objects do not exist. So there is no target, but an existing dependencie, so make should execute the rules.
找到了该问题的解决方案.
Found a solution for that Problem.
define FOO
$(1)/%.o : %.c
$(ECHO) $$< for $(1)
endef
$(foreach lang,$(LANGUAGE_LIST), $(eval $(call FOO,$(lang))))
灵感来自于: http://www.gnu.org /software/make/manual/make.html#Eval-Function
推荐答案
模式规则的工作方式不同于隐式规则.而诸如
Pattern rules work differently than implicit rules. While an implicit rule such as
a b c: d
command
等同于较长的符号
a: d
command
b: d
command
c: d
command
这不适用于模式规则.明确要求具有多个目标的模式规则,以通过一次调用command
来构建其目标的全部.因此,您将不得不写
this does NOT hold for pattern rules. Pattern rules with multiple targets are explicitly required to build all of their targets in a single invocation of command
. Thus you would have to write
$ cat GNUmakefile
all: de/x.o en/x.o es/x.o
de/%.o: %.c
@echo $@ from $<
en/%.o: %.c
@echo $@ from $<
es/%.o: %.c
@echo $@ from $<
$ gmake
de/x.o from x.c
en/x.o from x.c
es/x.o from x.c
相关文档可在GNU make手册的 10.5.1模式规则简介中找到:
The relevant documentation is found in 10.5.1 Introduction to Pattern Rules of the GNU make manual:
这篇关于GNU Makefile-具有多个具有一个依赖项的目标的模式规则将忽略除第一个目标以外的所有目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!