Makefile rule that depends on all files under a directory (including within subdirectories)

£可爱£侵袭症+ 提交于 2019-11-26 19:18:30

问题


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?

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/**/*

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

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).


回答1:


This:

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

seems to work, at least on some platforms.

EDIT:

Or better, just cut the knot:

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


来源:https://stackoverflow.com/questions/14289513/makefile-rule-that-depends-on-all-files-under-a-directory-including-within-subd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!