From: Lucas De Marchi Date: Tue, 10 Feb 2015 02:31:08 +0000 (-0200) Subject: build: add better check for builtin function X-Git-Tag: v20~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba52c77e04b0f2d5a9ebee147f4445ac8b1f2b2a;p=platform%2Fupstream%2Fkmod.git build: add better check for builtin function It's not used right now in kmod, but may be used in future for other builtins, so let the macro generic. --- diff --git a/m4/attributes.m4 b/m4/attributes.m4 index e822197..af17a6b 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -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], [