Solved

Phony targets and "make"

Posted on 2002-07-23
10
244 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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.:
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…

920 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

12 Experts available now in Live!

Get 1:1 Help Now