7

I have a makefile with something like the following targets:

install:
    do a whole bunch of stuff to install

dist: install
    cp README.txt $(INSTALL_DIR)
    zip $(INSTALL_DIR)

I am trying to not repeat the commands from target install and make dist execute install first before executing its own commands.

Calling make dist does indeed execute all commands from target install but then just stops and it does not execute its own commands, e.g. the cp.

Am I missing something?

2
  • 1
    Normally, your 'install' rule would depend on 'all' or thereabouts, and 'all' would do the 'whole bunch of stuff to build', leaving 'install' to do the 'whole bunch of stuff to install'. Mar 20, 2010 at 5:40
  • @Jonathan Yes, that's actually what it is doing. I will edit that.
    – cschol
    Mar 20, 2010 at 5:42

1 Answer 1

10

try to add this line in your makefile

.PHONY : install dist

3
  • That was it. Can you elaborate why this is necessary? Thanks.
    – cschol
    Mar 20, 2010 at 5:38
  • 1
    Was the install directory called 'install' (or perhaps 'dist')? That tends to confuse things. The '.PHONY' notation (a GNU Make extension) means roughly that the 'target' is to be treated as always out of date. Mar 20, 2010 at 5:45
  • 6
    To elaborate on what Jonathan said about .PHONY, think of it like this: Make assumes all targets are actual files and looks to see if it can find the file, if it can't the file is considered out of date and the rule executed. .PHONY tells make that it's not really a file, so don't look for it or try to match it to any patterns/rules and of course if there really is a file/directory called that, don't take that file to be the target, potentially treating the target as up to date. gnu.org/s/hello/manual/make/Phony-Targets.html
    – jhabbott
    Nov 30, 2011 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.