title: Makefile ifeq: when are they evaluated?
body: <p>The following is a very simple makefile that does not seem to work properly.</p>
  
  <pre><code>TEST=ON
  
  buildbegin:
  ifeq ($(TEST),ON)        
      @echo TEST PASSED
  else
      @echo TEST FAILED
  endif
  </code></pre>
  
  <p>No matter what I set the TEST variable to, my ifeq statement passes.  I always see TEST PASSED.  Anyone see what I am doing wrong here?</p>
  
  <p>EDIT:</p>
  
  <p>ok.  my example was not exactly accurate.  What I actually have is this:</p>
  
  <pre><code>SHELL = /bin/sh
  
  DEFAULT_TARGS:= all  all_debug  
  DEBUG_TARGS:= all_debug
  ALL_TARGS:= $(DEFAULT_TARGS) $(DEBUG_TARGS)
  
  .PHONY: $(ALL_TARGS)
  .PHONY: buildbegin
  
  $(ALL_TARGS): buildbegin
  
  TEST=ON
  
  $(DEBUG_TARGS): TEST=OFF
  
  buildbegin:
      @echo $(TEST)
  ifeq ($(TEST),ON)
      @echo PASSED
  else
      @echo FAILED
  endif
  </code></pre>
  
  <p>Running either make all or make all_debug will result in "PASSED" being printed.  If I echo $(TEST) before the condition, it looks as if my rules are changing the variable, but the ifeq only ever sees whatever the default value is.</p>