It took me 10 minutes to understand how acl_entries.c gets compiled,
even though no module adds it to lib_SOURCES. It's done through a
very ancient idiom AC_REPLACE_FUNCS, that invokes AC_LIBOBJ (also
a very ancient idiom). This patch removes the last use of
AC_REPLACE_FUNCS, thus making the code more consistent.


2025-11-05  Bruno Haible  <[email protected]>

        acl-permissions: Don't use AC_REPLACE_FUNCS.
        * m4/acl.m4 (gl_FUNC_ACL): Set variable NEED_ACL_ENTRIES. Don't use
        AC_REPLACE_FUNCS.
        * modules/acl-permissions (configure.ac): Define
        GL_COND_OBJ_ACL_ENTRIES.
        (Makefile.am): Conditionally add acl_entries.c to lib_SOURCES.
        * m4/README: Modernize.

diff --git a/m4/README b/m4/README
index 2fdb556ab8..9c9b8bba82 100644
--- a/m4/README
+++ b/m4/README
@@ -22,7 +22,12 @@ that makes it easy.
 
   AC_DEFUN([gl_FUNC_FOO],
   [
-    AC_REPLACE_FUNCS(foo)
+    AC_CHECK_FUNCS([foo])
+    if test $ac_cv_func_foo = yes; then
+      HAVE_FOO=1
+    else
+      HAVE_FOO=0
+    fi
     if test $ac_cv_func_foo = no; then
       gl_PREREQ_FOO
     fi
diff --git a/m4/acl.m4 b/m4/acl.m4
index 0ab7d34e2d..e68ed377ba 100644
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -1,5 +1,5 @@
 # acl.m4
-# serial 39
+# serial 40
 dnl Copyright (C) 2002, 2004-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -28,6 +28,7 @@ AC_DEFUN_ONCE([gl_FUNC_ACL]
   AC_CHECK_FUNCS_ONCE([fchmod])
   LIB_ACL=
   use_acl=0
+  NEED_ACL_ENTRIES=0
   if test "$enable_acl" != no; then
     dnl On all platforms, the ACL related API is declared in <sys/acl.h>.
     AC_CHECK_HEADERS([sys/acl.h])
@@ -55,7 +56,10 @@ AC_DEFUN_ONCE([gl_FUNC_ACL]
            if test $use_acl = 1; then
              dnl On GNU/Linux, an additional API is declared in <acl/libacl.h>.
              AC_CHECK_HEADERS([acl/libacl.h])
-             AC_REPLACE_FUNCS([acl_entries])
+             AC_CHECK_FUNC([acl_entries],
+               [AC_DEFINE([HAVE_ACL_ENTRIES], [1],
+                  [Define to 1 if libc or libacl defines the function 
acl_entries.])],
+               [NEED_ACL_ENTRIES=1])
              AC_CACHE_CHECK([for ACL_FIRST_ENTRY],
                [gl_cv_acl_ACL_FIRST_ENTRY],
                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
diff --git a/modules/acl-permissions b/modules/acl-permissions
index d86c50e91a..4acbd966d1 100644
--- a/modules/acl-permissions
+++ b/modules/acl-permissions
@@ -23,10 +23,14 @@ stdint-h
 
 configure.ac:
 gl_FUNC_ACL
+gl_CONDITIONAL([GL_COND_OBJ_ACL_ENTRIES], [test $NEED_ACL_ENTRIES = 1])
 
 Makefile.am:
 lib_SOURCES += acl-errno-valid.c acl-internal.c \
   get-permissions.c set-permissions.c
+if GL_COND_OBJ_ACL_ENTRIES
+lib_SOURCES += acl_entries.c
+endif
 
 Include:
 "acl.h"




Reply via email to