Infinite | Squares

Art of code and more

Makefile .PHONY

Currently I am working on a Node.js module to abstract cloud storage interaction with filesystem idioms. My partner in the project suggested to use Makefile for running test scripts. So I created following Makefile

1
2
3
4
5
6
7
8
9
TESTS = test/*.js
REPORTER = dot

test:
  @NODE_ENV=test ./node_modules/.bin/mocha \
    --require should \
    --reporter $(REPORTER) \
    --timeout 5000 \
    $(TESTS)

When I run make test I always got following response

1
2
$ make test
make: `test' is up to date.

So, what is the problem?

Apparently I have a folder named test (which contains all of test scripts). When I run make test, then Make command will be executed againts the test folder.

Enter .PHONY

If you have same command name and file/folder name on your project and you want to execute the command in Makefile, then you have to add .PHONY to tell the compiler to execute the command Makefile. The special rule .PHONY tells Make which targets are not files.

So update the Makefile to

1
2
3
4
5
6
7
8
9
10
11
TESTS = test/*.js
REPORTER = dot

test:
  @NODE_ENV=test ./node_modules/.bin/mocha \
    --require should \
    --reporter $(REPORTER) \
    --timeout 5000 \
    $(TESTS)

.PHONY: test

And the tests are running

Comments