Avoid some more autoconf warnings.
[gnulib.git] / m4 / acl.m4
1 # acl.m4 - check for access control list (ACL) primitives
2 # serial 2
3
4 # Copyright (C) 2002, 2004-2008 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
8
9 # Written by Paul Eggert and Jim Meyering.
10
11 AC_DEFUN([gl_FUNC_ACL],
12 [
13   AC_LIBOBJ([acl])
14   AC_LIBOBJ([file-has-acl])
15
16   AC_ARG_ENABLE([acl],
17     AS_HELP_STRING([--disable-acl], [do not support ACLs]),
18     , [enable_acl=auto])
19
20   LIB_ACL=
21   use_acl=0
22   if test "x$enable_acl" != "xno"; then
23     dnl Prerequisites of lib/acl.c.
24     AC_CHECK_HEADERS(sys/acl.h)
25     if test $ac_cv_header_sys_acl_h = yes; then
26       ac_save_LIBS=$LIBS
27       AC_CHECK_FUNCS([acl])
28       use_acl=1
29       AC_SEARCH_LIBS([acl_trivial], [sec],
30         [test "$ac_cv_search_acl_trivial" = "none required" ||
31          LIB_ACL=$ac_cv_search_acl_trivial
32          AC_CHECK_FUNCS([acl_trivial])],
33         [AC_CHECK_FUNCS([acl_trivial])
34          if test $ac_cv_func_acl_trivial != yes; then
35            AC_SEARCH_LIBS([acl_get_file], [acl],
36              [test "$ac_cv_search_acl_get_file" = "none required" ||
37               LIB_ACL=$ac_cv_search_acl_get_file
38               AC_CHECK_FUNCS(
39                 [acl_get_file acl_get_fd acl_set_file acl_set_fd \
40                  acl_free acl_from_mode acl_from_text \
41                  acl_delete_def_file acl_extended_file])
42               if test $ac_cv_func_acl_get_file = yes; then
43                 # If the acl_get_file bug is detected, disable all ACL support.
44                 gl_ACL_GET_FILE( , [use_acl=0])
45               fi
46               if test $use_acl = 1; then
47                 AC_CHECK_HEADERS([acl/libacl.h])
48                 if test $ac_cv_func_acl_get_file = yes &&
49                    test $ac_cv_func_acl_free = yes; then
50                   AC_REPLACE_FUNCS([acl_entries])
51                 fi
52               else
53                 LIB_ACL=
54               fi])
55          fi])
56       LIBS=$ac_save_LIBS
57     fi
58     if test "x$enable_acl$use_acl" = "xyes0"; then
59       AC_MSG_ERROR([ACLs enabled but support not detected])
60     fi
61   fi
62   AC_SUBST([LIB_ACL])
63   AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
64     [Define to nonzero if you want access control list support.])
65
66   # This is for backwards compatibility; remove this by the end of 2007.
67   LIB_ACL_TRIVIAL=
68   AC_SUBST([LIB_ACL_TRIVIAL])
69 ])
70
71 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
72 # -------------------------------------
73 # If `acl_get_file' works (does not have a particular bug),
74 # run IF-WORKS, otherwise, IF-NOT.
75 # This tests for a Darwin 8.7.0 bug, whereby acl_get_file returns NULL,
76 # but sets errno = ENOENT for an existing file or directory.
77 AC_DEFUN([gl_ACL_GET_FILE],
78 [
79   AC_CACHE_CHECK([for working acl_get_file], gl_cv_func_working_acl_get_file,
80     [AC_RUN_IFELSE(
81        [AC_LANG_PROGRAM(
82           [[#include <sys/types.h>
83            #include <sys/acl.h>
84            #include <errno.h>
85           ]],
86           [[return !! (!acl_get_file (".", ACL_TYPE_ACCESS)
87                        && errno == ENOENT);]])],
88        [gl_cv_func_working_acl_get_file=yes],
89        [gl_cv_func_working_acl_get_file=no],
90        [gl_cv_func_working_acl_get_file=cross-compiling])])
91
92   AS_IF([test $gl_cv_func_working_acl_get_file = yes], [$1], [$2])
93 ])