Hi Bruno,
Bruno Haible <[email protected]> writes:
> #if @HAVE_SYS_CDEFS_H@
> # include <sys/cdefs.h>
> #endif
>
> It would be good to use the same idiom in fts_.h. The idea is that
> things are more robust if the value of some HAVE_* macro is taken
> directly from config.status, rather than from config.h (where it
> comes from config.status as well, but indirectly). If the wrong config.h
> is included, due to wrong -I option in the package's Makefile.am, it
> helps to rely on config.h as little as possible.
Originally I just wanted to use gl_CHECK_HEADER_SYS_CDEFS_H from
sys_cdefs_h.m4 by adding an AC_DEFINE. But I felt that doing this:
if test "$gl_cv_header_sys_cdefs_h" = yes; then
HAVE_SYS_CDEFS_H=1
else
HAVE_SYS_CDEFS_H=0
fi
AC_DEFINE_UNQUOTED([HAVE_SYS_CDEFS_H], [$HAVE_SYS_CDEFS_H], ...)
But on a system without sys/cdefs.h that would produce this line in
config.h:
#define HAVE_SYS_CDEFS_H 0
Where an AC_CHECK_HEADER would do:
/* #undef HAVE_SYS_CDEFS_H */
Maybe I was overthinking it, but that seemed strange. Therefore, I just
used AC_CHECK_HEADERS_ONCE.
I prefer just changing this to an *.in.h file and replacing the variable
like you suggest. Could you double check the attached patch before I
push the change?
Collin
>From 21d8dfb0ef2becf18e41035739e1288eac153685 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Sat, 10 May 2025 17:39:26 -0700
Subject: [PATCH] fts: Improve previous commit.
Suggested by Bruno Haible in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00134.html>.
* lib/fts_.h: Remove file.
* lib/fts_.in.h: New file.
* m4/fts.m4 (gl_FUNC_FTS_CORE): Use gl_CHECK_HEADER_SYS_CDEFS_H instead
of AC_CHECK_HEADERS_ONCE.
* modules/fts (Files): Remove lib/fts_.h. Add lib/fts_.in.h and
m4/sys_cdefs_h.m4.
(Depends-on): Add gen-header.
(Makefile.am): Add fts_.h to BUILT_SOURCES. Generate fts_.h using
fts_.in.h while replacing @HAVE_SYS_CDEFS_H@. Add fts_.h and fts_.h-t to
MOSTLYCLEANFILES.
---
ChangeLog | 14 ++++++++++++++
lib/{fts_.h => fts_.in.h} | 2 +-
m4/fts.m4 | 4 ++--
modules/fts | 13 ++++++++++++-
4 files changed, 29 insertions(+), 4 deletions(-)
rename lib/{fts_.h => fts_.in.h} (99%)
diff --git a/ChangeLog b/ChangeLog
index 6c248f533a..c1eeff1fae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2025-05-10 Collin Funk <[email protected]>
+ fts: Improve previous commit.
+ Suggested by Bruno Haible in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00134.html>.
+ * lib/fts_.h: Remove file.
+ * lib/fts_.in.h: New file.
+ * m4/fts.m4 (gl_FUNC_FTS_CORE): Use gl_CHECK_HEADER_SYS_CDEFS_H instead
+ of AC_CHECK_HEADERS_ONCE.
+ * modules/fts (Files): Remove lib/fts_.h. Add lib/fts_.in.h and
+ m4/sys_cdefs_h.m4.
+ (Depends-on): Add gen-header.
+ (Makefile.am): Add fts_.h to BUILT_SOURCES. Generate fts_.h using
+ fts_.in.h while replacing @HAVE_SYS_CDEFS_H@. Add fts_.h and fts_.h-t to
+ MOSTLYCLEANFILES.
+
fts: Fix redefinition of __THROW.
* lib/fts_.h: Include <sys/cdefs.h> if the system has it.
(__THROW, __BEGIN_DECLS, __END_DECLS): Define properly if not previously
diff --git a/lib/fts_.h b/lib/fts_.in.h
similarity index 99%
rename from lib/fts_.h
rename to lib/fts_.in.h
index 052858da7b..32533b9f6a 100644
--- a/lib/fts_.h
+++ b/lib/fts_.in.h
@@ -62,7 +62,7 @@
# define __FLEXIBLE_ARRAY_MEMBER
# endif
# else
-# if HAVE_SYS_CDEFS_H
+# if @HAVE_SYS_CDEFS_H@
# include <sys/cdefs.h>
# endif
# define __FLEXIBLE_ARRAY_MEMBER FLEXIBLE_ARRAY_MEMBER
diff --git a/m4/fts.m4 b/m4/fts.m4
index 1d3a32f52e..c5bdc6eac9 100644
--- a/m4/fts.m4
+++ b/m4/fts.m4
@@ -1,5 +1,5 @@
# fts.m4
-# serial 25
+# serial 26
dnl Copyright (C) 2005-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,
@@ -15,7 +15,7 @@ AC_DEFUN([gl_FUNC_FTS_CORE]
[
dnl Prerequisites of lib/fts.c.
gl_FUNC_OPENAT
- AC_CHECK_HEADERS_ONCE([sys/cdefs.h])
+ gl_CHECK_HEADER_SYS_CDEFS_H
AC_CHECK_FUNCS_ONCE([fstatfs])
AC_CHECK_HEADERS_ONCE([sys/param.h sys/vfs.h])dnl
diff --git a/modules/fts b/modules/fts
index a50bd958b9..ecbd4f57ad 100644
--- a/modules/fts
+++ b/modules/fts
@@ -2,12 +2,14 @@ Description:
Traverse a file hierarchy.
Files:
-lib/fts_.h
+lib/fts_.in.h
lib/fts.c
lib/fts-cycle.c
m4/fts.m4
+m4/sys_cdefs_h.m4
Depends-on:
+gen-header
alignasof
attribute
c99
@@ -45,10 +47,19 @@ dnl NetBSD versions have bugs and/or unnecessary limitations.
gl_CONDITIONAL([GL_COND_OBJ_FTS], [true])
Makefile.am:
+BUILT_SOURCES += fts_.h
if GL_COND_OBJ_FTS
lib_SOURCES += fts.c
endif
+fts_.h: fts_.in.h
+@NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%'
+ $(gl_V_at)$(SED_HEADER_STDOUT) \
+ -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \
+ $(srcdir)/fts_.in.h > $@-t
+ $(AM_V_at)mv $@-t $@
+MOSTLYCLEANFILES += fts_.h fts_.h-t
+
Include:
"fts_.h"
--
2.49.0