]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
configure: improve march=native detection
authorEric Leblond <eric@regit.org>
Thu, 8 Nov 2012 22:39:20 +0000 (23:39 +0100)
committerEric Leblond <eric@regit.org>
Thu, 8 Nov 2012 22:45:14 +0000 (23:45 +0100)
clang is supposed to support march=native but if the CPU is too
recent for clang, this can cause an invalid detection of arch and
result in a incapability of clang to compile any binary.
This patch updates the test to try a compilation with march=native
when clang is the used compiler.

configure.ac

index 3aa62b45cc92a17c81af4e959d91d424d5050b2f..510928385c25284b8f21d04f169727393f0c604f 100644 (file)
@@ -248,22 +248,40 @@ AC_INIT(configure.ac)
     AC_ARG_ENABLE(gccmarch_native,
            AS_HELP_STRING([--enable-gccmarch-native], [Enable gcc march=native gcc 4.2 and later only]),,[enable_gccmarch_native=yes])
     AS_IF([test "x$enable_gccmarch_native" = "xyes"], [
-        case $host in
-           *darwin*|*Darwin*)
-               if test "$gccvernum" -ge "403"; then
-                    dnl gcc 4.3 or later
-                    CFLAGS="$CFLAGS -march=native"
-               else
-                   enable_gccmarch_native=no
-               fi
-               ;;
-           *)
-               if test "$gccvernum" -ge "402"; then
-                    dnl gcc 4.2 or later
-                    CFLAGS="$CFLAGS -march=native"
-               fi
-               ;;
-       esac
+        if test `basename $CC` = "clang"; then
+            OFLAGS="$CFLAGS"
+            CFLAGS="$CFLAGS -march=native"
+            AC_MSG_CHECKING([checking if $CC supports -march=native])
+            AC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[#include <stdlib.h>]])],
+                        [
+                          AC_MSG_RESULT([yes])
+                          CFLAGS="$OFLAGS -march=native"
+                        ],
+                        [
+                          AC_MSG_RESULT([no])
+                          CFLAGS="$OFLAGS"
+                          enable_gccmarch_native=no
+                        ]
+                     )
+        fi
+        if test `basename $CC` = "gcc"; then
+            case $host in
+            *darwin*|*Darwin*)
+            if test "$gccvernum" -ge "403"; then
+                        dnl gcc 4.3 or later
+                        CFLAGS="$CFLAGS -march=native"
+            else
+                enable_gccmarch_native=no
+            fi
+            ;;
+            *)
+            if test "$gccvernum" -ge "402"; then
+                        dnl gcc 4.2 or later
+                        CFLAGS="$CFLAGS -march=native"
+            fi
+            ;;
+            esac
+        fi
     ])
 
 # options