[Top][All Lists]

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

Re: 'How makefiles are remade'

From: Paul D. Smith
Subject: Re: 'How makefiles are remade'
Date: Wed, 21 Apr 2004 02:11:17 -0400

%% Jim <address@hidden> writes:

  j> That would be fine, if that even worked, that would probalby solve
  j> about 90% of the problems just by cleverly odering the
  j> includes... but, as I started, the first attached makefile fails,
  j> and it includes 'ticks' which if Makefile or one of the other
  j> touchable things changes, remakes ticks, which should cause a
  j> reload with the current, updated value.  Then x is included, and
  j> again, x needs to be updated, which will cause x to be regenerated
  j> with the current value of ticks, which in turn should do the same
  j> for y....


  j> but this is not what happens,

Yes it is, if you write it correctly.

  j> and what you're really saying is that only the LAST included file
  j> can be re-loaded, since ALL includes are read before their
  j> dependancies are even checked.

Well, your second statement is true: all includes (that exist) _ARE_
read in first, then make tries to create any included files that were
read (or failed to be read), and if any changed it re-execs itself.

  j> And THAT is not at all what the documentation indicates, it says -

  j> " if any have actually been changed, make starts with a clean slate and 
  j> reads all the makefiles over agai"

  j> if ANY changed, clean all, and reload all again...

Yes, exactly.

Consider this makefile; it works exactly as you expect (IIUC).  The
warning statements prove that make is re-execing at every step:

  $(warning Reading makefile)

  include first.mk

  all:: ; @echo "MAIN"

        @echo 'include second.mk' > $@
        @echo 'all:: ; @echo FIRST' >> $@
        @echo 'first.mk: second.mk' >> $@
        @echo 'second.mk:' >> $@
        @echo ' @echo "all:: ; @echo SECOND" >> $$@' >> $@

  clean: ; rm -f *.mk

Note that in the last @echo line, you have to make sure a TAB character
is inserted in the string that is echoed.

Yes, it's gross, but it does work as you expect.  Here's a sample run:

  temp$ make
  makefile:1: Reading makefile
  makefile:3: first.mk: No such file or directory
  makefile:1: Reading makefile
  first.mk:1: second.mk: No such file or directory
  makefile:1: Reading makefile

  temp$ make
  makefile:1: Reading makefile

I still think you may find using $(eval ...) to be overall simpler.

 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]