重新评估make中的通配符 [英] reevaluate wildcard in make

查看:96
本文介绍了重新评估make中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Makefile中,我想检查某个文件是否存在,执行某些操作,然后再次检查.使用gnu make,我不能.这是简单的示例:

In my Makefile, I want to check if a certain file exists, do something, and check again. Using gnu make, I cannot. Here is the simple example:

$(info $(wildcard OK))
$(shell touch OK)
$(info $(wildcard OK))

如果我运行一次make,我会看到两个空行.如果再次运行make,则这两行都是OK.

If I run make once, I see two empty lines. If I run make again, both lines are OK.

我想,也许$(eval)会让我得到更新的答案. las,

I thought, maybe $(eval) will let me get the updated answer. Alas,

$(eval $$(info $$(wildcard OK)))

产生相同的答案,就像make在开始评估其他命令之前可以通过某种方式预测所有通配符计算一样.

produces the same answer, as if make has some way to predict all wildcard calculations before it starts evaluating other commands.

我需要这样做才能满足Android NDK进行的检查:我必须生成一个

I need this to satisfy the checks performed by Android NDK: I must generate a prebuilt shared library on the fly.

推荐答案

此方法不起作用,因为为了提高性能,make维护目录内容的内部缓存.当前,仅当make运行规则时才更新该高速缓存:然后,将定义该规则创建的目标添加到高速缓存中.在您的情况下,make无法知道文件系统已被修改,因此不会更新缓存.

This cannot work because, for performance, make maintains an internal cache of the directory contents. Currently that cache is only updated when make runs a rule: then the target the rule is defined to create will be added to the cache. In your situation make has no way to know that the filesystem has been modified so it won't update the cache.

您必须使用外壳程序,而不是wildcard;外壳不知道make的内部缓存:

You have to use the shell, rather than wildcard; the shell doesn't know about make's internal caches:

$(info $(wildcard OK))
$(shell touch OK)
$(info $(shell [ -f OK ] && echo OK))

很明显,这是一个伪造的示例,但是我敢肯定您的真实代码与此明显不同.

Clearly this is a bogus example but I'm sure your real code is significantly different than this.

唯一的替代方法是将您需要运行的命令转换为规则.但同样,由于该问题与您真正想做的事情无关,所以我无法建议一个可行的解决方案.

The only other alternative is to turn the command you need to run into a rule. But again, since the question bears little relation to what you're really trying to do I can't suggest a solution that would work for that.

这篇关于重新评估make中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆