【问题标题】:Can GNU Make be made to follow symlinks in rules可以使 GNU Make 遵循规则中的符号链接吗
【发布时间】:2019-02-16 18:25:24
【问题描述】:

我有一个使用 GNU Make 进行构建的大型项目。一些规则依赖于符号链接,而其他规则的目标是符号链接引用的文件。

这是我所说的一个简单示例:

# assume the following symlink exists s-b2 -> f-b2

f-b1 :
    touch f-b1

f-b2 : f-b1
    touch f-b2

f-b3 : s-b2
    touch f-b3

我看到的行为是依赖于符号链接的最终规则没有完全链接到早期的规则。例如。对早期文件的更新不会导致重新评估后面的规则。您可以查看详细的失败并通过this github project 自己尝试。

在计算规则依赖时,有什么方法可以告诉 make 遵循符号链接?

【问题讨论】:

  • 我猜你已经尝试过-L, --check-symlink-times Use the latest mtime between symlinks and target.。不幸的是,它只能解决一半的问题:-(
  • 没有简单的方法可以做到这一点,因为 make 使用简单的文本比较来匹配目标和先决条件。它没有磁盘上文件的一些底层表示,该文件可以有多个名称,这些名称都被理解为同一个意思。您可以使用 $(realpath s-b2) 之类的东西作为先决条件,这将在 make 内部化之前扩展名称。
  • 感谢 cmets。正如你所说-L 不能完全工作。 $(realpath s-b2) 非常有趣,但它可能需要很长时间,因为依赖关系很大。我可能会尝试它,但是生成了 makefile,所以我可能只是让生成器遵循符号链接。无论如何,感谢您让我知道 make 似乎无法自然地做到这一点。
  • 原来用realpath替换依赖的正确方法是$(shell realpath --relative-to=. s-b2)
  • 如果你控制发电机,更新它是要走的路。我也可以,咳咳,建议忍者。

标签: makefile gnu-make


【解决方案1】:

如果您没有对符号链接做任何花哨的事情,也许尝试触摸链接?

all : f-b3

init : clean
        ln -s -f f-b2 s-b2

clean :
        -rm f-* s-*

f-b1 :
    touch f-b1 # not necessarily just touch in real makefile

f-b2 : f-b1
    touch f-b2

s-b2 : f-b2
    touch s-b2 # would be just this in real makefile

f-b3 : s-b2
    touch f-b3

示例制作结果:

$ make init
rm f-* s-*
ln -s -f f-b2 s-b2
$ make
touch f-b1
touch f-b2
touch s-b2
touch f-b3
$ touch f-b1
$ make
touch f-b2
touch s-b2
touch f-b3
$ touch f-b2
$ make
touch f-b3

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 2014-02-02
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2012-09-19
    • 1970-01-01
    相关资源
    最近更新 更多