diff --git a/Makefile b/Makefile index 5c8a6e3d..52215300 100644 --- a/Makefile +++ b/Makefile @@ -32,12 +32,21 @@ $(KCONFIG_CONFIG): $(KCONFIG_TOP) $(KCONFIG_TOP): generated/Config.in generated/Config.probed generated/unstripped/kconfig 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 defconfig: $(KCONFIG_TOP) generated/Config.in 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 baseline: generated/unstripped/toybox @cp generated/unstripped/toybox generated/unstripped/toybox_old diff --git a/kconfig/Makefile b/kconfig/Makefile index c7b9409e..352a6021 100644 --- a/kconfig/Makefile +++ b/kconfig/Makefile @@ -5,8 +5,7 @@ KCONFIG_TOP = Config.in KCONFIG_PROJECT = ToyBox obj = ./kconfig -PHONY += clean help oldconfig menuconfig config silentoldconfig \ - randconfig allyesconfig allnoconfig allmodconfig +PHONY += clean help oldconfig menuconfig config silentoldconfig menuconfig: $(obj)/mconf $(KCONFIG_TOP) $< $(KCONFIG_TOP) @@ -20,15 +19,6 @@ oldconfig: $(obj)/conf $(KCONFIG_TOP) silentoldconfig: $(obj)/conf $(KCONFIG_TOP) 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 macos_defconfig: $(obj)/conf $(KCONFIG_TOP) diff --git a/scripts/kconfig.c b/scripts/kconfig.c index 4e50b738..26e4fe74 100644 --- a/scripts/kconfig.c +++ b/scripts/kconfig.c @@ -27,6 +27,9 @@ struct kconfig { 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 char *trim(char *s) { @@ -167,17 +170,21 @@ struct kconfig *read_Config(char *name, struct kconfig *contain) return klist; } +// TODO: randconfig isn't randomizing CHOICE entries int value(struct kconfig *kc) { char *s = kc->value ? : kc->def ? : 0; if (!s) { - if (!strcmp(kc->contain->type, "choice") - && !strcmp(kc->contain->def, kc->symbol)) s = "y"; - else s = ""; + if (!strcmp(kc->contain->type, "choice")) + return !strcmp(kc->contain->def, kc->symbol); + 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) @@ -233,7 +240,7 @@ void options(char *opt) if (!(tt = strchr(esc, *ss))) putchar(*ss); else printf("\\%c", "n\\\""[tt-esc]); 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); struct tm *tt = localtime(&t); char buf[64]; @@ -245,10 +252,10 @@ void options(char *opt) if (!strcmp(kk->type, "menu") || !strcmp(kk->type, "comment")) printf("\n#\n# %s\n#\n", kk->prompt ? : ""); if (!(ss = kk->symbol)) continue; - if (*kk->type=='b') + if (*kk->type=='b') { printf((depends(kc, kk) && value(kk)) ? "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 ? : ""); else printf("CONFIG_%s=%d\n", ss, value(kk)); }