Use src/ not lib/ as root of source in example Makefile.am code.
[gnulib.git] / m4 / getgroups.m4
1 # serial 15
2
3 dnl From Jim Meyering.
4 dnl A wrapper around AC_FUNC_GETGROUPS.
5
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2010 Free Software Foundation, Inc.
7 #
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
11
12 AC_DEFUN([gl_FUNC_GETGROUPS],
13 [
14   AC_REQUIRE([AC_FUNC_GETGROUPS])
15   AC_REQUIRE([AC_TYPE_GETGROUPS])
16   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
17   if test "$ac_cv_func_getgroups" != yes; then
18     AC_LIBOBJ([getgroups])
19     HAVE_GETGROUPS=0
20   elif test "$ac_cv_func_getgroups_works.$ac_cv_type_getgroups" != yes.gid_t
21   then
22     AC_LIBOBJ([getgroups])
23     REPLACE_GETGROUPS=1
24     AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
25       getgroups(0,NULL) does not return the number of groups.])
26   else
27     dnl Detect FreeBSD bug; POSIX requires getgroups(-1,ptr) to fail.
28     AC_CACHE_CHECK([whether getgroups handles negative values],
29       [gl_cv_func_getgroups_works],
30       [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
31         [[int size = getgroups (0, 0);
32           gid_t *list = malloc (size * sizeof *list);
33           return getgroups (-1, list) != -1;]])],
34         [gl_cv_func_getgroups_works=yes],
35         [gl_cv_func_getgroups_works=no],
36         [gl_cv_func_getgroups_works="guessing no"])])
37     if test "$gl_cv_func_getgroups_works" != yes; then
38       AC_LIBOBJ([getgroups])
39       REPLACE_GETGROUPS=1
40     fi
41   fi
42   test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"
43 ])