使用 shell 和 % 生成依赖项?
我有一堆目录。我想为每个目录构建一个对象。假设 OBJS 包含“build/dir1 build/dir2 build/dir3”,并且我匹配的模式是
build/%: %
<do something here>
我想为每个对象添加该目录中每个文件的依赖项(递归地)。我想做一些类似的事情
build/%: $(shell find %)
<do something here>
,但似乎第二个“%”没有扩展。我怎样才能让它发挥作用?
(我注意到的奇怪的事情是“$(shell echo %)”中的“%”被扩展了。)
谢谢。
I have a bunch of directories. I want to build an object for each directory. Suppose OBJS contains "build/dir1 build/dir2 build/dir3", and the pattern I'm matching is
build/%: %
<do something here>
I'd like to add, for each object, dependencies for every file within that directory (recursively). I thought of doing something like
build/%: $(shell find %)
<do something here>
But it seems like the second '%' is not expanded. How can I get this working?
(Weird thing that I noticed is that the '%' in '$(shell echo %)' is expanded.)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你可以调用一个过程来计算依赖关系。运行进程来创建依赖项的唯一方法是让变量接收进程的输出并使用该变量,但这并不能解决您的问题。
常见的解决方案是生成依赖文件,并包含它们:
第一次构建时,不会生成依赖文件,但构建输出也不会存在,因此构建操作无论如何都会运行。在后续的 make 调用中,包含文件就在那里,并由 make 考虑。
I don't think you can invoke a process to compute the dependencies. The only way to run a process to create dependencies is by having a variable receive the output of a process and use that variable, but that won't solve your problem.
The common solution is to generate dependency files, and include them:
The first time you build, no dependency file will be generated, but the build outputs won't be there, either, so the build action will run, anyway. On subsequent make invocations, the include files are there, and considered by make.