取决于目录下(包括子目录内)所有文件的Makefile规则 [英] Makefile rule that depends on all files under a directory (including within subdirectories)

查看:55
本文介绍了取决于目录下(包括子目录内)所有文件的Makefile规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Makefile中的一条规则将整个目录(res/)压缩为ZIP文件.显然,当res/目录下的 any 文件更改时,需要执行此规则.因此,我希望该规则具有该目录下所有文件的先决条件.如何执行此规则?

One rule in my Makefile zips an entire directory (res/) into a ZIP file. Obviously, this rule needs to execute when any file under the res/ directory changes. Thus, I want the rule to have as a prerequisite all files underneath that directory. How can I implement this rule?

在Bash 启用了globstar选项的情况下,您可以获得列表使用通配符模式res/**/*的目录中的所有文件.但是,如果您在Makefile中将它指定为先决条件,则它似乎不起作用:

In Bash with the globstar option enabled, you can obtain a list of all the files in that directory using the wildcard pattern res/**/*. However, it doesn't seem to work if you specify it as a prerequisite in the Makefile:

filename.jar: res/**/*

即使touchres/中的文件之后,仍然制作报告

Even after touching a file in res/, Make still reports

make: `filename.jar' is up to date.

因此很明显,它无法识别模式.

so clearly it is not recognizing the pattern.

如果我声明目录本身为先决条件:

If I declare the directory itself as a prerequisite:

filename.jar: res

然后,在修改文件时,Make不会重新执行(我认为make仅查看目录本身的修改日期,只有在添加,删除或重命名直接子级时,该日期才会更改).

then Make will not re-execute when a file is modified (I think make only looks at the modified date of the directory itself, which only changes when immediate children are added, removed, or renamed).

推荐答案

此:

filename.jar: $(wildcard res/**/*)

至少在某些平台上似乎可以正常工作.

seems to work, at least on some platforms.

或者更好,只是打个结:

Or better, just cut the knot:

filename.jar: $(shell find res -type f)

这篇关于取决于目录下(包括子目录内)所有文件的Makefile规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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