Makefile GNU: Difference between revisions
(Created page with "== Overview == Makefile 작성법 내용 정리 == Basic == category:programming") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
Makefile 작성법 내용 정리 | Makefile 작성법 내용 정리 | ||
== | == Phony target == | ||
A phony target is one that is not really the name of a file; rather it is just a name for arecipe to be xecuted when you make aexplicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance. | |||
[[category: | If you write a rule whose recipe will not create the target file, the recipe will be executed every time the target comes up for remaking. | ||
<pre> | |||
clean: | |||
rm *.o temp | |||
</pre> | |||
Because the rm command does not create a file named clean, probably no such file will ever exist. Therefore, the rm command will be executed every time you say "make clean". | |||
In this example, the clean target will not work properly if a file named clean is ever created in this directory. Since it has no prerequisites, clean would always be considered up to date and its recipe would not be executed. To avoid this problem you can explicitly declare the target to be phony by making it a prerequisite of the special target .PHONY as follows: | |||
<pre> | |||
.PHONY: clean | |||
clean: | |||
rm *.o temp | |||
</pre> | |||
[[category:makefile]] |
Latest revision as of 15:31, 21 March 2020
Overview
Makefile 작성법 내용 정리
Phony target
A phony target is one that is not really the name of a file; rather it is just a name for arecipe to be xecuted when you make aexplicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance.
If you write a rule whose recipe will not create the target file, the recipe will be executed every time the target comes up for remaking.
clean: rm *.o temp
Because the rm command does not create a file named clean, probably no such file will ever exist. Therefore, the rm command will be executed every time you say "make clean".
In this example, the clean target will not work properly if a file named clean is ever created in this directory. Since it has no prerequisites, clean would always be considered up to date and its recipe would not be executed. To avoid this problem you can explicitly declare the target to be phony by making it a prerequisite of the special target .PHONY as follows:
.PHONY: clean clean: rm *.o temp