help-make
[Top][All Lists]
Advanced

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

Re: order in Makefile


From: Paul D. Smith
Subject: Re: order in Makefile
Date: Tue, 30 Jul 2002 10:57:56 -0400

%% address@hidden writes:

  yi> Is the order of definitions and actions in makefile important?

In some cases yes, in some cases no.

See the GNU make manual, section on "How Make Reads a Makefile" for
information on when variables are expanded in various contexts in a
makefile.

The GNU make manual is your friend :).

  yi> VAR1= ...
  yi> VAR2=...

  yi> clean:  ...
  yi>       ...

  yi> VAR3= $(shell ....)

  yi> make_dep: ....
  yi>       .....

  yi> Will VAR3 be calculated (= executing the shell command) ONLY for
  yi> make_dep ?

The shell command in VAR3 will be invoked every single time the value of
VAR3 is used.

Recursive variables, like the ones you're using above, have their
contents re-expanded every time they are used.

Compare this to simply-expanded variables (:=).  See the GNU make manual
for information on the difference.

  yi> or does the make parser first calculates all definition and then
  yi> starts checking for actions ?

It doesn't really work like that.  Make parses the entire makefile, and
as it does so it will expand variables as needed to construct the
dependency graph.  Again, see the GNU make manual for details.

Then, after the makefiles are all read, make will start to invoke
command scripts to build targets that are out of date.  As it attempts
to build each target, it will evaluate the variables in that target's
command scripts.

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