help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: let me rephrase that -- question about empty commands


From: Paul D. Smith
Subject: Re: let me rephrase that -- question about empty commands
Date: Mon, 15 Dec 2003 22:30:17 -0500

%% "Robert P. J. Day" <address@hidden> writes:

  rpjd> specifically, how does "make" process an empty command; that is,
  rpjd> a command of the form:

  rpjd>      target: ;

  rpjd> in the context of section 3.8 of the make manual, this kind of
  rpjd> target being used as a prerequisite is apparently being used to
  rpjd> *force* the re-evaluation of another target.  but why does it
  rpjd> work that way?

Because the target "target" doesn't exist.  As long as it doesn't exist,
and make has a command script to remake it, make will try to remake it.
And when make tries to remake a file that doesn't exist it always
assumes the target is "new", which forces everything that depends on it
to be remade.

  rpjd> the fact that it has no commands is obviously used to make sure
  rpjd> that no implicit rules will be used to try to build the target
  rpjd> name, that much is easy.

It's actually not true that this rule has no commands.  It does have a
command: the empty string.  This is actually very different from a rule
with no command script at all:

    target:

and they are treated differently by GNU make.

  rpjd> but, given that there are no prerequisites, what does this mean
  rpjd> in terms of needing to be processed?  that is, if there are no
  rpjd> pre-reqs in the above rule, what does it mean to say that it's
  rpjd> out of date and has to be "rebuilt" and will therefore force
  rpjd> rebuilding on the rule for which it is a prerequisite?

If a file is a prerequisite and it doesn't exist, then of course make
must build it.

If that target ever existed, then it would never be rebuilt.  That's why
these kinds of methods are not ideal for forcing a recompile; if someone
every accidentally created that file your build would no longer work
properly.

That's why .PHONY is better; look that up in the manual.

  rpjd> and what if (perchance) someone just happens to create a file
  rpjd> called "target" in this directory?  how does that affect the
  rpjd> processing?  or does it?

See above.

  rpjd> sorry if all this is obvious, but it's just one of those picky
  rpjd> details i'd like to nail down.

If you read the manual section on "Rules without commands or
prerequisites" the pros and cons are discussed there.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]