这些特殊目标称为 phony ,您可以明确告知Make与文件无关,例如:.PHONY: cleanclean: rm -rf *.o现在,即使您有一个名为clean的文件,make clean也将按预期运行.就Make而言,虚假目标只是始终过期的目标,因此,每当您问make <phony_target>时,它都会运行,而与文件系统的状态无关.常见的通常会发声的make目标是:all,install,clean,distclean,TAGS,info,check.What does .PHONY mean in a Makefile? I have gone through this, but it is too complicated.Can somebody explain it to me in simple terms? 解决方案 By default, Makefile targets are "file targets" - they are used to build files from other files. Make assumes its target is a file, and this makes writing Makefiles relatively easy:foo: bar create_one_from_the_other foo barHowever, sometimes you want your Makefile to run commands that do not represent physical files in the file system. Good examples for this are the common targets "clean" and "all". Chances are this isn't the case, but you may potentially have a file named clean in your main directory. In such a case Make will be confused because by default the clean target would be associated with this file and Make will only run it when the file doesn't appear to be up-to-date with regards to its dependencies.These special targets are called phony and you can explicitly tell Make they're not associated with files, e.g.:.PHONY: cleanclean: rm -rf *.oNow make clean will run as expected even if you do have a file named clean.In terms of Make, a phony target is simply a target that is always out-of-date, so whenever you ask make <phony_target>, it will run, independent from the state of the file system. Some common make targets that are often phony are: all, install, clean, distclean, TAGS, info, check. 这篇关于Makefile中.PHONY的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 10:52
查看更多