help-make
[Top][All Lists]
Advanced

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

Re: a little trick about making programs that makes variables...


From: Paul D. Smith
Subject: Re: a little trick about making programs that makes variables...
Date: Thu, 8 Jan 2004 18:14:34 -0500

%% Paolo Gai <address@hidden> writes:

  pg> myvar = $(shell cat goofy)

  pg> all: goofy2
  pg>         make -C . test
  pg> test: $(myvar) goofy
  pg>         @echo "end... did the Done message has been printed?"
  pg> mygoofy:
  pg>         @echo Done!!!
  pg> goofy: goofy2
  pg>         cp goofy2 goofy
  pg> goofy2:
  pg>         echo mygoofy > goofy2

  pg> When executed the first time, goofy will be created -after- the
  pg> expansion of myvar. When executed the second time, the makefile will
  pg> work, printing "Done!!!".

Yes.  That's because variables and functions in a prerequisite context
are expanded when the makefile is read in, before any rules are run.

Read the GNU make manual section "How 'make' Reads a Makefile" to
understand this critical aspect of make.


The only way to do this is change it around so that the file contains
the variable setting itself, and use "include", something like this:

  include goofy

  all: test

  clean:
        rm goofy

  test: $(myvar)
        @echo "end... did the Done message has been printed?"

  mygoofy:
        @echo Done!!!

  goofy:
        echo 'myvar = mygoofy' > $@

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