gpt4 book ai didi

c++ - 生成文件行 `test -f `

转载 作者:太空宇宙 更新时间:2023-11-04 07:13:21 25 4
gpt4 key购买 nike

我有一个包含以下行的 Makefile:

 $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<

你能解释一下这条线的作用吗?

注意:Makefile 取自此处:https://projects.coin-or.org/BuildTools/wiki/user-examples

该页面指定了这个:

The generic compilation rules (e.g., .c.o) might look somewhat complicated. But with this, the Makefile can also be used by people who work with the MS compilers (e.g., cl) under Cygwin, since those compilers don't understand the UNIX-type directory paths. In such a case, the CYGPATH_W will have been set to "cygpath -w" by configure, otherwise it is just "echo".

我不会使用 MS 编译器。

最佳答案

test -f thing 是一个 Unix-ism,如果指定的文件存在则返回 true,否则返回 false。 "$<"是 make 规则的源文件。所以test -f '$<' || echo '$(SRCDIR)/'将检查源文件是否存在,如果它存在,将回显 $(SRCDIR)/后跟文件的名称。这将是实际编译器的输入。

它基本上是说“如果文件 X 存在于本地目录中,则编译它。否则(这就是 || 所做的),编译名为 X 的文件位于目录 $(SRCDIR) 中。通过这种方式,您可以将所有源代码放在一个子目录中,然后通过将它们的新拷贝放在与 Makefile 相同的目录中来覆盖某些文件。

关于c++ - 生成文件行 `test -f `,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26690018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com