makefile - 我是否应该使用 .PHONY?

标签 makefile

<分区>

我正在使用生成文件来运行测试。我不确定 .PHONY 的使用。我读过这篇文章:What is the purpose of .PHONY in a makefile? , 但我仍然不确定。

我有以下生成文件:

```

test:
    @# Clear console log before we start.
    @clear

    # Make sure we are not having too much modules.
    @npm prune

    # Make sure we have the required modules.
    @npm install

    @# Clear the console, so we only see the test results.
    @clear

    # Run the test.
    @./node_modules/.bin/mocha-casperjs test.js --reporter=spec

```

我的 make test 命令没有生成任何新文件。我是否应该使用 .PHONY: 测试?但更重要的是,为什么? (或者为什么不呢?)

谢谢!

马尔科姆·金德曼斯

最佳答案

感谢@Wintermute,我得到了问题的答案。他评论道:

If you removed the tab before them, they'd not show up either -- then they'd be make comments instead of shell comments. Anyway, this question seems to be answered quite extensively behind the link you posted. test should be phony so that touch test; make test doesn't claim that test is up to date. What exactly is still unclear?

所以答案是:“是的,我需要将 test 添加到 .PHONY,因为执行命令 touch test 会中断这个 make 命令。

关于makefile - 我是否应该使用 .PHONY?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29601240/

相关文章:

c++ - 如何解决具有多个派生类的抽象基类的继承

c++ - 为什么我会看到此消息 "library not found for -lboost_system"?

c - Makefile - 只需安装(复制文件),无需构建目标

gcc - make 和 gcc 有什么区别?

c - 具有可变目标的 makefile

c++ - 使 LLVM 无法包含 $(LLVM_SRC_ROOT)/Makefile.rules

c++ - 在一个 makefile 中生成多个构建

ubuntu - 在 ubuntu 13.04 上安装 glfw3 - 出现错误

makefile - make - 模式规则目标被错误地视为中间对象

c++ - 链接器错误 : "linker input file unused because linking not done", 未定义对该文件中函数的引用