skip to content
Alvin Lucillo

Declare a target non-file

/ 1 min read

If there’s already a file named hello, running make hello will not run the recipe commands because Make found a file. To fix that, the target needs to be declared as phony.

hello:
	@echo "Hello, Make!"
	@echo "This recipe has two commands." > hello.txt
	cat hello.txt
$ make hello
make: 'hello' is up to date.

.PHONY tells Make that hello represents an action, not a file.

.PHONY: hello

hello:
	@echo "Hello, Make!"
	@echo "This recipe has two commands." > hello.txt
	cat hello.txt
$ make hello 
Hello, Make!
cat hello.txt
This recipe has two commands.