Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1 | From 5e2355bf017b3347b29126a0eeb866558334f704 Mon Sep 17 00:00:00 2001 |
| 2 | From: Stefan Reinauer <stefan.reinauer@coreboot.org> |
| 3 | Date: Fri, 3 Apr 2015 20:01:38 +0200 |
| 4 | Subject: [PATCH] kconfig: Add wildcard support for "source" |
| 5 | |
| 6 | Kconfig's include directive "source" does not support |
| 7 | wildcards (e.g. source src/mainboard/*/Kconfig) which |
| 8 | makes automatic inclusion of all boards a tedious task |
| 9 | and prevents us from implementing "drop in" boards. |
| 10 | |
Martin Roth | 659f97c | 2024-01-18 19:06:14 -0700 | [diff] [blame] | 11 | In our Makefile.mk files we already include mainboard |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 12 | directories per wildcard, so let's add the infrastructure |
| 13 | to do the same with Kconfig. |
| 14 | |
| 15 | v2: change from wordexp to glob for better portability. |
| 16 | |
| 17 | Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org> |
| 18 | Signed-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 | |
| 25 | Index: kconfig/lexer.l |
| 26 | =================================================================== |
| 27 | --- kconfig.orig/lexer.l |
| 28 | +++ kconfig/lexer.l |
| 29 | @@ -8,6 +8,7 @@ |
| 30 | %{ |
Patrick Georgi | 3e397dd | 2024-01-30 23:37:11 +0100 | [diff] [blame^] | 31 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 32 | #include <assert.h> |
| 33 | +#include <glob.h> |
| 34 | #include <limits.h> |
| 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 37 | @@ -439,6 +440,32 @@ void zconf_nextfile(const char *name) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 38 | current_file = file; |
| 39 | } |
Patrick Georgi | 3e397dd | 2024-01-30 23:37:11 +0100 | [diff] [blame^] | 40 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 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; |
| 70 | Index: 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 Georgi | 3e397dd | 2024-01-30 23:37:11 +0100 | [diff] [blame^] | 81 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 82 | Index: 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 Georgi | 3e397dd | 2024-01-30 23:37:11 +0100 | [diff] [blame^] | 94 | |