为什么是工作在我的Makefile不是我的eval函数? [英] Why isn't my eval function in my Makefile working?
问题描述
当我尝试运行下面让文件(更新下面的建议):
When I try to run the following make file (updated with suggestions below):
# Build Directories
src_dir=src
obj_dir=obj
bin_dir=bin
cc=cl
cc_flags=
configs = dbg rel
# create the directory for the current target.
dir_guard=@mkdir -p $(@D)
# source files
src = MainTest.cpp
define build_template =
# object files - replace .cpp on source files with .o and add the temp directory prefix
obj_$(1) = $$(addprefix $$(obj_dir)/$(1)/, $$(addsuffix .obj, $$(basename $$(src))))
testVar = "wooo"
# build TwoDee.exe from all of the object files.
$$(bin_dir)/$(1)/MainTest.exe : $$(obj_$(1))
$$(dir_guard)
$$(cc) -out:$$@ $$(obj_$(1)) -link
# build all of the object files in the temp directory from their corresponding cpp files.
$$(obj): $$(obj_dir)/$(1)/%.obj : $$(src_dir)/%.cpp
$$(dir_guard)
$$(cc) $$(cc_flags) -Fo$$(obj_dir)/$$(1) -c $$<
endef
$(foreach cfg_dir,$(configs),$(eval $(call build_template,$(cfg_dir))))
release: $(bin_dir)/rel/MainTest.exe
debug: cc_flags += -Yd -ZI
debug: $(bin_dir)/dbg/MainTest.exe
$(warning testVar $(testVar))
我得到的是:
$ make
Makefile:41: testVar
make: *** No rule to make target `bin/rel/MainTest.exe', needed by `release'. Stop.
您可以从输出该变量的testvar从未设置见。我根据我的最后一个问题了这些更改:<一href=\"http://stackoverflow.com/questions/11331390/why-doesnt-my-makefile-target-specific-variable-work\">Why没有我的makefile特定目标变量的工作?
You can see from the output that the testVar variable is never set. I made these changes based on my last question: Why doesn't my makefile target-specific variable work?
推荐答案
有一些空间而混淆制作。试试这个:
There are some spaces which confuse Make. Try this:
$(foreach cfg_dir,$(configs),$(eval $(call build_template,$(cfg_dir))))
另外,还要确保您指定正确的对象链接:
Also make sure that you specify the right objects to link:
$$(cc) -out:$$@ $$(obj_$(1)) -link
和作为@Beta在模板定义语法下面的评论中, =
指出需要GNU使3.82或更高版本。因此,更好地从行中省略它:
And as @Beta pointed out in the comments below, the =
in the template definition syntax requires GNU make 3.82 or later. So better omit it from the line:
define build_template
这篇关于为什么是工作在我的Makefile不是我的eval函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!