title: How to avoid both GNU Make and shell from unwrapping the commas and apostrophes when defining variables
body: <p>I have a variable called <em>SELF</em> in my makefile that I want to pass to my GCC compiler through the <em>-D</em> option to define a macro. This macro can only have a single character in [0-9a-zA-Z] - but this is another problem in itself I won't try to discuss here -.
  I'm having trouble to find a workaround for avoiding both GNU Make and the shell to remove the commas in the definition.
  An example how it is defined would be:</p>
  <pre class="lang-C prettyprint-override"><code>#include &lt;stdio.h&gt;
  
  #define str(x) #x
  #define xstr(x) str(x)
      
  #ifndef SELF  
  # define SELF '0'
  #endif
  #pragma message(&quot;SELF is: &quot; xstr(SELF))
  
  int main(void){
      return 0;
  }
  
  </code></pre>
  <p>The makefile looks like this:</p>
  <pre class="lang-make prettyprint-override"><code>CC = gcc
  WFLAGS = -Wall -Wextra
  
  ifdef SELF
  DSELF = -DSELF=$(SELF)
  endif
  CFLAGS = -std=c99 $(DSELF)
  
  all: clean test
  
  %: %.o
  
  .PHONY: clean
  clean:
      -rm -v test
  </code></pre>
  <p>If you execute the makefile with <code>make</code>, a note will appear that will tokenize the definition of <em>SELF</em>:</p>
  <pre class="lang-c prettyprint-override"><code>test.c:9:9: note: ‘#pragma message: SELF is: '0'’
      9 | #pragma message(&quot;SELF is: &quot; xstr(SELF))
        |         ^~~~~~~
  </code></pre>
  <p>On the other hand, executing <code>make SELF='0'</code> will destroy the apostrophes, as you can see in the verbose output of GNU Make:</p>
  <pre><code>gcc -std=c99 -DSELF=0    test.c   -o test
  </code></pre>
  <p>If you try to wrap the apostrophes with quotes, like <code>make SELF=&quot;'0'&quot;</code>, the definition will pass to GCC, but even the shell removes the apostrophes since the #pragma message will still display <code>0</code>. BUT if you execute directly <code>gcc -std=c99 -DSELF=&quot;'0'&quot; test.c -o test</code>, the definition will be successfully be done:</p>
  <pre class="lang-c prettyprint-override"><code>test.c:9:9: note: ‘#pragma message: SELF is: '0'’
      9 | #pragma message(&quot;SELF is: &quot; xstr(SELF))
        |         ^~~~~~~
  </code></pre>
  <p>How can you avoid all this from happening? Does this mean you can't define string of the same sorts?</p>