Linux Makefile如何为每个变量执行函数
我正在尝试设置一个具有依赖项的 Makefile。依赖关系在变量中指定。
MATH_VER=1.1
EXTERNAL_DEPS=MATH GC LOG
我希望它运行一个函数,尝试根据可用的内容找出每个外部库的位置。 所以我添加了一个规则集版本,
all:setversion myexe
setversion:
$(foreach CHKLIB, $(EXTERNAL_DEPS), $(call checklib, $(CHKLIB)))
我有一个功能来检查
checklib = ifeq ($(wildcard $(ROOT)/$(var)/$(var)_VER),)
echo 'Bad dir'
$(var)_ROOT=$SOMEOTHERDIR
else
echo 'Good dir'
$(var)_ROOR=$(ROOT)/$(var)/$(var)_VER
endif
这不工作 - 但我认为它很好地了解了我正在寻找的内容。谁能指出我如何实现这一点? 谢谢
I am trying to setup a Makefile with dependencies. The dependencies are specified in a variable.
MATH_VER=1.1
EXTERNAL_DEPS=MATH GC LOG
I want it to run a function that tries to figure out the location of each of the external libs based on whats available.
So I added a rule setversion,
all:setversion myexe
setversion:
$(foreach CHKLIB, $(EXTERNAL_DEPS), $(call checklib, $(CHKLIB)))
I have the function that does the checking
checklib = ifeq ($(wildcard $(ROOT)/$(var)/$(var)_VER),)
echo 'Bad dir'
$(var)_ROOT=$SOMEOTHERDIR
else
echo 'Good dir'
$(var)_ROOR=$(ROOT)/$(var)/$(var)_VER
endif
This dosent work - but I think it gives a good idea of what Im looking for. Can anyone point me to how this can be accomplished?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:我在我的系统上对此进行了测试,它似乎可以满足您的需要。
请务必查看eval 函数的文档 。
另外,如果您想匹配可能的目录列表,您可以使用以下内容。
Edit: I tested this out on my system and it seemed to do what you need.
Make sure to check out the documentation for the eval function.
Also, if you wanted to match against a list of possible directories you could use the following.
这个网站可能会有所帮助:
请注意在该示例中,存储的是 foreach 调用的结果,而不是调用 foreach 循环中每个函数的副作用。
This site might help:
Note that in the example, the result of the foreach call is what is stored, not the side-effects of calling each function in the foreach loop.