summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-09-08 17:25:51 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-09-08 19:33:47 +0200
commit374f48873424f9167f508a53a80f3ea1c2d41c46 (patch)
tree3a4d93f34e261df55e4ba7551678350dd4ecbce7
parent87fe0b8a96d8aa522b47dee46dfeaf4fbc0c306b (diff)
Clean up kernel Makefile patch and add new targets
Add two new targets: - 'make kmenuconfig' runs the menuconfig interface - 'make dumpvarsconfig' lists all referenced environment variables together with their values (assuming they used the preprocessor syntax) Remove the 'kconfiglibtestconfig' target, which is no longer used. Also clean up the target definitions. The joys of ancient code.
-rw-r--r--README.rst8
-rw-r--r--examples/dumpvars.py15
-rw-r--r--kconfiglib.py33
-rw-r--r--makefile.patch48
4 files changed, 66 insertions, 38 deletions
diff --git a/README.rst b/README.rst
index 54d8ad2..7eb1197 100644
--- a/README.rst
+++ b/README.rst
@@ -21,10 +21,10 @@ exclusively, with lots of small helper scripts in other projects.
Kconfiglib implements the recently added `Kconfig preprocessor
<https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kconfig-macro-language.txt>`_.
For backwards compatibility, environment variables can be referenced both as
-``$(FOO)`` (the new syntax) and as ``$FOO`` (the old syntax). Support for the
-old syntax might be removed in the future (the major version would be increased
-at the same time). Using the old syntax with an undefined environment variable
-keeps the string as is.
+``$(FOO)`` (the new syntax) and as ``$FOO`` (the old syntax). The old syntax is
+deprecated, but will probably be supported for a very long time (the major
+version would be increased if support is ever dropped). Using the old syntax
+with an undefined environment variable keeps the string as is.
Note: See `this issue <https://github.com/ulfalizer/Kconfiglib/issues/47>`_ if you run into
a "macro expanded to blank string" error with kernel 4.18+.
diff --git a/examples/dumpvars.py b/examples/dumpvars.py
new file mode 100644
index 0000000..5ce65c2
--- /dev/null
+++ b/examples/dumpvars.py
@@ -0,0 +1,15 @@
+# Shows a list of all (set) environment variables referenced in the Kconfig
+# files, together with their values.
+#
+# Note: This only works for environment variables referenced via the $(FOO)
+# preprocessor syntax. The older $FOO syntax is maintained for backwards
+# compatibility.
+
+import os
+import sys
+
+import kconfiglib
+
+
+for var in kconfiglib.Kconfig(sys.argv[1]).env_vars:
+ print("{:16} '{}'".format(var, os.environ[var]))
diff --git a/kconfiglib.py b/kconfiglib.py
index 770614a..c0746ec 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -44,6 +44,13 @@ The targets added by the Makefile patch are described in the following
sections.
+make kmenuconfig
+----------------
+
+This target runs the curses menuconfig interface with Python 3 (Python 2 is
+currently not supported for the menuconfig).
+
+
make [ARCH=<arch>] iscriptconfig
--------------------------------
@@ -75,12 +82,23 @@ argument, if given.
See the examples/ subdirectory for example scripts.
+make dumpvarsconfig
+-------------------
+
+This target prints a list of all environment variables referenced from the
+Kconfig files, together with their values. See the
+Kconfiglib/examples/dumpvars.py script.
+
+Only environment variables that are referenced via the Kconfig preprocessor
+$(FOO) syntax are included. The preprocessor was added in Linux 4.18.
+
+
Using Kconfiglib without the Makefile targets
=============================================
The make targets are only needed to pick up environment variables exported from
the Kbuild makefiles and referenced inside Kconfig files, via e.g.
-'source "arch/$(SRCARCH)/Kconfig" and '$(shell,...)'.
+'source "arch/$(SRCARCH)/Kconfig" and commands run via '$(shell,...)'.
These variables are referenced as of writing (Linux 4.18), together with sample
values:
@@ -94,6 +112,12 @@ values:
HOSTCXX (g++)
CC_VERSION_TEXT (gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0)
+Older kernels only reference ARCH, SRCARCH, and KERNELVERSION.
+
+If your kernel is recent enough (4.18+), you can get a list of referenced
+environment variables via 'make dumpvarsconfig' (see above). Note that this
+command is added by the Makefile patch.
+
To run Kconfiglib without the Makefile patch, set the environment variables
manually:
@@ -104,13 +128,6 @@ manually:
Search the top-level Makefile for "Additional ARCH settings" to see other
possibilities for ARCH and SRCARCH.
-To see a list of all referenced environment variables together with their
-values, run this code from e.g. 'make iscriptconfig':
-
- import os
- for var in kconf.env_vars:
- print(var, os.environ[var])
-
Intro to symbol values
======================
diff --git a/makefile.patch b/makefile.patch
index 5b71d10..9992755 100644
--- a/makefile.patch
+++ b/makefile.patch
@@ -1,22 +1,24 @@
-From 01899aa5e6d1f33e1965d7934bea2ff97a48bc89 Mon Sep 17 00:00:00 2001
+From 7cac9bab3de49c03e1edce71d5d4b631d7464b74 Mon Sep 17 00:00:00 2001
From: Ulf Magnusson <ulfalizer@gmail.com>
Date: Tue, 9 Jun 2015 13:01:34 +0200
-Subject: [PATCH] Kconfiglib scripts/kconfig/Makefile patch.
+Subject: [PATCH] Kconfiglib scripts/kconfig/Makefile patch
---
- scripts/kconfig/Makefile | 35 +++++++++++++++++++++++++++++++++++
- 1 file changed, 35 insertions(+)
+ scripts/kconfig/Makefile | 30 ++++++++++++++++++++++++++++++
+ 1 file changed, 30 insertions(+)
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
-index 8c12c20c55a6..88c618b34915 100644
+index 4a7bd2192073..448cd1cb9314 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
-@@ -27,1 +27,36 @@ gconfig: $(obj)/gconf
-+PHONY += scriptconfig iscriptconfig kconfiglibtestconfig
+@@ -27,2 +27,32 @@ gconfig: $(obj)/gconf
+
++PHONY += scriptconfig iscriptconfig kmenuconfig dumpvarsconfig
+
-+ifneq ($(filter scriptconfig iscriptconfig,$(MAKECMDGOALS)),)
-+PYTHONCMD ?= python
-+endif
++PYTHONCMD ?= python
++kpythonpath := PYTHONPATH=$(srctree)/Kconfiglib:$$PYTHONPATH
++kpython := $(kpythonpath) $(PYTHONCMD)
++kpython3 := $(kpythonpath) python3
+
+ifneq ($(filter scriptconfig,$(MAKECMDGOALS)),)
+ifndef SCRIPT
@@ -25,29 +27,23 @@ index 8c12c20c55a6..88c618b34915 100644
+endif
+
+scriptconfig:
-+ifdef SCRIPT_ARG
-+ $(Q)PYTHONPATH="$(srctree)/Kconfiglib:$$PYTHONPATH" \
-+ "$(PYTHONCMD)" "$(SCRIPT)" $(Kconfig) "$(SCRIPT_ARG)"
-+else
-+ $(Q)PYTHONPATH="$(srctree)/Kconfiglib:$$PYTHONPATH" \
-+ "$(PYTHONCMD)" "$(SCRIPT)" $(Kconfig)
-+endif
++ $(Q)$(kpython) $(SCRIPT) $(Kconfig) $(if $(SCRIPT_ARG),"$(SCRIPT_ARG)")
+
+iscriptconfig:
-+ $(Q)PYTHONPATH="$(srctree)/Kconfiglib:$$PYTHONPATH" "$(PYTHONCMD)" -i -c \
++ $(Q)$(kpython) -i -c \
+ "import kconfiglib; \
+ import sys; \
-+ kconf = kconfiglib.Kconfig(sys.argv[4 if \"$(PYTHONCMD)\".startswith(\"ipython\") else 1]); \
-+ print(\"A Kconfig instance 'kconf' for the architecture $(ARCH) has been created.\")" \
++ kconf = kconfiglib.Kconfig(sys.argv[4 if '$(PYTHONCMD)'.startswith('ipython') else 1]); \
++ print('A Kconfig instance \'kconf\' for the architecture $(ARCH) has been created.')" \
+ $(Kconfig)
+
-+# Used by testsuite.py to be able to compare output for nonsensical
-+# arch/defconfig combinations, which has proven effective for finding obscure
-+# bugs
-+kconfiglibtestconfig: $(obj)/conf
-+ $(Q)$< --defconfig=.config $(Kconfig)
++kmenuconfig:
++ $(Q)$(kpython3) $(srctree)/Kconfiglib/menuconfig.py $(Kconfig)
++
++dumpvarsconfig:
++ $(Q)$(kpython) $(srctree)/Kconfiglib/examples/dumpvars.py $(Kconfig)
+
menuconfig: $(obj)/mconf
--
-2.14.1
+2.17.1