title: GNU make conditional function $(if ...) inside a user-defined function always evaluates to true
body: <p>I am trying to write a make function to touch/create an empty file and/or set the permissions, user and group, where possible, or warn if not. However, every conditional check within my function seems to evaluate to true.</p>
  
  <p>The essentials of my Makefile are</p>
  
  <pre><code>INSTALL_USER  := fileUser
  INSTALL_GROUP := fileGroup
  
  .PHONY: test
  test:
      $(call touchFile,~/test.ini)
  
  define touchFile
  $(eval fileName := $(strip $(1)))
  -touch $(fileName)
  -chmod -c 664 $(fileName)
  
  $(info filename info $(fileName))
  $(info $(shell stat -c "%a %U:%G" $(fileName)))
  
  $(if ifeq  "foo" "bar", @echo match is broken, @echo match works)
  $(if ifneq "foo" "bar", @echo match works, @echo match is broken)
  
  $(if ifneq ($(shell stat -c %a $(fileName)),664), $(warning Error - $(fileName) does not have expected permissions of 664))
  -chgrp -c $(INSTALL_GROUP) $(fileName)
  $(if ifneq ($(shell stat -c %G $(fileName)),$(INSTALL_GROUP)), $(warning Error - $(fileName) does not belong to $(INSTALL_GROUP) group))
  -chown -c $(INSTALL_USER) $(fileName)
  $(if ifneq ($(shell stat -c %U $(fileName)),$(INSTALL_USER)), $(warning Error - $(fileName) does not belong to $(INSTALL_USER) user))
  endef
  </code></pre>
  
  <p>Running <code>make test</code> outputs</p>
  
  <pre><code>filename info ~/test.ini
  664 myUserName:myGroup
  Makefile:7: Error - ~/test.ini does not have expected permissions of 664
  Makefile:7: Error - ~/test.ini does not belong to common group
  Makefile:7: Error - ~/test.ini does not belong to netserve user
  touch ~/test.ini
  chmod -c 664 ~/test.ini
  match is broken
  match works
  chgrp -c fileGroup ~/test.ini
  changed group of `/home/myUserName/test.ini' to fileGroup
  chown -c fileUser ~/test.ini
  chown: changing ownership of `/home/myUserName/test.ini': Operation not permitted
  make: [test] Error 1 (ignored)
  </code></pre>
  
  <p>I've considered/tried the following:</p>
  
  <ul>
  <li>$(if ...) is evaluated at "compile-time", before the function is called with a parameter. But, the hard-coded <code>ifeq  "foo" "bar"</code> also gives an invalid result. Additionally, <code>$(info ...)</code> correctly evaluates <code>$(fileName)</code> at "compile-time".</li>
  <li>The <a href="http://www.gnu.org/software/make/manual/make.html#Conditional-Functions" rel="noreferrer">documentation</a> doesn't actually give examples, so in addition to <code>$(if ifeq...)</code>, I also tried <code>$(ifeq ...)</code>, which seemed to be ignored.</li>
  <li>"Non-functional" <code>if</code> (i.e., the <code>ifeq</code> without the <code>$(if...)</code>) inside a function gives <code>/bin/sh: ifeq: command not found</code>.</li>
  </ul>
  
  <p>Can someone help identify why my conditionals aren't behaving as I expect (or why I'm expecting the wrong thing)?</p>
  
  <p><strong>Caveat:</strong> I know there are still bugs to be worked out if the file doesn't exist, but that should be trivial compared to this hurdle.</p>