summaryrefslogtreecommitdiffstats
path: root/util/kconfig/patches/0008-kconfig-Add-wildcard-support-for-source.patch
blob: 688b387407f49a05ba1747a49f16bd01496294c8 (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
From 5e2355bf017b3347b29126a0eeb866558334f704 Mon Sep 17 00:00:00 2001
From: Stefan Reinauer <stefan.reinauer@coreboot.org>
Date: Fri, 3 Apr 2015 20:01:38 +0200
Subject: [PATCH] kconfig: Add wildcard support for "source"

Kconfig's include directive "source" does not support
wildcards (e.g. source src/mainboard/*/Kconfig) which
makes automatic inclusion of all boards a tedious task
and prevents us from implementing "drop in" boards.

In our Makefile.inc files we already include mainboard
directories per wildcard, so let's add the infrastructure
to do the same with Kconfig.

v2: change from wordexp to glob for better portability.

Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
---
 util/kconfig/lexer.l  | 27 +++++++++++++++++++++++++++
 util/kconfig/lkc.h    |  1 +
 util/kconfig/parser.y |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)

Index: kconfig/lexer.l
===================================================================
--- kconfig.orig/lexer.l
+++ kconfig/lexer.l
@@ -8,6 +8,7 @@
 %{
 
 #include <assert.h>
+#include <glob.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -439,6 +440,32 @@ void zconf_nextfile(const char *name)
 	current_file = file;
 }
 
+void zconf_nextfiles(const char *wildcard)
+{
+	glob_t g;
+	char **w;
+	int i;
+
+	if (glob(wildcard, 0, NULL, &g) != 0) {
+		return;
+	}
+	if (g.gl_pathv == NULL) {
+		globfree(&g);
+		return;
+	}
+
+	/* working through files backwards, since
+	 * we're first pushing them on a stack
+	 * before actually handling them.
+	 */
+	for (i = g.gl_pathc; i > 0; i--) {
+		w = &g.gl_pathv[i - 1];
+		zconf_nextfile(*w);
+	}
+
+	globfree(&g);
+}
+
 static void zconf_endfile(void)
 {
 	struct buffer *parent;
Index: kconfig/lkc.h
===================================================================
--- kconfig.orig/lkc.h
+++ kconfig/lkc.h
@@ -36,6 +36,7 @@ void zconf_starthelp(void);
 FILE *zconf_fopen(const char *name);
 void zconf_initscan(const char *name);
 void zconf_nextfile(const char *name);
+void zconf_nextfiles(const char *name);
 int zconf_lineno(void);
 const char *zconf_curname(void);
 
Index: kconfig/parser.y
===================================================================
--- kconfig.orig/parser.y
+++ kconfig/parser.y
@@ -358,7 +358,7 @@ menu_option_list:
 source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
 {
 	printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
-	zconf_nextfile($2);
+	zconf_nextfiles($2);
 	free($2);
 };