Formatting changes (coding guidelines) while thinking about something else...
[asterisk/asterisk.git] / acinclude.m4
index f9235a7..1395241 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
@@ -75,6 +79,7 @@ AC_DEFUN([AST_CHECK_MANDATORY],
 
 # The next three functions check for the availability of a given package.
 # AST_C_DEFINE_CHECK looks for the presence of a #define in a header file,
+# AST_C_COMPILE_CHECK can be used for testing for various items in header files,
 # AST_EXT_LIB_CHECK looks for a symbol in a given library, or at least
 #      for the presence of a header file.
 # AST_EXT_TOOL_CHECK looks for a symbol in using $1-config to determine CFLAGS and LIBS
@@ -91,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
@@ -100,7 +105,44 @@ AC_DEFUN([AST_C_DEFINE_CHECK],
        CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
 
        AC_COMPILE_IFELSE(
-           [ AC_LANG_PROGRAM( [#include <$3>], [int foo = $2;]) ],
+           [ AC_LANG_PROGRAM( [#include <$3>],
+                              [#if defined($2)
+                               int foo = 0;
+                               #else
+                               int foo = bar;
+                               #endif
+                               0
+                              ])],
+           [   AC_MSG_RESULT(yes)
+               PBX_$1=1
+               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) ] 
+       )
+       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])
+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])
+       saved_cppflags="${CPPFLAGS}"
+       if test "x${$1_DIR}" != "x"; then
+           $1_INCLUDE="-I${$1_DIR}/include"
+       fi
+       CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
+
+       AC_COMPILE_IFELSE(
+           [ AC_LANG_PROGRAM( [#include <$3>],
+                              [ $2; ]
+                              )],
            [   AC_MSG_RESULT(yes)
                PBX_$1=1
                AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
@@ -173,18 +215,44 @@ 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
 
-# AST_EXT_TOOL_CHECK([package], [tool name], [symbol], [version])
+# 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
        PBX_$1=0
        AC_CHECK_TOOL(CONFIG_$1, $2-config, No)
        if test ! "x${CONFIG_$1}" = xNo; then
-           $1_INCLUDE=$(${CONFIG_$1} --cflags $3)
-           $1_LIB=$(${CONFIG_$1} --libs $3)
-           PBX_$1=1
-           AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
+           if test x"$3" = x ; then A=--cflags ; else A="$3" ; fi
+           $1_INCLUDE=$(${CONFIG_$1} $A)
+           if test x"$4" = x ; then A=--libs ; else A="$4" ; fi
+           $1_LIB=$(${CONFIG_$1} $A)
+           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
 ])