aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2010-07-31 17:35:34 -0400
committerMichal Marek <mmarek@suse.cz>2010-08-03 07:49:32 -0400
commit7cf3d73b4360e91b14326632ab1aeda4cb26308d (patch)
tree547bc52c631c9fb99ecd5c4be5ba25610505397a /scripts/kconfig/confdata.c
parent49192f266ffa187bd7adaf5c2d881f85bd53e0ed (diff)
kconfig: add savedefconfig
savedefconfig will save a minimal config to a file named "defconfig". The config symbols are saved in the same order as they appear in the menu structure so it should be possible to map them to the relevant menus if desired. The implementation was tested against several minimal configs for arm which was created using brute-force. There was one regression related to default numbers which had their valid range further limited by another symbol. Sample: config FOO int "foo" default 4 config BAR int "bar" range 0 FOO If FOO is set to 3 then BAR cannot take a value higher than 3. But the current implementation will set BAR equal to 4. This is seldomly used and the final configuration is OK, and the fix was non-trivial. So it was documented in the code and left as is. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 583f6405f01d..f81f263b64f2 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -457,6 +457,82 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
457 } 457 }
458} 458}
459 459
460/*
461 * Write out a minimal config.
462 * All values that has default values are skipped as this is redundant.
463 */
464int conf_write_defconfig(const char *filename)
465{
466 struct symbol *sym;
467 struct menu *menu;
468 FILE *out;
469
470 out = fopen(filename, "w");
471 if (!out)
472 return 1;
473
474 sym_clear_all_valid();
475
476 /* Traverse all menus to find all relevant symbols */
477 menu = rootmenu.list;
478
479 while (menu != NULL)
480 {
481 sym = menu->sym;
482 if (sym == NULL) {
483 if (!menu_is_visible(menu))
484 goto next_menu;
485 } else if (!sym_is_choice(sym)) {
486 sym_calc_value(sym);
487 if (!(sym->flags & SYMBOL_WRITE))
488 goto next_menu;
489 sym->flags &= ~SYMBOL_WRITE;
490 /* If we cannot change the symbol - skip */
491 if (!sym_is_changable(sym))
492 goto next_menu;
493 /* If symbol equals to default value - skip */
494 if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
495 goto next_menu;
496
497 /*
498 * If symbol is a choice value and equals to the
499 * default for a choice - skip.
500 * But only if value equal to "y".
501 */
502 if (sym_is_choice_value(sym)) {
503 struct symbol *cs;
504 struct symbol *ds;
505
506 cs = prop_get_symbol(sym_get_choice_prop(sym));
507 ds = sym_choice_default(cs);
508 if (sym == ds) {
509 if ((sym->type == S_BOOLEAN ||
510 sym->type == S_TRISTATE) &&
511 sym_get_tristate_value(sym) == yes)
512 goto next_menu;
513 }
514 }
515 conf_write_symbol(sym, sym->type, out, true);
516 }
517next_menu:
518 if (menu->list != NULL) {
519 menu = menu->list;
520 }
521 else if (menu->next != NULL) {
522 menu = menu->next;
523 } else {
524 while ((menu = menu->parent)) {
525 if (menu->next != NULL) {
526 menu = menu->next;
527 break;
528 }
529 }
530 }
531 }
532 fclose(out);
533 return 0;
534}
535
460int conf_write(const char *name) 536int conf_write(const char *name)
461{ 537{
462 FILE *out; 538 FILE *out;