[Top][All Lists]

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

Re: more make questions

From: Paul D. Smith
Subject: Re: more make questions
Date: 02 Feb 2006 03:31:32 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

%% "James" <> writes:

  j> S:
  j>         @echo $@ $(VAR)
  j> ifeq ($(VAR),)
  j>         @echo VAR is an empty string
  j> else
  j>         @echo VAR=$(VAR)
  j> endif

Make preprocessor statements like ifdef, ifeq, etc. are all parsed as
the makefile is read in (similar to C preprocessor statements like
#ifdef etc.)

The target-specific value of VAR is only set much later, when make tries
to run the rule; by that time it's far too late to have any relevance to
the ifeq.

If you want an if statement that is evaluated at runtime, rather than at
makefile read time, you need to use the shell's conditional, or else use
make's $(if ...) function inside the command script (prefixed by a TAB):

            @echo $@ $(VAR)
            @if [ -z "$(VAR)" ]; then \
                echo VAR is an empty string; \
             else \
                echo VAR=$(VAR); \


            @echo $@ $(VAR)
            @echo $(if $(VAR),VAR=$(VAR),VAR is an empty string)

One of the most critical and fundamental things to understand about make
is the difference between the makefile read-in step and the run-time
step of make processing, and which make constructs are expanded at which
time.  There's a section in the GNU make manual called "How 'make' Reads
a Makefile" which tries to explain this.

 Paul D. Smith <>          Find some GNU make tips at:            
 "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]