• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 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
11In our Makefile.mk files we already include mainboard
12directories 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 %{
31
32 #include <assert.h>
33+#include <glob.h>
34 #include <limits.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37@@ -439,6 +440,32 @@ void zconf_nextfile(const char *name)
38 	current_file = file;
39 }
40
41+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);
81
82Index: 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 };
94
95