Solved

Phony targets and "make"

Posted on 2002-07-23
10
247 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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

732 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