LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2005, 02:18 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
makefile (.PHONY)


I saw alot of makefile which contain a target .PHONY. what it do?
 
Old 03-03-2005, 04:39 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: makefile (.PHONY)

Quote:
Originally posted by blackzone
I saw alot of makefile which contain a target .PHONY. what it do?
A regular makefile-rule looks like this:
Code:
FileToBuild : Other target this one depends on
<tab> Command that generates FileToBuild
These kind of rules with proper dependecy lists after the colon ( : ) make it possible for "make" to do as little work as possible to (re-)build the requested target (file) by checking the modifcation times of sources and targets.

Often rules are used that do not really builds/generates some file. E.g. when you do "make clean" you don't expect "make" to build a file called "clean". Still, "make" cannot guess that, so with a make-rule like this:
Code:
clean:
<tab> rm *.o
... "make" will think "rm *.o" is the command to rebuild a file called "clean" if the file is not there or if it's old.

Normally this will do what we want it to do. But imagine a person creates some file called "clean" by accident or for some reason. Then "make" will not do the cleaning up command (rm *.o) when "make clean" is run, because the file "clean" is "up to date".

Labeling the target "clean" as "phony" will prevent that. It tells "make" that "clean" is a phony target, i.e. not a real file that needs to be kept up to date.

While it may sound like a unlikely thing to happen, it could introduce hard to find errors when it does happen. When makefile's are used with a lot of (phony) targets changes these accindents will actually happen increase. And makefile generated by configure-scripts contain quite a lot of phony targets. Also. listing target as "phony" helps documenting/explaining the makefile itself.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify makefile.in or makefile.am QiangWan Linux - Newbie 1 05-17-2005 11:07 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
makefile moonloader Programming 4 01-05-2004 06:26 AM
Makefile jesLinux Programming 1 07-17-2003 03:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration