]> Savannah Git Hosting - gnulib.git/commitdiff
maint.mk: improve new syntax-check rule
authorJim Meyering <meyering@meta.com>
Mon, 19 Feb 2024 04:23:28 +0000 (20:23 -0800)
committerJim Meyering <meyering@meta.com>
Mon, 19 Feb 2024 05:01:41 +0000 (21:01 -0800)
* top/maint.mk (sc_prefer_angle_bracket_headers): Rename from
sc_verify_absolute_include_headers.  Simplify to run a single
invocation of grep, rather than usually many.  Derive a regular
expression matching the selected headers, and warn about any
offending matches via what is usually a single grep invocation.

ChangeLog
top/maint.mk

index b8d484e8daa1911fe806045f1593bb74357793b8..b941c7449d3f9b24b0e8622c11977aa6253b58b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-02-18  Jim Meyering  <meyering@meta.com>
+
+       maint.mk: improve new syntax-check rule
+       * top/maint.mk (sc_prefer_angle_bracket_headers): Rename from
+       sc_verify_absolute_include_headers.  Simplify to run a single
+       invocation of grep, rather than usually many.  Derive a regular
+       expression matching the selected headers, and warn about any
+       offending matches via what is usually a single grep invocation.
+
 2024-02-18  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Fix function call on incorrect object.
index 5746b911dd4655a00542f0aa6b157dc380617729..227861993159892832b214fef6dc0bb81808ea68 100644 (file)
@@ -539,7 +539,7 @@ sc_require_config_h_first:
 
 # Generated headers that override system headers.
 # Keep sorted.
-gl_absolute_include_headers_ ?= \
+gl_prefer_angle_bracket_headers_ ?= \
   alloca.h             \
   arpa_inet.h          \
   assert.h             \
@@ -608,26 +608,17 @@ gl_absolute_include_headers_ ?= \
   wchar.h              \
   wctype.h
 
+# Remove each .h suffix and change each space to "|".
+angle_bracket_header_re = \
+  $(subst $(_sp),|,$(patsubst %.h,%,$(gl_prefer_angle_bracket_headers_)))
+
 # Suggest using '#include <header.h>' instead of '#include "header.h"' for
 # headers that override system headers.
 # Rationale: The Gnulib documentation, node 'Style of #include statements'.
-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;
+sc_prefer_angle_bracket_headers:
+       @prohibit='^ *# *include "($(angle_bracket_header_re))\.h"'     \
+       halt='Use #include <hdr.h>, not #include "hdr.h" for the above' \
+         $(_sc_search_regexp)
 
 sc_prohibit_HAVE_MBRTOWC:
        @prohibit='\bHAVE_MBRTOWC\b'                                    \