Use the right compiler and flags for configure tests, but don't use
CFLAGS/CXXFLAGS when checking headers because if building universal
the multiple -arch flags would cause this error:
clang: error: cannot use 'c++-cpp-output' output with multiple -arch options

This patch replaces "cc" or "c++" at the beginning of $1 with the right
compiler and flags from the environment variables. This is done (instead
of just checking if $1 is exactly equal to "cc" or "c++") to accommodate
the use case where $1 also contains some flags, which currently occurs
when configure invokes headercheck to find evas.
--- config/functions.bak	2015-02-23 08:26:30.000000000 -0600
+++ config/functions	2019-01-10 14:25:50.000000000 -0600
@@ -1,3 +1,8 @@
+: "${CC:=cc}"
+: "${CFLAGS:=}"
+: "${CPPFLAGS:=}"
+: "${CXX:=c++}"
+: "${CXXFLAGS:=}"
 
 # Initalization
 #
@@ -41,6 +46,25 @@
   eval $1'="${'$1'#$b$a}"'
 }
 
+# Remove at the beginning of a variable.
+#	var_remove_prefix var separator prefix
+#
+var_remove_prefix() {
+  local a=${2//\/\\/}
+  local b=${3//\/\\/}
+  eval '[ "$'$1'" = "$3" ] && '$1'="" || true'
+  eval $1'="${'$1'#$b$a}"'
+}
+
+# Replace at the beginning of a variable.
+#	var_replace_prefix var separator prefix content
+#
+var_replace_prefix() {
+  eval 'case "$'$1'$2" in "$3$2"*) true;; *) false;; esac;' || return 0
+  var_remove_prefix "$1" "$2" "$3"
+  var_insert "$1" "$2" "$4"
+}
+
 # Test for a key in a give "array".
 #	in_list key values
 #
@@ -358,6 +381,9 @@
 compile () {
   local errors=0
   local PROG="$1" ; shift
+  local COMPILER="$PROG"
+  var_replace_prefix COMPILER " " cc "$CC $CPPFLAGS $CFLAGS"
+  var_replace_prefix COMPILER " " c++ "$CXX $CPPFLAGS $CXXFLAGS"
 
   while [ "$1" ] ; do
 	local file="config/$PROG-$1"
@@ -369,7 +395,7 @@
 	  cflags="`grep -a CFLAGS= $file | sed 's/.* CFLAGS="\(.*\)".*/\1/'`"
 	  libs="`grep -a LIBS= $file | sed 's/.* LIBS="\(.*\)".*/\1/'`"
 	  status "$desc ... "
-	  if $PROG -c $cflags $libs $file -o config.tmp \
+	  if $COMPILER -c $cflags $libs $file -o config.tmp \
 	     >/dev/null 2>> config.log ; then
 		status_result "yes"
 	  else
@@ -388,10 +414,13 @@
 headercheck () {
   local errors=0
   local PROG="$1" ; shift
+  local COMPILER="$PROG"
+  var_replace_prefix COMPILER " " cc "$CC $CPPFLAGS"
+  var_replace_prefix COMPILER " " c++ "$CXX $CPPFLAGS"
   while [ "$1" ] ; do
 	echo "#include <$1>" > conftest.c
 	status "checking for header "$1" ... "
-	if $PROG -E conftest.c >/dev/null 2>> config.log ; then
+	if $COMPILER -E conftest.c >/dev/null 2>> config.log ; then
 	  status_result "found"
 	else
 	  status_result "not found"
@@ -413,6 +442,8 @@
 
   if [ $mode = lib -o $mode = header ]; then
 	local prg="$1"; shift
+	var_replace_prefix prg " " cc "$CC $CPPFLAGS $CFLAGS"
+	var_replace_prefix prg " " c++ "$CXX $CPPFLAGS $CXXFLAGS"
 	local args="$*"; shift $#
   elif [ $mode = shell ]; then
 	local script="$1"; shift
