title: Using ifdef and ifndef directives
body: <p>I'm trying to check whether a variable is defined using <code>ifndef/ifdef</code>, but I keep getting a <code>not found</code> error from the execution. I'm using <code>GNU Make 3.81</code>, and here is a snippet of what I have:</p>
  
  <pre><code>all: _images                 
      $(call clean, .)         
      $(call compile, .)       
      @$(OPENER) *.pdf &amp;       
  
  _images:                     
      $(call clean, "images")  
      $(call compile, "images")
  
  define clean                                             
      @rm -f ${1}/*.log ${1}/*.aux ${1}/*.pdf              
  endef                                                    
  
  define compile                                           
  
      ifdef ${1}                                           
          dir = ${1}                                       
      else                                                 
          dir = .                                          
      endif                                                
  
      ifdef ${2}                                           
          outdir = ${2}                                    
      else                                                 
          outdir = ${1}                                    
      endif                                                
  
      @$(COMPILER) -output-directory ${outdir} ${dir}/*.tex
  
  endef                                                    
  </code></pre>
  
  <p>And the exact error:</p>
  
  <pre><code>$ make                       
  ifdef  "images"              
  /bin/sh: 1: ifdef: not found 
  make: *** [_images] Error 127
  </code></pre>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Considering Barmar comments, here goes the conclusions:</p>
  
  <p>The contents of a define are shell command lines, not make directives;
  to break lines inside commands within a define block, the linebreak must be escaped -- with \;
  also, each block corresponding to one-liner commands is executed separately, each in a different shell execution, which means that, defining local variables won't work if the intention is to access the variable value in the next one-liner block.</p>
  
  <p>Thanks tripleee for the nice work around.</p>