From d619ccf6c11ab574466914c57994a82fb99401af Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Wed, 22 Mar 2017 16:06:55 +0000
Subject: [PATCH] configure: Check for clang

Disable gcc specific options if using clang

Upstream-Status: Inactive-Upstream [https://gitlab.xiph.org/xiph/vorbis,https://github.com/xiph/vorbis]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---

 configure.ac | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,16 @@ AC_ARG_ENABLE(examples,
 
 AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$enable_examples" = xyes])
 
+AC_MSG_CHECKING([whether C compiler is clang])
+$CC -x c /dev/null -dM -E > conftest.txt 2>&1
+if grep "__clang__" conftest.txt >/dev/null 2>&1; then
+  AC_SUBST([CC_CLANG], [1])
+   AC_MSG_RESULT([yes])
+ else
+   AC_SUBST([CC_CLANG], [0])
+   AC_MSG_RESULT([no])
+fi
+
 dnl --------------------------------------------------
 dnl Set build flags based on environment
 dnl --------------------------------------------------
@@ -132,10 +142,15 @@ else
 	AC_MSG_RESULT([$GCC_VERSION])
 	case $host in
 	*86-*-linux*)
+		if test "$CC_CLANG" = "1"; then
+			ieeefp=""
+		else
+			ieefp="-mno-ieee-fp"
+		fi
 		DEBUG="-g -Wall -Wextra -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
-		CFLAGS="-O3 -Wall -Wextra -ffast-math -mno-ieee-fp -D_REENTRANT -fsigned-char"
+		CFLAGS="-O3 -Wall -Wextra -ffast-math -D_REENTRANT -fsigned-char ${ieefp}"
 #              	PROFILE="-Wall -Wextra -pg -g -O3 -ffast-math -D_REENTRANT -fsigned-char -fno-inline -static"
-		PROFILE="-Wall -Wextra -pg -g -O3 -ffast-math -mno-ieee-fp -D_REENTRANT -fsigned-char -fno-inline"
+		PROFILE="-Wall -Wextra -pg -g -O3 -ffast-math ${ieefp} -D_REENTRANT -fsigned-char -fno-inline"
 
 		# glibc < 2.1.3 has a serious FP bug in the math inline header
 		# that will cripple Vorbis.  Look to see if the magic FP stack
@@ -178,12 +193,12 @@ else
   		fi;;
         powerpc-*-linux*spe)
  	        DEBUG="-g -Wall -Wextra -D_REENTRANT -D__NO_MATH_INLINES"
- 	        CFLAGS="-O3 -Wall -Wextra -ffast-math -mfused-madd -D_REENTRANT"
- 	        PROFILE="-pg -g -O3 -ffast-math -mfused-madd -D_REENTRANT";;
+			CFLAGS="-O3 -Wall -Wextra -ffast-math -D_REENTRANT"
+			PROFILE="-pg -g -O3 -ffast-math -D_REENTRANT";;
 	powerpc-*-linux*)
 		DEBUG="-g -Wall -Wextra -D_REENTRANT -D__NO_MATH_INLINES"
-		CFLAGS="-O3 -Wall -Wextra -ffast-math -mfused-madd -mcpu=750 -D_REENTRANT"
-		PROFILE="-pg -g -O3 -ffast-math -mfused-madd -mcpu=750 -D_REENTRANT";;
+		CFLAGS="-O3 -Wall -Wextra -ffast-math -mcpu=750 -D_REENTRANT"
+		PROFILE="-pg -g -O3 -ffast-math -mcpu=750 -D_REENTRANT";;
 	*-*-linux*)
 		DEBUG="-g -Wall -Wextra -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
 		CFLAGS="-O3 -Wall -Wextra -ffast-math -D_REENTRANT -fsigned-char"
