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