From 3f6fc35cc28387e327cb6f47feb00061ed17b84c
From: Mamoru TASAKA <mtasaka@fedoraproject.org>
Date: Sat, 30 Apr 2022 13:32:34 +0900
Subject: [PATCH] configure.ac: reset compiler flags before calling
 AC_CHECK_DECLS

With autoconf 2.71, [AC_CHECK_DECLS] calls new internal macro
[_AC_UNDECLARED_BUILTIN], which raises error with unknown compiler
flag. On non-x86 archs, -mavx or so is not recognized, so configure
fails on such architecture.

To fix this, reset vector related compiler flags before calling
AC_CHECK_DECLS.

*OPENWRT EDIT: typo "sse_flags"
---
 configure.ac | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- a/configure.ac
+++ b/configure.ac
@@ -674,11 +674,19 @@ AC_CHECK_HEADERS([sys/types.h sys/un.h a
 
 save_cxxflags="${CXXFLAGS}"
 save_cppflags="${CPPFLAGS}"
-CXXFLAGS="${CXXFLAGS} -msse3"
-CPPFLAGS="${CPPFLAGS} -msse3"
+sse3_flags="-msse3"
+avx_flags="-mavx"
+CXXFLAGS="${save_cxxflags} ${sse3_flags}"
+CPPFLAGS="${save_cppflags} ${sse3_flags}"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([],)], [], [sse3_flags=""])
+CXXFLAGS="${save_cxxflags} ${avx_flags}"
+CPPFLAGS="${save_cppflags} ${avx_flags}"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([],)], [], [avx_flags=""])
+CXXFLAGS="${save_cxxflags} ${sse3_flags}"
+CXXFLAGS="${save_cxxflags} ${sse3_flags}"
 AC_CHECK_HEADERS([intrin.h x86intrin.h pmmintrin.h xmmintrin.h emmintrin.h])
-CXXFLAGS="${save_cxxflags} -mavx"
-CPPFLAGS="${save_cppflags} -mavx"
+CXXFLAGS="${save_cxxflags} ${avx_flags}"
+CPPFLAGS="${save_cppflags} ${avx_flags}"
 AC_CHECK_HEADERS([immintrin.h avxintrin.h])
 
 AC_CHECK_DECLS([_xgetbv, xgetbv, __xgetbv, cpuid, _cpuid, __cpuid],
