Move allyesconfig, allnoconfig, and randconfig over to new kconfig.c

This commit is contained in:
Rob Landley 2025-05-01 14:06:17 -05:00
parent 5d1fd7a302
commit 79cd1a4537
3 changed files with 25 additions and 19 deletions

View File

@ -32,12 +32,21 @@ $(KCONFIG_CONFIG): $(KCONFIG_TOP)
$(KCONFIG_TOP): generated/Config.in generated/Config.probed generated/unstripped/kconfig $(KCONFIG_TOP): generated/Config.in generated/Config.probed generated/unstripped/kconfig
generated/Config.probed: generated/Config.in generated/Config.probed: generated/Config.in
generated/Config.in: toys/*/*.c scripts/genconfig.sh generated/Config.in: toys/*/*.c scripts/genconfig.sh scripts/kconfig.c
scripts/genconfig.sh scripts/genconfig.sh
defconfig: $(KCONFIG_TOP) generated/Config.in defconfig: $(KCONFIG_TOP) generated/Config.in
generated/unstripped/kconfig -d > $(KCONFIG_CONFIG) generated/unstripped/kconfig -d > $(KCONFIG_CONFIG)
randconfig: $(KCONFIG_TOP) generated/Config.in
generated/unstripped/kconfig -r > $(KCONFIG_CONFIG)
allyesconfig: $(KCONFIG_TOP) generated/Config.in
generated/unstripped/kconfig -y > $(KCONFIG_CONFIG)
allnoconfig: $(KCONFIG_TOP) generated/Config.in
generated/unstripped/kconfig -n > $(KCONFIG_CONFIG)
# Development targets # Development targets
baseline: generated/unstripped/toybox baseline: generated/unstripped/toybox
@cp generated/unstripped/toybox generated/unstripped/toybox_old @cp generated/unstripped/toybox generated/unstripped/toybox_old

View File

@ -5,8 +5,7 @@
KCONFIG_TOP = Config.in KCONFIG_TOP = Config.in
KCONFIG_PROJECT = ToyBox KCONFIG_PROJECT = ToyBox
obj = ./kconfig obj = ./kconfig
PHONY += clean help oldconfig menuconfig config silentoldconfig \ PHONY += clean help oldconfig menuconfig config silentoldconfig
randconfig allyesconfig allnoconfig allmodconfig
menuconfig: $(obj)/mconf $(KCONFIG_TOP) menuconfig: $(obj)/mconf $(KCONFIG_TOP)
$< $(KCONFIG_TOP) $< $(KCONFIG_TOP)
@ -20,15 +19,6 @@ oldconfig: $(obj)/conf $(KCONFIG_TOP)
silentoldconfig: $(obj)/conf $(KCONFIG_TOP) silentoldconfig: $(obj)/conf $(KCONFIG_TOP)
yes '' | $< -o $(KCONFIG_TOP) > /dev/null yes '' | $< -o $(KCONFIG_TOP) > /dev/null
randconfig: $(obj)/conf $(KCONFIG_TOP)
$< -r $(KCONFIG_TOP) > /dev/null
allyesconfig: $(obj)/conf $(KCONFIG_TOP)
$< -y $(KCONFIG_TOP) > /dev/null
allnoconfig: $(obj)/conf $(KCONFIG_TOP)
$< -n $(KCONFIG_TOP) > /dev/null
KCONFIG_ALLCONFIG ?= /dev/null KCONFIG_ALLCONFIG ?= /dev/null
macos_defconfig: $(obj)/conf $(KCONFIG_TOP) macos_defconfig: $(obj)/conf $(KCONFIG_TOP)

View File

@ -27,6 +27,9 @@ struct kconfig {
char *symbol, *value, *type, *prompt, *def, *depend, *help; char *symbol, *value, *type, *prompt, *def, *depend, *help;
}; };
// 0 = allnoconfig, 1 = defconfig, 2 = allyesconfig, 4 = randconfig
int cfgtype;
// Skip/remove leading space, quotes, and escapes within quotes // Skip/remove leading space, quotes, and escapes within quotes
char *trim(char *s) char *trim(char *s)
{ {
@ -167,17 +170,21 @@ struct kconfig *read_Config(char *name, struct kconfig *contain)
return klist; return klist;
} }
// TODO: randconfig isn't randomizing CHOICE entries
int value(struct kconfig *kc) int value(struct kconfig *kc)
{ {
char *s = kc->value ? : kc->def ? : 0; char *s = kc->value ? : kc->def ? : 0;
if (!s) { if (!s) {
if (!strcmp(kc->contain->type, "choice") if (!strcmp(kc->contain->type, "choice"))
&& !strcmp(kc->contain->def, kc->symbol)) s = "y"; return !strcmp(kc->contain->def, kc->symbol);
else s = ""; s = "";
} }
return *kc->type=='b' ? *s=='y' : atoi(s); if (*kc->type!='b') return atoi(s);
if (cfgtype==1 || !*kc->prompt) return *s=='y';
if (cfgtype==4) return random()&1;
return !!cfgtype;
} }
struct kconfig *lookup(struct kconfig *klist, char *symbol) struct kconfig *lookup(struct kconfig *klist, char *symbol)
@ -233,7 +240,7 @@ void options(char *opt)
if (!(tt = strchr(esc, *ss))) putchar(*ss); if (!(tt = strchr(esc, *ss))) putchar(*ss);
else printf("\\%c", "n\\\""[tt-esc]); else printf("\\%c", "n\\\""[tt-esc]);
printf("\"\n\n"); printf("\"\n\n");
} else if (!strcmp(opt, "-d")) { } else if (-1 != (cfgtype = strany(opt, (char *[]){"-n", "-d", "-y", 0})-1)) {
time_t t = time(0); time_t t = time(0);
struct tm *tt = localtime(&t); struct tm *tt = localtime(&t);
char buf[64]; char buf[64];
@ -245,10 +252,10 @@ void options(char *opt)
if (!strcmp(kk->type, "menu") || !strcmp(kk->type, "comment")) if (!strcmp(kk->type, "menu") || !strcmp(kk->type, "comment"))
printf("\n#\n# %s\n#\n", kk->prompt ? : ""); printf("\n#\n# %s\n#\n", kk->prompt ? : "");
if (!(ss = kk->symbol)) continue; if (!(ss = kk->symbol)) continue;
if (*kk->type=='b') if (*kk->type=='b') {
printf((depends(kc, kk) && value(kk)) printf((depends(kc, kk) && value(kk))
? "CONFIG_%s=y\n" : "# CONFIG_%s is not set\n", ss); ? "CONFIG_%s=y\n" : "# CONFIG_%s is not set\n", ss);
else if (*kk->type=='s') } else if (*kk->type=='s')
printf("CONFIG_%s=\"%s\"\n", ss, kk->value ? : kk->def ? : ""); printf("CONFIG_%s=\"%s\"\n", ss, kk->value ? : kk->def ? : "");
else printf("CONFIG_%s=%d\n", ss, value(kk)); else printf("CONFIG_%s=%d\n", ss, value(kk));
} }