Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / m4 / acl.m4
blobdf8290e5debe7669ab06ab094e6759e7ddbca702
1 # acl.m4 - check for access control list (ACL) primitives
2 # serial 16
4 # Copyright (C) 2002, 2004-2014 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.
9 # Written by Paul Eggert and Jim Meyering.
11 AC_DEFUN([gl_FUNC_ACL],
13   AC_ARG_ENABLE([acl],
14     AS_HELP_STRING([--disable-acl], [do not support ACLs]),
15     , [enable_acl=auto])
17   LIB_ACL=
18   use_acl=0
19   if test "x$enable_acl" != "xno"; then
20     dnl On all platforms, the ACL related API is declared in <sys/acl.h>.
21     AC_CHECK_HEADERS([sys/acl.h])
22     if test $ac_cv_header_sys_acl_h = yes; then
23       ac_save_LIBS=$LIBS
25       dnl Test for POSIX-draft-like API (Linux, FreeBSD, Mac OS X, IRIX, Tru64).
26       dnl -lacl is needed on Linux, -lpacl is needed on OSF/1.
27       if test $use_acl = 0; then
28         AC_SEARCH_LIBS([acl_get_file], [acl pacl],
29           [if test "$ac_cv_search_acl_get_file" != "none required"; then
30              LIB_ACL=$ac_cv_search_acl_get_file
31            fi
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               acl_delete_fd_np acl_delete_file_np \
37               acl_copy_ext_native acl_create_entry_np \
38               acl_to_short_text acl_free_text])
39            # If the acl_get_file bug is detected, don't enable the ACL support.
40            gl_ACL_GET_FILE([use_acl=1], [])
41            if test $use_acl = 1; then
42              dnl On Linux, additional API is declared in <acl/libacl.h>.
43              AC_CHECK_HEADERS([acl/libacl.h])
44              AC_REPLACE_FUNCS([acl_entries])
45              AC_CACHE_CHECK([for ACL_FIRST_ENTRY],
46                [gl_cv_acl_ACL_FIRST_ENTRY],
47                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
48 [[#include <sys/types.h>
49 #include <sys/acl.h>
50 int type = ACL_FIRST_ENTRY;]])],
51                   [gl_cv_acl_ACL_FIRST_ENTRY=yes],
52                   [gl_cv_acl_ACL_FIRST_ENTRY=no])])
53              if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then
54                AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1],
55                  [Define to 1 if the constant ACL_FIRST_ENTRY exists.])
56              fi
57              dnl On Mac OS X, other types of ACLs are supported.
58              AC_CACHE_CHECK([for ACL_TYPE_EXTENDED],
59                [gl_cv_acl_ACL_TYPE_EXTENDED],
60                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
61 [[#include <sys/types.h>
62 #include <sys/acl.h>
63 int type = ACL_TYPE_EXTENDED;]])],
64                   [gl_cv_acl_ACL_TYPE_EXTENDED=yes],
65                   [gl_cv_acl_ACL_TYPE_EXTENDED=no])])
66              if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then
67                AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1],
68                  [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.])
69              fi
70            else
71              LIB_ACL=
72            fi
73           ])
74       fi
76       dnl Test for Solaris API (Solaris, Cygwin).
77       if test $use_acl = 0; then
78         AC_CHECK_FUNCS([facl])
79         if test $ac_cv_func_facl = yes; then
80           AC_SEARCH_LIBS([acl_trivial], [sec],
81             [if test "$ac_cv_search_acl_trivial" != "none required"; then
82                LIB_ACL=$ac_cv_search_acl_trivial
83              fi
84             ])
85           AC_CHECK_FUNCS([acl_trivial])
86           use_acl=1
87         fi
88       fi
90       dnl Test for HP-UX API.
91       if test $use_acl = 0; then
92         AC_CHECK_FUNCS([getacl])
93         if test $ac_cv_func_getacl = yes; then
94           use_acl=1
95         fi
96         dnl Test for HP-UX 11.11 API.
97         AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>])
98       fi
100       dnl Test for AIX API (AIX 5.3 or newer).
101       if test $use_acl = 0; then
102         AC_CHECK_FUNCS([aclx_get])
103         if test $ac_cv_func_aclx_get = yes; then
104           use_acl=1
105         fi
106       fi
108       dnl Test for older AIX API.
109       if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then
110         AC_CHECK_FUNCS([statacl])
111         if test $ac_cv_func_statacl = yes; then
112           use_acl=1
113         fi
114       fi
116       dnl Test for NonStop Kernel API.
117       if test $use_acl = 0; then
118         AC_CHECK_FUNCS([aclsort])
119         if test $ac_cv_func_aclsort = yes; then
120           use_acl=1
121         fi
122       fi
124       LIBS=$ac_save_LIBS
125     fi
126     if test "x$enable_acl$use_acl" = "xyes0"; then
127       AC_MSG_ERROR([ACLs enabled but support not detected])
128     elif test "x$enable_acl$use_acl" = "xauto0"; then
129       AC_MSG_WARN([libacl development library was not found or not usable.])
130       AC_MSG_WARN([AC_PACKAGE_NAME will be built without ACL support.])
131     fi
132   fi
133   AC_SUBST([LIB_ACL])
134   AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
135     [Define to nonzero if you want access control list support.])
136   USE_ACL=$use_acl
137   AC_SUBST([USE_ACL])
140 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
141 # -------------------------------------
142 # If 'acl_get_file' works (does not have a particular bug),
143 # run IF-WORKS, otherwise, IF-NOT.
144 # When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file
145 # returns NULL, but sets errno = ENOENT for an existing file or directory.
146 # When cross-compiling, assume that this old bug no longer applies.
147 AC_DEFUN([gl_ACL_GET_FILE],
149   AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file],
150     [gl_cv_func_working_acl_get_file=no
151      AC_LINK_IFELSE(
152        [AC_LANG_PROGRAM(
153           [[#include <sys/types.h>
154            #include <sys/acl.h>
155            #include <errno.h>
156           ]],
157           [[if (!acl_get_file (".", ACL_TYPE_ACCESS) && errno == ENOENT)
158               return 1;
159             return 0;
160           ]])],
161        [if test $cross_compiling = yes; then
162           gl_cv_func_working_acl_get_file="guessing yes"
163         elif ./conftest$ac_exeext; then
164           gl_cv_func_working_acl_get_file=yes
165         fi])])
166   AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2])