使用 shell 和 % 生成依赖项?

发布于 2024-08-06 03:19:55 字数 374 浏览 3 评论 0原文

我有一堆目录。我想为每个目录构建一个对象。假设 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姜生凉生 2024-08-13 03:19:55

我不认为你可以调用一个过程来计算依赖关系。运行进程来创建依赖项的唯一方法是让变量接收进程的输出并使用该变量,但这并不能解决您的问题。

常见的解决方案是生成依赖文件,并包含它们:

include build/*.depend

build/%: build/%.depend %
    ...

build/%.depend:
     command to generate explicit dependencies for build/% into build/%.depend
     possibly recursive make invocations

第一次构建时,不会生成依赖文件,但构建输出也不会存在,因此构建操作无论如何都会运行。在后续的 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:

include build/*.depend

build/%: build/%.depend %
    ...

build/%.depend:
     command to generate explicit dependencies for build/% into build/%.depend
     possibly recursive make invocations

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.

疾风者 2024-08-13 03:19:55
You could try:
DIR := %
$(shell find $(DIR))
You could try:
DIR := %
$(shell find $(DIR))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文