Add two make rules that detect missing entries in Makefile.deps: check-existing-deps-: 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-: for families without CFLAGS, check whether their default uapi header (linux/.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 --- 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_ (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_ (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/.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_ 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 " | \ + $(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