]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
build: add better check for builtin function
authorLucas De Marchi <lucas.demarchi@intel.com>
Tue, 10 Feb 2015 02:31:08 +0000 (00:31 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 10 Feb 2015 02:31:25 +0000 (00:31 -0200)
It's not used right now in kmod, but may be used in future for other
builtins, so let the macro generic.

m4/attributes.m4

index e8221970505d02ee2afb193516eb049e920d9824..af17a6b89d2cca3922aec4a4afa17535e876723b 100644 (file)
@@ -254,27 +254,21 @@ AC_DEFUN([CC_FLAG_VISIBILITY], [
     [$2])
 ])
 
-AC_DEFUN([CC_FUNC_EXPECT], [
-  AC_REQUIRE([CC_CHECK_WERROR])
-  AC_CACHE_CHECK([if compiler has __builtin_expect function],
-    [cc_cv_func_expect],
-    [ac_save_CFLAGS="$CFLAGS"
-     CFLAGS="$CFLAGS $cc_cv_werror"
-     AC_COMPILE_IFELSE([AC_LANG_SOURCE(
-       [int some_function() {
-        int a = 3;
-        return (int)__builtin_expect(a, 3);
-       }])],
-       [cc_cv_func_expect=yes],
-       [cc_cv_func_expect=no])
-     CFLAGS="$ac_save_CFLAGS"
-    ])
-
-  AS_IF([test "x$cc_cv_func_expect" = "xyes"],
-    [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
-     [Define this if the compiler supports __builtin_expect() function])
-     $1],
-    [$2])
+AC_DEFUN([CC_CHECK_FUNC_BUILTIN], [
+  m4_pushdef([UPNAME], m4_translit([$1], [-a-z], [_A-Z]))
+  AC_CACHE_CHECK([if compiler has $1 function],
+    [cc_cv_have_$1],
+    [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
+       m4_case([$1],
+         [__builtin_expect], [$1(0, 0)]
+       )])],
+       [cc_cv_have_$1=yes],
+       [cc_cv_have_$1=no])])
+
+  AS_IF([test "x$cc_cv_have_$1" = "xyes"],
+    [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 1, [Define this if the compiler supports $1() function])
+     $2], [$3])
+  m4_popdef([UPNAME])
 ])
 
 AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [