09ac70fcd9f00469faeb6c3a2c9f566ae499768a
[citadel.git] / citadel / m4 / ucread.m4
1 # Check if "struct ucred" is available.  If not, try harder with
2 # _GNU_SOURCE.
3 #
4 # heavily inspired by: http://git.musicpd.org/cgit/master/mpd.git/tree/m4/ucred.m4
5 # Author: Max Kellermann <max@duempel.org>
6
7 AC_DEFUN([STRUCT_UCRED],[
8         AC_MSG_CHECKING([for struct ucred])
9         AC_CACHE_VAL(mpd_cv_have_struct_ucred, [
10                 AC_TRY_COMPILE([#include <sys/socket.h>],
11                         [struct ucred cred;],
12                         mpd_cv_have_struct_ucred=yes,
13                         mpd_cv_have_struct_ucred=no)
14                 if test x$mpd_cv_have_struct_ucred = xno; then
15                         # glibc 2.8 forces _GNU_SOURCE on us
16                         AC_TRY_COMPILE(
17                                 [#define _GNU_SOURCE
18                                  #include <sys/socket.h>],
19                                 [struct ucred cred;],
20                                 mpd_cv_have_struct_ucred=yes,
21                                 mpd_cv_have_struct_ucred=no)
22                         if test x$mpd_cv_have_struct_ucred = xyes; then
23                                 # :(
24                                 MPD_CFLAGS="$MPD_CFLAGS -D_GNU_SOURCE"
25                         fi
26                 fi
27                 ])
28
29         AC_MSG_RESULT($mpd_cv_have_struct_ucred)
30         if test x$mpd_cv_have_struct_ucred = xyes; then
31                 AC_DEFINE(HAVE_STRUCT_UCRED, 1, [Define if struct ucred is present from sys/socket.h])
32         fi
33 ])