blob: 2e6a24f30fb523bba2fa8ad1eac6d40e54bf284f [file] [log] [blame]
Patrick Georgi53ea1d42019-11-22 16:55:58 +01001From 5e2355bf017b3347b29126a0eeb866558334f704 Mon Sep 17 00:00:00 2001
2From: Stefan Reinauer <stefan.reinauer@coreboot.org>
3Date: Fri, 3 Apr 2015 20:01:38 +0200
4Subject: [PATCH] kconfig: Add wildcard support for "source"
5
6Kconfig's include directive "source" does not support
7wildcards (e.g. source src/mainboard/*/Kconfig) which
8makes automatic inclusion of all boards a tedious task
9and prevents us from implementing "drop in" boards.
10
Martin Roth659f97c2024-01-18 19:06:14 -070011In our Makefile.mk files we already include mainboard
Patrick Georgi53ea1d42019-11-22 16:55:58 +010012directories per wildcard, so let's add the infrastructure
13to do the same with Kconfig.
14
15v2: change from wordexp to glob for better portability.
16
17Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
18Signed-off-by: Patrick Georgi <pgeorgi@google.com>
19---
20 util/kconfig/lexer.l | 27 +++++++++++++++++++++++++++
21 util/kconfig/lkc.h | 1 +
22 util/kconfig/parser.y | 2 +-
23 3 files changed, 29 insertions(+), 1 deletion(-)
24
25Index: kconfig/lexer.l
26===================================================================
27--- kconfig.orig/lexer.l
28+++ kconfig/lexer.l
29@@ -8,6 +8,7 @@
30 %{
Patrick Georgi3e397dd2024-01-30 23:37:11 +010031
Patrick Georgi53ea1d42019-11-22 16:55:58 +010032 #include <assert.h>
33+#include <glob.h>
34 #include <limits.h>
35 #include <stdio.h>
36 #include <stdlib.h>
Patrick Georgi4c9b9e92022-10-28 01:00:26 +020037@@ -439,6 +440,32 @@ void zconf_nextfile(const char *name)
Patrick Georgi53ea1d42019-11-22 16:55:58 +010038 current_file = file;
39 }
Patrick Georgi3e397dd2024-01-30 23:37:11 +010040
Patrick Georgi53ea1d42019-11-22 16:55:58 +010041+void zconf_nextfiles(const char *wildcard)
42+{
43+ glob_t g;
44+ char **w;
45+ int i;
46+
47+ if (glob(wildcard, 0, NULL, &g) != 0) {
48+ return;
49+ }
50+ if (g.gl_pathv == NULL) {
51+ globfree(&g);
52+ return;
53+ }
54+
55+ /* working through files backwards, since
56+ * we're first pushing them on a stack
57+ * before actually handling them.
58+ */
59+ for (i = g.gl_pathc; i > 0; i--) {
60+ w = &g.gl_pathv[i - 1];
61+ zconf_nextfile(*w);
62+ }
63+
64+ globfree(&g);
65+}
66+
67 static void zconf_endfile(void)
68 {
69 struct buffer *parent;
70Index: kconfig/lkc.h
71===================================================================
72--- kconfig.orig/lkc.h
73+++ kconfig/lkc.h
74@@ -36,6 +36,7 @@ void zconf_starthelp(void);
75 FILE *zconf_fopen(const char *name);
76 void zconf_initscan(const char *name);
77 void zconf_nextfile(const char *name);
78+void zconf_nextfiles(const char *name);
79 int zconf_lineno(void);
80 const char *zconf_curname(void);
Patrick Georgi3e397dd2024-01-30 23:37:11 +010081
Patrick Georgi53ea1d42019-11-22 16:55:58 +010082Index: kconfig/parser.y
83===================================================================
84--- kconfig.orig/parser.y
85+++ kconfig/parser.y
86@@ -358,7 +358,7 @@ menu_option_list:
87 source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
88 {
89 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
90- zconf_nextfile($2);
91+ zconf_nextfiles($2);
92 free($2);
93 };
Patrick Georgi3e397dd2024-01-30 23:37:11 +010094