bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: Bruno Haible <bruno@clisp.org>, bug-gnulib@gnu.org
Cc: Jim Meyering <jim@meyering.net>
Subject: Re: syntax-check rule to silence -Winclude-next-absolute-path warning
Date: Sun, 18 Feb 2024 12:12:34 -0800	[thread overview]
Message-ID: <bb22275c-819d-4543-9f4f-9dff65116c81@gmail.com> (raw)
In-Reply-To: <45004650.doPnVEEUbh@nimes>

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

On 2/18/24 4:44 AM, Bruno Haible wrote:
> Does anyone want to contribute a syntax-check rule (in maint.mk) for this?

I attached a patch that seems to work alright. I'm not the greatest with GNU Make so it isn't very pretty. Feel free to modify it as much as you would like.

Here is some sample output from Coreutils. One or two are real so I'll submit a patch there.

[collin@debian coreutils]$ make sc_verify_absolute_include_headers
verify_absolute_include_headers
maint.mk: Use #include <sys/stat.h> instead of  #include "sys/stat.h" in src/od.c
maint.mk: Use #include <error.h> instead of  #include "error.h" in src/od.c
maint.mk: Use #include <getopt.h> instead of  #include "getopt.h" in src/shuf.c
maint.mk: Use #include <getopt.h> instead of  #include "getopt.h" in src/stat.c
maint.mk: Use #include <error.h> instead of  #include "error.h" in src/system.h

[-- Attachment #2: 0001-maint.mk-Add-syntax-check-rule-to-check-for-include-.patch --]
[-- Type: text/x-patch, Size: 3418 bytes --]

From c8315b3514181c1369da067516c1ec7c2a23a203 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Sun, 18 Feb 2024 12:02:33 -0800
Subject: [PATCH] maint.mk: Add syntax-check rule to check for #include syntax.

* top/maint.mk (sc_verify_absolute_include_headers): New rule
to check for #includes that might cause
-Winclude-next-absolute-path warnings.
---
 ChangeLog    |  7 ++++
 top/maint.mk | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f09e819707..a3f316e3cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-02-18  Collin Funk  <collin.funk1@gmail.com>
+
+	maint.mk: Add syntax-check rule to check for #include syntax.
+	* top/maint.mk (sc_verify_absolute_include_headers): New rule
+	to check for #includes that might cause
+	-Winclude-next-absolute-path warnings.
+
 2024-02-18  Bruno Haible  <bruno@clisp.org>
 
 	doc: Mention requirement regarding #include syntax.
diff --git a/top/maint.mk b/top/maint.mk
index 1b4a2de4f9..84751337b0 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -914,6 +914,98 @@ sc_prohibit_always-defined_macros:
 		 exit 1; }						\
 	    || :;							\
 	fi
+
+# Generated headers that override system headers.
+# Keep sorted.
+gl_absolute_include_headers_ ?= \
+  alloca.h		\
+  arpa_inet.h		\
+  assert.h		\
+  ctype.h		\
+  dirent.h		\
+  errno.h		\
+  error.h		\
+  fcntl.h		\
+  fenv.h		\
+  float.h		\
+  fnmatch.h		\
+  getopt.h		\
+  glob.h		\
+  iconv.h		\
+  inttypes.h		\
+  langinfo.h		\
+  limits.h		\
+  locale.h		\
+  malloc.h		\
+  math.h		\
+  monetary.h		\
+  netdb.h		\
+  net/if.h		\
+  netinet/in.h		\
+  omp.h			\
+  poll.h		\
+  pthread.h		\
+  pty.h			\
+  sched.h		\
+  search.h		\
+  selinux/selinux.h	\
+  signal.h		\
+  spawn.h		\
+  stdalign.h		\
+  stdarg.h		\
+  stddef.h		\
+  stdint.h		\
+  stdio.h		\
+  stdlib.h		\
+  string.h		\
+  strings.h		\
+  sysexits.h		\
+  sys/file.h		\
+  sys/ioctl.h		\
+  sys/msg.h		\
+  sys/random.h		\
+  sys/resource.h	\
+  sys/select.h		\
+  sys/sem.h		\
+  sys/shm.h		\
+  sys/socket.h		\
+  sys/stat.h		\
+  sys/time.h		\
+  sys/times.h		\
+  sys/types.h		\
+  sys/uio.h		\
+  sys/utsname.h		\
+  sys/wait.h		\
+  termios.h		\
+  threads.h		\
+  time.h		\
+  uchar.h		\
+  unistd.h		\
+  utime.h		\
+  utmp.h		\
+  wchar.h		\
+  wctype.h
+
+# Suggest using '#include <header.h>' instead of '#include "header.h"' for
+# headers that substitute system headers.
+sc_verify_absolute_include_headers:
+	@if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then	\
+	  source_files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.\(c\|h\)$$');	\
+	  for source_file in $$source_files; do				\
+	    local_includes=$$($(GREP) -h '^ *# *include "[^"]\+"' 	\
+                              $$source_file | $(SED) 			\
+                              -e 's/^[^"]\+"//g' -e 's/"$///g');	\
+	    for local_include in $$local_includes; do			\
+	      for header in $(gl_absolute_include_headers_); do         \
+	        if test "$$header" = "$$local_include";	then		\
+	          echo "$(ME): Use #include <$$header> instead of "     \
+	               "#include \"$$header\" in $$source_file" 2>&1;	\
+	        fi;							\
+	      done;							\
+	    done;							\
+          done;								\
+	fi;
+
 # ==================================================================
 
 # Prohibit checked in backup files.
-- 
2.39.2


  reply	other threads:[~2024-02-18 20:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17  8:36 [PATCH] math: Silence -Winclude-next-absolute-path warning Collin Funk
2024-02-17 10:51 ` Bruno Haible
2024-02-17 12:26   ` Collin Funk
2024-02-17 13:17     ` Bruno Haible
2024-02-18 12:19     ` Bruno Haible
2024-02-18 12:44       ` syntax-check rule to silence " Bruno Haible
2024-02-18 20:12         ` Collin Funk [this message]
2024-02-18 20:33           ` Bruno Haible
2024-02-19  5:02             ` Jim Meyering
2024-02-19 18:11               ` Collin Funk
2024-02-19 18:32                 ` Jim Meyering
2024-02-19  8:45             ` Simon Josefsson via Gnulib discussion list
2024-02-19 20:39               ` Jim Meyering
2024-02-20 15:17               ` Bruno Haible
2024-02-20 20:23         ` Collin Funk
2024-02-20 20:49           ` Bruno Haible
2024-02-19  6:31       ` [PATCH] math: Silence " Paul Eggert
2024-02-19 11:03         ` Bruno Haible
2024-02-19 20:41           ` Paul Eggert
2024-02-19 21:24             ` Bruno Haible
2024-02-19 21:45               ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bb22275c-819d-4543-9f4f-9dff65116c81@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=jim@meyering.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).