?
Solved

Phony targets and "make"

Posted on 2002-07-23
10
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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
Course of the Month13 days, 8 hours left to enroll

801 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