summaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/preprocess.c
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 11:21:46 +0200
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 20:31:19 +0200
commit2fd5b09c201e20ab87299efd6a25f0bfc546e7c9 (patch)
tree712cb918bbc6c7f58314e03330ea51bec6612905 /scripts/kconfig/preprocess.c
parentkconfig: add built-in function support (diff)
downloadlinux-2fd5b09c201e20ab87299efd6a25f0bfc546e7c9.tar.xz
linux-2fd5b09c201e20ab87299efd6a25f0bfc546e7c9.zip
kconfig: add 'shell' built-in function
This accepts a single command to execute. It returns the standard output from it. [Example code] config HELLO string default "$(shell,echo hello world)" config Y def_bool $(shell,echo y) [Result] $ make -s alldefconfig && tail -n 2 .config CONFIG_HELLO="hello world" CONFIG_Y=y Caveat: Like environments, functions are expanded in the lexer. You cannot pass symbols to function arguments. This is a limitation to simplify the implementation. I want to avoid the dynamic function evaluation, which would introduce much more complexity. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/kconfig/preprocess.c')
-rw-r--r--scripts/kconfig/preprocess.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index f32a496626da..528be594e1d0 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -106,8 +106,49 @@ struct function {
char *(*func)(int argc, char *argv[]);
};
+static char *do_shell(int argc, char *argv[])
+{
+ FILE *p;
+ char buf[256];
+ char *cmd;
+ size_t nread;
+ int i;
+
+ cmd = argv[0];
+
+ p = popen(cmd, "r");
+ if (!p) {
+ perror(cmd);
+ exit(1);
+ }
+
+ nread = fread(buf, 1, sizeof(buf), p);
+ if (nread == sizeof(buf))
+ nread--;
+
+ /* remove trailing new lines */
+ while (buf[nread - 1] == '\n')
+ nread--;
+
+ buf[nread] = 0;
+
+ /* replace a new line with a space */
+ for (i = 0; i < nread; i++) {
+ if (buf[i] == '\n')
+ buf[i] = ' ';
+ }
+
+ if (pclose(p) == -1) {
+ perror(cmd);
+ exit(1);
+ }
+
+ return xstrdup(buf);
+}
+
static const struct function function_table[] = {
/* Name MIN MAX Function */
+ { "shell", 1, 1, do_shell },
};
#define FUNCTION_MAX_ARGS 16