configure: fix NEON flag detection under gcc 6

use a compile check on a separate file to avoid assuming using
arm_neon.h is safe to use without flags when just the file itself is
self-contained with GCC target pragmas.

BUG=webp:313

Change-Id: I48f92ae3e6e4a9468ea5b937c80a89ee40b2dcfd
(cherry picked from commit 0104d730bf)
This commit is contained in:
James Zern 2016-10-05 00:03:14 -07:00
parent 83cbfa09a1
commit 42ebe3b783

View File

@ -10,6 +10,7 @@ dnl === it must occur before LT_INIT (AC_PROG_LIBTOOL).
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
AC_PROG_SED
AM_PROG_CC_C_O AM_PROG_CC_C_O
dnl === Enable less verbose output when building. dnl === Enable less verbose output when building.
@ -195,40 +196,51 @@ AC_ARG_ENABLE([neon_rtcd],
AS_IF([test "x$enable_neon" != "xno"], [ AS_IF([test "x$enable_neon" != "xno"], [
case "$host_cpu" in case "$host_cpu" in
arm|armv7*) arm|armv7*)
dnl Test for NEON support with no flags. # Test for NEON support without flags before falling back to -mfpu=neon
AC_CHECK_HEADER([arm_neon.h], for flag in '' '-mfpu=neon'; do
[AC_DEFINE(WEBP_HAVE_NEON, [1], LOCAL_NEON_FLAGS="$INTRINSICS_CFLAGS $NEON_FLAGS"
[Set to 1 if NEON is supported])], TEST_AND_ADD_CFLAGS([LOCAL_NEON_FLAGS], [$flag])
dnl Test for NEON support using -mfpu=neon SAVED_CFLAGS=$CFLAGS
[unset ac_cv_header_arm_neon_h CFLAGS="$CFLAGS $LOCAL_NEON_FLAGS"
NEON_FLAGS="$INTRINSICS_CFLAGS $NEON_FLAGS"
TEST_AND_ADD_CFLAGS([NEON_FLAGS], [-mfpu=neon]) dnl Note AC_LANG_PROGRAM([]) uses an old-style main definition.
AS_IF([test -n "$NEON_FLAGS"], [ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
SAVED_CFLAGS=$CFLAGS #include <arm_neon.h>
CFLAGS="$CFLAGS $NEON_FLAGS" int main(void) {
AC_CHECK_HEADER([arm_neon.h], int8x8_t v = vdup_n_s8(0);
[AS_IF([test "${host_os%%-*}" = "linux" -o \ (void)v;
"x$enable_neon_rtcd" = "xno"], [ return 0;
AC_DEFINE(WEBP_HAVE_NEON, [1], }])],
[Set to 1 if NEON is supported])], [NEON_FLAGS="$(echo $LOCAL_NEON_FLAGS | $SED 's/^ *//')"
[AC_MSG_WARN(m4_normalize([NEON runtime AS_IF([test -n "$NEON_FLAGS"], [
cpu-detection is unavailble for AS_IF([test "${host_os%%-*}" = "linux" -o \
${host_os%%-*}. Force with "x$enable_neon_rtcd" = "xno"], [
CFLAGS=-mfpu=neon or CFLAGS=$SAVED_CFLAGS
--disable-neon-rtcd.])) AC_DEFINE(WEBP_HAVE_NEON, [1], [Set to 1 if NEON is supported])
enable_neon_rtcd=no break
NEON_FLAGS=""])], ],[
[NEON_FLAGS=""]) AC_MSG_WARN(m4_normalize([NEON runtime cpu-detection is
CFLAGS=$SAVED_CFLAGS unavailable for ${host_os%%-*}. Force
AS_IF([test -n "$NEON_FLAGS"], [ with CFLAGS=-mfpu=neon or
dnl If NEON is available and rtcd is disabled apply --disable-neon-rtcd.]))
dnl NEON_FLAGS globally. enable_neon_rtcd=no
AS_IF([test "x$enable_neon_rtcd" = "xno"], [ NEON_FLAGS=""
AM_CFLAGS="$AM_CFLAGS $NEON_FLAGS" ])
NEON_FLAGS=""], ],[
[AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1], CFLAGS=$SAVED_CFLAGS
[Set to 1 if runtime detection of NEON AC_DEFINE(WEBP_HAVE_NEON, [1], [Set to 1 if NEON is supported])
is enabled])])])])]) break
])])
CFLAGS=$SAVED_CFLAGS
done
AS_IF([test -n "$NEON_FLAGS"], [
# If NEON is available and rtcd is disabled apply NEON_FLAGS globally.
AS_IF([test "x$enable_neon_rtcd" = "xno"], [
AM_CFLAGS="$AM_CFLAGS $NEON_FLAGS"
NEON_FLAGS=""],
[AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1],
[Set to 1 if runtime detection of NEON is enabled])])])
;; ;;
esac esac
AC_SUBST([NEON_FLAGS])]) AC_SUBST([NEON_FLAGS])])