summaryrefslogtreecommitdiff
path: root/makefile.patch
blob: 6f7a33ce0b58a8a87692a838b8a5826bfda2c7aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--- a/Documentation/kbuild/kconfig-language.txt
+++ b/Documentation/kbuild/kconfig-language.txt
@@ -381,3 +381,8 @@ config FOO
 
 limits FOO to module (=m) or disabled (=n).
 
+Kconfiglib
+~~~~~~~~~~
+If you need to programmatically generate a .config or parse Kconfig files,
+Kconfiglib might come handy. See 'scriptconfig' and 'iscriptconfig' in
+'make help' and scripts/kconfig/kconfiglib.py.
diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
index cca46b1..73cf58f 100644
--- a/Documentation/kbuild/kconfig.txt
+++ b/Documentation/kbuild/kconfig.txt
@@ -195,4 +195,12 @@ Searching in gconfig:
 	however, gconfig does have a few more viewing choices than
 	xconfig does.
 
+======================================================================
+scriptconfig
+--------------------------------------------------
+
+If you need to programmatically generate a .config or parse Kconfig files,
+Kconfiglib might come handy. See 'scriptconfig' and 'iscriptconfig' in
+'make help' and scripts/kconfig/kconfiglib.py.
+
 ###
diff --git a/README b/README
index 1b81d28..bb5e68f 100644
--- a/README
+++ b/README
@@ -196,6 +196,19 @@ CONFIGURING the kernel:
 			   values to 'n' as much as possible.
 	"make randconfig"  Create a ./.config file by setting symbol
 			   values to random values.
+	"make scriptconfig SCRIPT=<path to script>" Run a Kconfiglib
+			   script (see scripts/kconfig/kconfiglib.py).  This
+			   can be used to programatically generate a
+			   ./.config, and for applications that need to
+			   extract information from Kconfig files.
+	"make iscriptconfig" Launch an interactive Python shell
+			   for running Kconfiglib on the architecture's
+			   Kconfig configuration.  The kconfiglib and sys
+			   (for sys.argv[1] - the base Kconfig file) modules
+			   will be imported automatically, and a Config
+			   instance 'c' will be created for the architecture
+			   (using c = kconfiglib.Config(sys.argv[1])).
+
 
    You can find more information on using the Linux kernel config tools
    in Documentation/kbuild/kconfig.txt.
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 368ae30..0044933 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -3,7 +3,7 @@
 # These targets are used from top-level makefile
 
 PHONY += oldconfig xconfig gconfig menuconfig config silentoldconfig update-po-config \
-	localmodconfig localyesconfig
+	localmodconfig localyesconfig scriptconfig iscriptconfig kconfiglibtestconfig
 
 ifdef KBUILD_KCONFIG
 Kconfig := $(KBUILD_KCONFIG)
@@ -33,6 +33,30 @@ silentoldconfig: $(obj)/conf
 	$(Q)mkdir -p include/generated
 	$< --$@ $(Kconfig)
 
+ifneq ($(filter scriptconfig iscriptconfig,$(MAKECMDGOALS)),)
+PYTHONCMD ?= python
+endif
+
+scriptconfig:
+	$(Q)if [ ! -n "$(SCRIPT)" ]; then                                                                     \
+			echo 'No script argument provided; use "make scriptconfig SCRIPT=<path to script>".'; \
+	else                                                                                                  \
+			PYTHONPATH="$(srctree)/$(src):$$PYTHONPATH"                                           \
+			  "$(PYTHONCMD)" "$(SCRIPT)" $(srctree)/$(Kconfig);                                   \
+	fi
+
+iscriptconfig:
+	$(Q)PYTHONPATH="$(srctree)/$(src):$$PYTHONPATH" "$(PYTHONCMD)" -i -c \
+	  "import kconfiglib; \
+	   import sys; \
+	   c = kconfiglib.Config(sys.argv[1]); \
+	   print \"A Config instance 'c' for the architecture ({0}) has been created.\".format(c.get_arch())" \
+	  $(srctree)/$(Kconfig)
+
+# Used by kconfigtest.py to prevent an 'option defconfig' .config from being loaded
+kconfiglibtestconfig: $(obj)/conf
+	$(Q)$< --defconfig=.config $(srctree)/$(Kconfig)
+
 # if no path is given, then use src directory to find file
 ifdef LSMOD
 LSMOD_F := $(LSMOD)
@@ -139,6 +163,8 @@ help:
 	@echo  '  randconfig	  - New config with random answer to all options'
 	@echo  '  listnewconfig   - List new options'
 	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
+	@echo  '  scriptconfig    - Run a kconfiglib script (see scripts/kconfig/kconfiglib.py)'
+	@echo  '  iscriptconfig   - Launch interactive Python shell for using kconfiglib'
 
 # lxdialog stuff
 check-lxdialog  := $(srctree)/$(src)/lxdialog/check-lxdialog.sh