Netdev List
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, donald.hunter@gmail.com, horms@kernel.org,
	sdf@fomichev.me, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 2/2] tools/ynl: add check-deps target to verify Makefile.deps completeness
Date: Fri,  8 May 2026 13:41:14 -0700	[thread overview]
Message-ID: <20260508204114.205896-3-sdf@fomichev.me> (raw)
In-Reply-To: <20260508204114.205896-1-sdf@fomichev.me>

Add two make rules that detect missing entries in Makefile.deps:

check-existing-deps-<family>: for families that already have CFLAGS,
  parse each force-included header for #include directives and verify
  that every included uapi header is either already listed in CFLAGS
  or findable by the compiler without -idirafter.

check-new-deps-<family>: for families without CFLAGS, check whether
  their default uapi header (linux/<family>.h) exists in the kernel
  tree but is not findable by the compiler -- meaning it needs a new
  CFLAGS entry.

(this is slop but I added extensive comments on how it works)

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
 tools/net/ynl/Makefile.deps      | 35 ++++++++++++++++++++++++++++++++
 tools/net/ynl/generated/Makefile |  6 +++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps
index cc53b2f21c44..f2c24097a2c8 100644
--- a/tools/net/ynl/Makefile.deps
+++ b/tools/net/ynl/Makefile.deps
@@ -52,3 +52,38 @@ CFLAGS_tc:= $(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \
 	$(call get_hdr_inc,_TC_TUNNEL_KEY_H,tc_act/tc_tunnel_key.h)
 CFLAGS_tcp_metrics:=$(call get_hdr_inc,_LINUX_TCP_METRICS_H,tcp_metrics.h)
 CFLAGS_wireguard:=$(call get_hdr_inc2,_LINUX_WIREGUARD_H,_WG_UAPI_WIREGUARD_H,wireguard.h)
+
+# For families that already have CFLAGS, verify that every #include in
+# their force-included headers is accounted for.
+#
+# How it works:
+#   1. Extract -include paths from CFLAGS_<family>      (grep + sed)
+#   2. Parse each header for #include <...> directives  (sed)
+#   3. Skip if the included file is not a uapi header   (test against UAPI_PATH)
+#   4. Skip if it is already listed in CFLAGS_<family>  (grep)
+#   5. Skip if the compiler can find it without help    (try $(CC))
+#   6. Otherwise error -- the header needs to be added
+check-existing-deps-%:
+	@for inc in $$(sed -n 's/.*#include <\([^>]*\)>.*/\1/p' \
+		$$(echo "$(CFLAGS_$*)" | grep -o '\-include [^ ]*' | sed 's/-include //')); do \
+	  test -f $(UAPI_PATH)/$$inc || continue; \
+	  echo "$(CFLAGS_$*)" | grep -qF "$$inc" && continue; \
+	  echo "#include <$$inc>" | $(CC) -x c -fsyntax-only - 2>/dev/null && continue; \
+	  echo "ERROR: $* missing $$inc"; exit 1; \
+	done; true
+
+# For families without CFLAGS, check whether their default uapi header
+# (linux/<family>.h) exists in the kernel tree but is not findable by
+# the compiler -- meaning it needs a new CFLAGS entry.
+#
+# How it works (short-circuit chain, all four must fail to error):
+#   1. Skip if CFLAGS_<family> is already defined          (test -n)
+#   2. Skip if the default uapi header does not exist      (test -f)
+#   3. Skip if the compiler can find it without help       (try $(CC))
+#   4. Otherwise error -- a new CFLAGS entry is needed
+check-new-deps-%:
+	@test -n "$(CFLAGS_$*)" \
+	  || ! test -f $(UAPI_PATH)/linux/$(subst -,_,$*).h \
+	  || echo "#include <linux/$(subst -,_,$*).h>" | \
+	     $(CC) -x c -fsyntax-only - 2>/dev/null \
+	  || { echo "ERROR: $* needs CFLAGS entry for linux/$(subst -,_,$*).h"; exit 1; }
diff --git a/tools/net/ynl/generated/Makefile b/tools/net/ynl/generated/Makefile
index 86e1e4a959a7..0f1d2c70b6a5 100644
--- a/tools/net/ynl/generated/Makefile
+++ b/tools/net/ynl/generated/Makefile
@@ -83,5 +83,9 @@ install-rsts: $(RSTS)
 
 install: install-headers install-rsts install-specs
 
-.PHONY: all clean distclean regen install install-headers install-rsts install-specs
+check-deps: $(patsubst %,check-existing-deps-%,$(GENS)) \
+	    $(patsubst %,check-new-deps-%,$(GENS))
+	@echo "All Makefile.deps OK"
+
+.PHONY: all clean distclean regen install install-headers install-rsts install-specs check-deps
 .DEFAULT_GOAL: all
-- 
2.53.0-Meta


  parent reply	other threads:[~2026-05-08 20:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 20:41 [PATCH net-next 0/2] tools/ynl: add missing uapi header deps in Makefile.deps Stanislav Fomichev
2026-05-08 20:41 ` [PATCH net-next 1/2] " Stanislav Fomichev
2026-05-08 20:41 ` Stanislav Fomichev [this message]
2026-05-10 15:35   ` [PATCH net-next 2/2] tools/ynl: add check-deps target to verify Makefile.deps completeness Jakub Kicinski
2026-05-10 15:40 ` [PATCH net-next 0/2] tools/ynl: add missing uapi header deps in Makefile.deps patchwork-bot+netdevbpf

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

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

  git send-email \
    --in-reply-to=20260508204114.205896-3-sdf@fomichev.me \
    --to=sdf.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    /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