Add a checkconfig target to validate the current kernel .config against a
set of rules.  Select the rules using a mandatory RULES= make variable.

Example usage:

   make RULES=preempt_rt checkconfig

Use the kconfig-checker to perform all sanity checks.

Document the new target at the 'make help' text.

Signed-off-by: Ahmed S. Darwish <[email protected]>
---
 scripts/kconfig/Makefile | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 5baf1c44ffa2..d67a23730259 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -125,6 +125,26 @@ testconfig: $(obj)/conf
        $(if $(findstring 1,$(KBUILD_VERBOSE)),--capture=no)
 clean-files += tests/.cache
 
+checkconfig := $(PYTHON3) -B $(srctree)/tools/kconfig-checker/check.py
+list_checkconfig_rules =                                               \
+       echo -n >&2 "Available RULES: ";                                \
+       $(checkconfig) list-rules >&2;                                  \
+       echo >&2
+
+PHONY += checkconfig
+checkconfig:
+       $(Q)if [ -z "$(RULES)" ]; then                                  \
+               echo >&2 "Usage: make RULES=<profile> checkconfig";     \
+               $(list_checkconfig_rules);                              \
+               exit 2;                                                 \
+       fi
+       $(Q)if ! $(checkconfig) list-rules | grep -qw "$(RULES)"; then  \
+               echo >&2 "Unknown RULES profile = $(RULES)";            \
+               $(list_checkconfig_rules);                              \
+               exit 2;                                                 \
+       fi
+       $(Q)$(checkconfig) check -r "$(RULES)" -c "$(KCONFIG_CONFIG)"
+
 # Help text used by make help
 help:
        @echo  'Configuration targets:'
@@ -154,6 +174,9 @@ help:
        @echo  '                    default value without prompting'
        @echo  '  tinyconfig      - Configure the tiniest possible kernel'
        @echo  '  testconfig      - Run Kconfig unit tests (requires python3 
and pytest)'
+       @echo  '  checkconfig     - Check current config against sanity rules 
specified by RULES'
+       @echo  '                    Example usage: "make RULES=preempt_rt 
checkconfig"'
+       @echo  '                    (requires python3, PyYAML, and jsonschema)'
        @echo  ''
        @echo  'Configuration topic targets:'
        @$(foreach f, $(all-config-fragments), \
-- 
2.56.0

Reply via email to