如何复制Makefile中的目录?

发布于 2024-09-06 09:30:13 字数 452 浏览 3 评论 0原文

我有一个目录 images/ ,我想从 Makefile 中将其复制到 build/images/ 。该目录可能包含多个级别的子目录。最优雅的方法是什么?我想要:

  • 避免在每次 make 运行时进行完整目录复制(即没有 cp -r
  • 保证一致性(即如果 images/ 中的文件发生更改> 它应该在 build/images/ 中自动更新)
  • 避免为 Makefile 中的每个图像和每个子目录指定规则
  • 解决 make 中的问题,所以没有 rsynccp -u 如果可能的话

我使用的是 GNU make,所以允许 GNU 特定的东西。

I have a directory images/ that I want to copy to build/images/ from within a Makefile. The directory might contain multiple levels of subdirectories. What would be the most elegant way to do that? I want:

  • avoid a full directory copy on each make run (i.e. no cp -r)
  • guaranteed consistency (i.e. if a file changed in images/ it should be automatically updated in build/images/)
  • avoid to specify a rule for each image and each subdirectory in the Makefile
  • solve the issue within make, so no rsync or cp -u if possible

I am using GNU make, so GNU specific stuff is allowed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

看春风乍起 2024-09-13 09:30:13

好吧,我只使用 rsync。您将使用这些约束创建的任何 make 脚本都只会复制其功能,并且很可能会变慢并且可能包含错误。示例规则可能如下所示:(

build/images:
    rsync -rupE images build/

.PHONY: build/images

.PHONY 每次都会触发规则)。

也许可以使用符号链接或硬链接来代替?

build/images:
    ln -s ../images build/images

如果你真的想避免 rsync 和链接,这篇文章会以某种方式重新实现它们(未经测试,需要 findmkdir 和普通 <代码>cp):

image_files:=$(shell find images -type f)
build/images/%: images/%
    mkdir -p $(@D)
    cp 
lt; $@

build: $(patsubst %,build/%,$(image_files))

Well, I'd just use rsync. Any make script you will create with these constraints will just replicate its functionality, and most probably will be slower and may contain bugs. An example rule might look:

build/images:
    rsync -rupE images build/

.PHONY: build/images

(.PHONY to trigger the rule every time).

Maybe symlinks or hardlinks can be used instead?

build/images:
    ln -s ../images build/images

If you really want to avoid rsync and links, this piece re-implements them somehow (not tested, needs find, mkdir, and plain cp):

image_files:=$(shell find images -type f)
build/images/%: images/%
    mkdir -p $(@D)
    cp 
lt; $@

build: $(patsubst %,build/%,$(image_files))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文