Solved

Phony targets and "make"

Posted on 2002-07-23
10
243 Views
Last Modified: 2010-04-21
In my makefile, I want to specify two ways of making the file "fsing".


fsing: dependencies
      construct_fsing_verbosely

fsing_quiet: dependencies(same)
      construct_fsing_quietly

However, since fsing_quiet is a phony target (doesn't correspond to a real file, whether I specify it as .PHONY or not doesn't matter), then if I say "make fsing_quiet" it will run the commands construct_fsing_quietly *whether or not the fsing file is up-to date*.

How do I get the behaviour I want?

Thanks
0
Comment
Question by:glebspy
  • 5
  • 5
10 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7172187
PHONY targets cannot have dependencies, for obvious reason
(they are done always, 'cause you explizizely tell make that there is no file to check the dependencies against)

The PHONY target is always executed if used.

> How do I get the behaviour I want?
Which behaviour do you want?
0
 
LVL 1

Author Comment

by:glebspy
ID: 7172318
I want "make fsing_quiet" to execute "construct_fsing_quietly" only if fsin is up to date.
I want "make fsing" to execute "construct_fsing_verbosely" only if fsing is up to date.
0
 
LVL 1

Author Comment

by:glebspy
ID: 7172320
I want "make fsing_quiet" to execute "construct_fsing_quietly" only if fsing is up to date.
                       I want "make fsing" to execute "construct_fsing_verbosely" only if fsing is up to date.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7172370
if you want to do it in either case, why do you need 2 targets?
Why do you need a target with dependencies, when fsing is the dependency?
0
 
LVL 1

Author Comment

by:glebspy
ID: 7172402
if you want to do it in either case, why do you need 2 targets?

I want to do a different thing in either case.




Why do you need a target with dependencies, when fsing is the dependency?

because I want to invoke use the syntax "make fsing_quiet"
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7172722
> I want to do a different thing in either case.
what is the difference? Your description contains none.

Could you please give working examples.
0
 
LVL 1

Author Comment

by:glebspy
ID: 7172793
what is the difference? Your description contains none.

In one case I want the executable "construct_fsing_verbosely" to be run, and in the other
case I want "construct_fsing_quietly" to be run. These are applications which construct the same target but one produces a lot of output, and the other doesn't. I hope that is clear.

A simple example could be with rsync, although my applications are not so simple:

fsing: dependencies
      /usr/bin/rsync --verbose me@foreign_host:fsing .

fsing_quiet: dependencies
      /usr/bin/rsync me@foreign_host:fsing .
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 7173671
ok, I got it, but (quote from your original question):

> .. doesn't correspond to a real file .. whether or not the fsing file is up-to date

as you know yourself, phony targets do not generate/use a target file, so they also cannot check against dependencies (see my very first comment).

try following:

fsing_verbose: dependencies
     construct_fsing_verbosely
     @touch $@
fsing_quiet: dependencies
     construct_fsing_quietly
     @touch $@
0
 
LVL 1

Author Comment

by:glebspy
ID: 7174002
ok thanks for helping ahoffman
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7174594
Thanks for grading.

And don't forget to remove these targets from the .PHONY: list ('cause they are no longer phony targets).
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now