Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I be using .PHONY or not? [duplicate]

Tags:

makefile

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

like image 460
Malcolm Kindermans Avatar asked Dec 07 '25 07:12

Malcolm Kindermans


1 Answers

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.

like image 153
Malcolm Kindermans Avatar answered Dec 09 '25 04:12

Malcolm Kindermans