From: Felipe Contreras <felipe.contreras@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-kbuild@vger.kernel.org,
"Yann E. MORIN" <yann.morin.1998@free.fr>,
Linus Torvalds <torvalds@linux-foundation.org>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [RFC/PATCH 2/2] kconfig: add KCONFIG_BASECONFIG option to savedefconfig
Date: Thu, 27 Aug 2015 08:08:45 -0500 [thread overview]
Message-ID: <1440680925-2879-3-git-send-email-felipe.contreras@gmail.com> (raw)
In-Reply-To: <1440680925-2879-1-git-send-email-felipe.contreras@gmail.com>
This option parses a defconfig file, and sets all the values as default
ones. The result is a much simplified defconfig.
This defconfig can be used as a KBUILD_USERCONFIG, which added to the
default defconfig generates exactly the same config file.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
scripts/kconfig/conf.c | 3 ++
scripts/kconfig/confdata.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
scripts/kconfig/lkc_proto.h | 1 +
3 files changed, 93 insertions(+)
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 6c20431..382151c 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -698,6 +698,9 @@ int main(int ac, char **av)
return 1;
}
} else if (input_mode == savedefconfig) {
+ name = getenv("KCONFIG_BASECONFIG");
+ if (name)
+ conf_read_def(name);
if (conf_write_defconfig(defconfig_file)) {
fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
defconfig_file);
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index c814f57..af96042 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -476,6 +476,95 @@ int conf_read(const char *name)
return 0;
}
+static void conf_set_sym_default(struct symbol *sym, char *p)
+{
+ struct property *prop, **propp;
+
+ prop = xmalloc(sizeof(*prop));
+ memset(prop, 0, sizeof(*prop));
+ prop->type = P_DEFAULT;
+ prop->sym = sym;
+ prop->file = current_file;
+ prop->lineno = zconf_lineno();
+
+ for (propp = &sym->prop; *propp; propp = &(*propp)->next) {
+ if ((*propp)->type == P_DEFAULT) {
+ prop->next = *propp;
+ break;
+ }
+ }
+ *propp = prop;
+
+ prop->expr = expr_alloc_symbol(sym_lookup(p, SYMBOL_CONST));
+}
+
+int conf_read_def(const char *name)
+{
+ FILE *in = NULL;
+ char *line = NULL;
+ size_t line_asize = 0;
+ char *p, *p2;
+ struct symbol *sym;
+
+ in = zconf_fopen(name);
+ if (!in)
+ return 1;
+
+ conf_filename = name;
+ conf_lineno = 0;
+ conf_warnings = 0;
+
+ while (compat_getline(&line, &line_asize, in) != -1) {
+ conf_lineno++;
+ sym = NULL;
+ if (line[0] == '#') {
+ if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
+ continue;
+ p = strchr(line + 2 + strlen(CONFIG_), ' ');
+ if (!p)
+ continue;
+ *p++ = 0;
+ if (strncmp(p, "is not set", 10))
+ continue;
+ sym = sym_find(line + 2 + strlen(CONFIG_));
+ if (!sym)
+ continue;
+ switch (sym->type) {
+ case S_BOOLEAN:
+ case S_TRISTATE:
+ conf_set_sym_default(sym, "n");
+ break;
+ default:
+ ;
+ }
+ } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
+ p = strchr(line + strlen(CONFIG_), '=');
+ if (!p)
+ continue;
+ *p++ = 0;
+ p2 = strchr(p, '\n');
+ if (p2) {
+ *p2-- = 0;
+ if (*p2 == '\r')
+ *p2 = 0;
+ }
+
+ sym = sym_find(line + strlen(CONFIG_));
+ if (!sym)
+ continue;
+ conf_set_sym_default(sym, p);
+ } else {
+ if (line[0] != '\r' && line[0] != '\n')
+ conf_warning("unexpected data");
+ continue;
+ }
+ }
+ free(line);
+ fclose(in);
+
+ return 0;
+}
+
/*
* Kconfig configuration printer
*
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index d539871..69c3785 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -3,6 +3,7 @@
/* confdata.c */
void conf_parse(const char *name);
int conf_read(const char *name);
+int conf_read_def(const char *name);
int conf_read_simple(const char *name, int);
int conf_write_defconfig(const char *name);
int conf_write(const char *name);
--
2.5.0
next prev parent reply other threads:[~2015-08-27 13:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 13:08 [RFC/PATCH 0/2] A simpler way to maintain custom defconfigs Felipe Contreras
2015-08-27 13:08 ` [RFC/PATCH 1/2] kconfig: add KBUILD_USERCONFIG option Felipe Contreras
2015-08-27 13:08 ` Felipe Contreras [this message]
2015-08-28 12:55 ` [RFC/PATCH 0/2] A simpler way to maintain custom defconfigs John Stoffel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440680925-2879-3-git-send-email-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=yann.morin.1998@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®