%% Carlo Wood <[EMAIL PROTECTED]> writes:

I do not believe this is a bug, although it is a bit confusing.  I'll
explain what's happening.

First, you should go read the chapter _How Makefiles Are Remade_ in the
GNU make manual.  This is crux of why you're seeing this behavior.

  cw> FOO="This should not be printed"

  cw> Makefile: foobar
  cw>   @echo Target $@: $(FOO)

This rule is broken.  You're saying that the file "Makefile" should be
rebuilt if the file "foobar" is newer than it... but then the command
doesn't update the target file ("Makefile").

  cw> foobar:
  cw>   @echo Target $@: $(FOO)
  cw>   touch foobar

  cw> Now we get to the bug:

  cw> ~/tmp>make
  cw> Target Makefile: This should not be printed
  cw> make: `Makefile' is up to date.

That's because of the broken rule above: make will try to rebuild
"Makefile" every time as long as "foobar" is newer than it, and since
your command doesn't modify the timestamp on "Makefile" that will never
happen no matter how many times you run make.

  cw> and even:

  cw> ~/tmp>make -n
  cw> Target Makefile: This should not be printed
  cw> make: `Makefile' is up to date.

  cw> It seems that target `Makefile' is ALWAYS executed.

That's because make _always_ tries to rebuild the makefile and all of
its included files, even if you give -n.  Just like it will always
invoke submakes, even if you give -n.

This, I believe, is correct behavior.

If you use generic target names like "foo" instead of targets involving
the "Makefile" file, then you will get the behavior you expect.

  cw> I think this one is also funny:

  cw> ~/tmp>rm foobar
  cw> ~/tmp>make -n
  cw> Target foobar: This should not be printed
  cw> touch foobar
  cw> Target Makefile: This should not be printed
  cw> make: `Makefile' is up to date.

That's because "foobar" is a prerequisite of "Makefile", and make wants
to _really_ rebuild "Makefile", without -n, so it has to _really_
rebuild all the prerequisites of "Makefile", like "foobar", without -n
(otherwise the rebuilding of "Makefile" would most likely fail--else why
would "foobar" be a prerequisite?)

  cw> ~/tmp>rm foobar
  cw> ~/tmp>make -n foobar
  cw> Target foobar: This should not be printed
  cw> touch foobar
  cw> Target Makefile: This should not be printed
  cw> make: `foobar' is up to date.

Same reason as above.

If you remove "foobar" as a prerequisite from the special file
"Makefile", you won't see this behavior anymore WRT "foobar".

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

Reply via email to