?
Solved

Phony targets and "make"

Posted on 2002-07-23
10
Medium Priority
?
253 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

839 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