title: Using GNU-make functions to check if variables are defined
body: <p>I'm writing a makefile that requires some enviroment variables to be defined. I am trying to use something like this to acheive this:</p>
  
  <pre><code>define check-var-defined
    ifndef $(1)
      $(error $(1) is not defined)
    endif
  endef
  
  $(call check-var-defined,VAR1)
  $(call check-var-defined,VAR2)
  $(call check-var-defined,VAR3)
  
  rule1:
      #stuff 
  </code></pre>
  
  <p>When I run make with no args I get this:</p>
  
  <pre><code>$ make
  Makefile:7: *** VAR1 is not defined. Stop.
  </code></pre>
  
  <p>But when I run it with VAR1 specified I get the same error. </p>
  
  <pre><code>$ make VAR1=hello
  Makefile:7: *** VAR1 is not defined. Stop.
  </code></pre>
  
  <p>Any ideas why this doesn't work? What can I do to make this work? Thanks in advance.</p>
  
  <p>(Note that I need to check that the variables are actually defined when the makefile is run, as I need to include another makefle further down and the variables need to be set correctly by the time I do this). </p>