Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.PHONY usage in makefile

Tags:

makefile

While searching for the usage of .PHONY in makefile, i came accross this which says something like

.PHONY also allows you to have targets that do not have an associated rule

I put the example metioned in that post in a makefile and I ran that but it is not showing me any error as mentioned in the OP. Can someone please detail it?

The makefile

target1: dostuff

.PHONY: target2
target2: dostuff



dostuff:
        @echo "Stuff gets done!!!!"

O/P

[sourav@titan temp]$ make target1
Stuff gets done!!!!
[sourav@titan temp]$ make target2
Stuff gets done!!!!
[sourav@titan temp]$ make
Stuff gets done!!!!
[sourav@titan temp]$

As per the OP, make target1 should throw an error. Please enlight.

Some Info

[sourav@titan temp]$ uname -r
2.6.18-194.el5PAE
[sourav@titan temp]$ make --version
GNU Make 3.81
[sourav@titan temp]$
like image 846
Sourav Ghosh Avatar asked Oct 20 '22 19:10

Sourav Ghosh


1 Answers

True. A .PHONY target can have only dependencies, without any rule. In this case, make will not execute any rule, but will check if the dependencies are satisfied (and, if not, will execute their rules).

Therefore, in your example, it is correct that both target1 and target2 call dostuff because it is a dependency.

like image 101
Claudio Avatar answered Oct 23 '22 22:10

Claudio