Makefile GNU

From 탱이의 잡동사니
Jump to: navigation, search


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.

	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
	rm *.o temp