Code

configure: updated m4/*.m4
[ncmpc.git] / m4 / socklen_t.m4
2 dnl Like AC_TRY_EVAL but also errors out if the compiler generates
3 dnl _any_ output. Some compilers might issue warnings which we want
4 dnl to catch.
5 AC_DEFUN([AC_TRY_EVAL2],
6 [{ (eval echo configure:__oline__: \"[$]$1\") 1>&AC_FD_CC; dnl
7 (eval [$]$1) 2>&AC_FD_CC; _out=`eval [$]$1 2>&1` && test "x$_out" = x; }])
10 dnl Like AC_TRY_COMPILE but calls AC_TRY_EVAL2 instead of AC_TRY_EVAL
11 AC_DEFUN([AC_TRY_COMPILE2],
12 [cat > conftest.$ac_ext <<EOF
13 [#]line __oline__ "configure"
14 #include "confdefs.h"
15 [$1]
16 int main(void) {
17 [$2]
18 ; return 0; }
19 EOF
20 if AC_TRY_EVAL2(ac_compile); then
21   ifelse([$3], , :, [rm -rf conftest*
22   $3])
23 else
24   echo "configure: failed program was:" >&AC_FD_CC
25   cat conftest.$ac_ext >&AC_FD_CC
26 ifelse([$4], , , [  rm -rf conftest*
27   $4
28 ])dnl
29 fi
30 rm -f conftest*])
32 dnl Determine what socket length (socklen_t) data type is 
33 AC_DEFUN([AC_SOCKLEN_T],
34 [
35 AC_MSG_CHECKING([for type of socket length (socklen_t)])
36 AC_TRY_COMPILE2([
37 #include <stddef.h>
38 #include <sys/types.h>
39 #include <sys/socket.h>],[
40 (void)getsockopt (1, 1, 1, NULL, (socklen_t *)NULL)],[
41   AC_MSG_RESULT(socklen_t *)
42   SOCKLEN_T=socklen_t],[
43   AC_TRY_COMPILE2([
44 #include <stddef.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>],[
47 (void)getsockopt (1, 1, 1, NULL, (size_t *)NULL)],[
48     AC_MSG_RESULT(size_t *)
49     SOCKLEN_T=size_t],[
50     AC_TRY_COMPILE2([
51 #include <stddef.h>
52 #include <sys/types.h>
53 #include <sys/socket.h>],[
54 (void)getsockopt (1, 1, 1, NULL, (int *)NULL)],[
55       AC_MSG_RESULT(int *)
56       SOCKLEN_T=int],[
57       AC_MSG_WARN(could not determine)
58       SOCKLEN_T="unsigned int"])])])
60 if test "$SOCKLEN_T" = socklen_t; then
61   AC_DEFINE(HAVE_SOCKLEN_T, 1, socklen_t defined in sys/socket.h)
62 fi
64 AC_DEFINE_UNQUOTED(SOCKLEN_T, $SOCKLEN_T, [Determine what socket length (socklen_t) data type is])
66 ])