Merged revisions 135597 via svnmerge from
[asterisk/asterisk.git] / acinclude.m4
index 66e1ef7..59566d0 100644 (file)
@@ -7,13 +7,17 @@
 AC_DEFUN([AST_GCC_ATTRIBUTE],
 [
 AC_MSG_CHECKING(for compiler 'attribute $1' support)
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Werror"
 AC_COMPILE_IFELSE(
-       AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
+       AC_LANG_PROGRAM([static void __attribute__(($1)) *test(void *muffin, ...) {}],
                        []),
        AC_MSG_RESULT(yes)
        AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
        AC_MSG_RESULT(no))
-])
+]
+CFLAGS="$saved_CFLAGS"
+)
 
 # Helper function to setup variables for a package.
 # $1 -> the package name. Used in configure.ac and also as a prefix
@@ -92,7 +96,7 @@ AC_DEFUN([AST_CHECK_MANDATORY],
 # AST_C_DEFINE_CHECK([package], [macro name], [header file], [version])
 AC_DEFUN([AST_C_DEFINE_CHECK],
 [
-    if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
+    if test "x${PBX_$1}" != "x1"; then
        AC_MSG_CHECKING([for $2 in $3])
        saved_cppflags="${CPPFLAGS}"
        if test "x${$1_DIR}" != "x"; then
@@ -114,20 +118,25 @@ AC_DEFUN([AST_C_DEFINE_CHECK],
                AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
                AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
            ],
-           [       AC_MSG_RESULT(no) ] 
+           [   AC_MSG_RESULT(no) ] 
        )
        CPPFLAGS="${saved_cppflags}"
     fi
+    AC_SUBST(PBX_$1)
 ])
 
 
 # Check if a given expression will compile using a certain header.
 
-# AST_C_COMPILE_CHECK([package], [expression], [header file], [version])
+# AST_C_COMPILE_CHECK([package], [expression], [header file], [version], [description])
 AC_DEFUN([AST_C_COMPILE_CHECK],
 [
     if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
-       AC_MSG_CHECKING([if "$2" compiles using $3])
+        if test "x$5" != "x"; then
+            AC_MSG_CHECKING([for $5])
+       else
+            AC_MSG_CHECKING([if "$2" compiles using $3])
+       fi
        saved_cppflags="${CPPFLAGS}"
        if test "x${$1_DIR}" != "x"; then
            $1_INCLUDE="-I${$1_DIR}/include"
@@ -187,7 +196,7 @@ if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
          $1_HEADER_FOUND="1"
       else                             # check for the header
          saved_cppflags="${CPPFLAGS}"
-         CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE} $6"
+         CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
         AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
          CPPFLAGS="${saved_cppflags}"
       fi
@@ -210,9 +219,9 @@ fi
 
 # Check for a package using $2-config. Similar to AST_EXT_LIB_CHECK,
 # but use $2-config to determine cflags and libraries to use.
-# $3 and $4 can be used to replace --cflags and --libs in the request 
+# $3 and $4 can be used to replace --cflags and --libs in the request
 
-# AST_EXT_TOOL_CHECK([package], [tool name], [--cflags], [--libs])
+# AST_EXT_TOOL_CHECK([package], [tool name], [--cflags], [--libs], [includes], [expression])
 AC_DEFUN([AST_EXT_TOOL_CHECK],
 [
     if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
@@ -223,8 +232,31 @@ AC_DEFUN([AST_EXT_TOOL_CHECK],
            $1_INCLUDE=$(${CONFIG_$1} $A)
            if test x"$4" = x ; then A=--libs ; else A="$4" ; fi
            $1_LIB=$(${CONFIG_$1} $A)
-           PBX_$1=1
-           AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
+           if test x"$5" != x ; then
+               saved_cppflags="${CPPFLAGS}"
+               if test "x${$1_DIR}" != "x"; then
+                   $1_INCLUDE="-I${$1_DIR}/include"
+               fi
+               CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
+
+               saved_ldflags="${LDFLAGS}"
+               LDFLAGS="${$1_LIB}"
+
+               AC_LINK_IFELSE(
+                   [ AC_LANG_PROGRAM( [ $5 ],
+                                      [ $6; ]
+                                      )],
+                   [   PBX_$1=1
+                       AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
+                   ],
+                   []
+               )
+               CPPFLAGS="${saved_cppflags}"
+               LDFLAGS="${saved_ldflags}"
+           else
+               PBX_$1=1
+               AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
+           fi
        fi
     fi
 ])