3

I am using a makefile to run tests. I am not sure about the use of .PHONY. I've read this post: What is the purpose of .PHONY in a makefile?, but still I'm not sure.

I have the following 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

```

My make test command isn't making any new files. Should I be using the .PHONY: test or not? But even more important, why? (or why not?)

Thank you!

Malcolm Kindermans

Community
  • 1
  • 1
  • Those lines starting `@#` are "odd". – trojanfoe Apr 13 '15 at 08:47
  • @trojanfoe Not really, by precending those commented lines with a `@` they are not visible in the output, only in the makefile. – Malcolm Kindermans Apr 13 '15 at 08:49
  • They are comments and therefore ignored by everything anyway. As I say "odd". – trojanfoe Apr 13 '15 at 08:54
  • @trojanfoe That's kinda strange, because when I don't preceed those lines with the `@`, they are printed in the output. – Malcolm Kindermans Apr 13 '15 at 08:55
  • 2
    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? – Wintermute Apr 13 '15 at 08:58
  • @Wintermute Thanks! Now, nothing is unclear anymore. Actually that was all I needed to know :) – Malcolm Kindermans Apr 13 '15 at 09:02
  • I'll (vote to) mark it as a duplicate of the link then. The top answer in that question does explain this, after all. – Wintermute Apr 13 '15 at 09:04

1 Answers1

0

Thanks to @Wintermute I got the answer to my question. He commented:

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?

So the answer is: "Yes, I need to add test to the .PHONY, because executing the command touch test would break this make command.