Makefile目标对生成文件的依赖

编程入门 行业动态 更新时间:2024-10-08 10:28:30
本文介绍了Makefile目标对生成文件的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在运行依赖于生成文件的目标时,我对Make的行为有疑问.

I have a question regarding the behavior of Make when running targets that are dependent on generated files.

考虑到下面的源代码树和Makefile,即使我在第一次运行时生成了所有内容,当我运行它时也需要两次运行才能完成构建".

Given the source tree and Makefile below, when I run this it takes two runs to complete the "build" even though everything was generated on the first run.

$ ls -R .: bar foo Makefile

Makefile

all: foobar work: mkdir -p work work/foo: work foo cp foo work/foo work/bar: work bar cp bar work/bar foobar: work/foo work/bar

make

$ make mkdir -p work cp foo work/foo cp bar work/bar $ ls -R .: work/ bar CMakeLists.txt foo Makefile ./work: bar foo $ make cp foo work/foo $ make make: Nothing to be done for 'all'.

为什么会这样?

推荐答案

您需要将目录设置为 仅订购 的先决条件,否则每次目录更改时都将重新建立目标;在第二次调用期间,work比work/foo更新,因为work/bar是在work/foo之后创建的,所以work的时间戳比work/foo更新.

You need to make the directory an order-only prerequisite, otherwise the targets will be remade each time the directory changes; during the second invocation work is newer than work/foo because work/bar was created after work/foo, so work's timestamp is newer than work/foo.

work/foo: foo | work cp foo work/foo work/bar: bar | work cp bar work/bar

或更简洁

work/foo work/bar: work/%: % | work cp $< $@

更多推荐

Makefile目标对生成文件的依赖

本文发布于:2023-11-12 14:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目标   文件   Makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!