From aaead8a5694356874b77f4a6c4f5012c7388d1ba Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 28 Nov 2026 22:21:23 -0600 Subject: [PATCH] Implement oldconfig, move config and oldconfig to new plumbing. --- Makefile | 8 +++- kconfig/Makefile | 12 +----- scripts/help.txt | 47 +++++++++++---------- scripts/kconfig.c | 105 +++++++++++++++++++++++++++++----------------- 4 files changed, 99 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 03788f21..afc1ee5d 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ toybox generated/unstripped/toybox: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/* .PHONY: clean distclean baseline bloatcheck install install_flat \ uninstall uninstall_flat tests help change defconfig \ - list list_example list_pending root run_root \ + list list_example list_pending root run_root config oldconfig \ defconfig randconfig allyesconfig allnoconfig silentoldconfig \ macos_defconfig bsd_defconfig android_defconfig @@ -48,6 +48,12 @@ allyesconfig: allnoconfig: scripts/genconfig.sh -n +config: + scripts/genconfig.sh -c + +oldconfig: + scripts/genconfig.sh -o + silentoldconfig: KCONFIG_ALLCONFIG=$(KCONFIG_CONFIG) scripts/genconfig.sh -d diff --git a/kconfig/Makefile b/kconfig/Makefile index 1331434c..967e3757 100644 --- a/kconfig/Makefile +++ b/kconfig/Makefile @@ -5,25 +5,15 @@ KCONFIG_TOP = Config.in KCONFIG_PROJECT = ToyBox obj = ./kconfig -PHONY += clean help oldconfig menuconfig config +PHONY += clean help menuconfig menuconfig: $(obj)/mconf $(KCONFIG_TOP) scripts/genconfig.sh $< $(KCONFIG_TOP) -config: $(obj)/conf $(KCONFIG_TOP) - scripts/genconfig.sh - $< $(KCONFIG_TOP) - -oldconfig: $(obj)/conf $(KCONFIG_TOP) - scripts/genconfig.sh - $< -o $(KCONFIG_TOP) - # Help text used by make help help:: - @echo ' config - Update current config utilising a line-oriented program' @echo ' menuconfig - Update current config utilising a menu based program' - @echo ' oldconfig - Update current config utilising a provided .config as base' # Cheesy build diff --git a/scripts/help.txt b/scripts/help.txt index fd6d1f8d..913b958a 100644 --- a/scripts/help.txt +++ b/scripts/help.txt @@ -1,14 +1,18 @@ - toybox - Build unified toybox with commands selected in .config - defconfig - Write .config with default answers (max sane config) - allyesconfig - New config where all options are accepted with yes - This may not actually compile, it's a starting point - for further configuration (probably with menuconfig) - allnoconfig - New config where all options are answered with no - randconfig - New config with random answer to all options - silentoldconfig - Same as oldconfig, but quietly + toybox - Build toybox with commands selected in file ".config" + + defconfig - Write new .config with default answers (max sane config) macos_defconfig - Select commands known to build on macosx bsd_defconfig - Select commands known to build on freebsd android_defconfig - Select commands available on android + config - Update .config by asking questions (ENTER = keep current) + allyesconfig - New .config where all options set to "yes" where possible + (may not actually compile due to unmet dependencies, mostly + a starting point for further config/menuconfig) + allnoconfig - New config where all options are answered with no + (mostly useless, again provides a starting point) + randconfig - New config with random answer to all options + oldconfig - Update .config only asking about new symbols + silentoldconfig - Same as oldconfig, but auto-fill gaps with defconfig COMMANDNAME - Build individual toybox command as a standalone binary. list - List COMMANDNAMEs you can build standalone. @@ -16,6 +20,16 @@ list_pending - List unfinished COMMANDNAMEs out of toys/pending. change - Build each command standalone under change/. + clean - Delete temporary files. + distclean - Delete everything that isn't shipped. + + install - Install toybox into bin/sbin subdirectories of $PREFIX + install_airlock - Install toybox and host toolchain (plus $TOOLCHAIN if any) + into $PREFIX directory (providing $PATH for hermetic builds) + install_flat - Install toybox into $PREFIX directory (no sudirs) + uninstall - Remove toybox from subdirectories of $PREFIX + uninstall_flat - Remove toybox from $PREFIX directory + test_COMMAND - Run tests for COMMAND (test_ps, test_cat, etc.) tests - Run test suite against all compiled commands. export TEST_HOST=1 to test host command, VERBOSE=all @@ -23,22 +37,11 @@ baseline - Create toybox_old for use by bloatcheck. bloatcheck - Report size differences between old and current versions - clean - Delete temporary files. - distclean - Delete everything that isn't shipped. - - install_airlock - Install toybox and host toolchain (plus $TOOLCHAIN if any) - into $PREFIX directory, providing $PATH for hermetic builds. - install_flat - Install toybox into $PREFIX directory. - install - Install toybox into subdirectories of $PREFIX. - uninstall_flat - Remove toybox from $PREFIX directory. - uninstall - Remove toybox from subdirectories of $PREFIX. - root - Build/package root filesystem under root/ by calling - mkroot/mkroot.sh which is controlled by + mkroot/mkroot.sh which is controlled by: CROSS= cross compile target (see scripts/mcm-buildall.sh) - LINUX= build kernel from this source as configured for qemu + LINUX= build kernel from this source (configured for qemu) run_root - boot toyroot under qemu by calling root/$CROSS/run-qemu.sh -example: make defconfig toybox install LDFLAGS="--static" CROSS_COMPILE=armv5l- +example: make defconfig toybox install LDFLAGS=--static CROSS_COMPILE=armv5l- or : make root run_root CROSS=sh4 LINUX=~/linux - diff --git a/scripts/kconfig.c b/scripts/kconfig.c index 5cf68641..c427780a 100644 --- a/scripts/kconfig.c +++ b/scripts/kconfig.c @@ -325,13 +325,14 @@ void read_dotconfig(struct kconfig *klist, FILE *fp) int main(int argc, char *argv[]) { struct kconfig *kc = read_Config("Config.in", 0), *kk, *kt; - char *ss = argv[1], *rr = "ndyrhmc", *tt, *esc = "\n\\\"", buf[64]; + char *ss = argv[1], *rr = "ndyrhmco", *tt, *esc = "\n\\\"", buf[64]; + struct scene { struct scene *next; char *seen; } *seen = 0, *sen; time_t t = time(0); unsigned type; FILE *fp; int ii, min, max; - if (argc!=2 || *ss!='-' || (!ss[1] || !(tt = strchr(rr, ss[1]),ss[1]))||ss[2]) + if (argc!=2 || *ss!='-' || (!ss[1] || !(tt = strchr(rr, ss[1]))||ss[2])) error_exit("Need -[%s]\n", rr); cfgtype = tt-rr; if (cfgtype>3) cfgtype = 1; // interactive config falls back to defconfig @@ -357,69 +358,95 @@ int main(int argc, char *argv[]) read_dotconfig(kc, fp); } - // menuconfig - if (*tt=='m') { + if (strchr("mco", *tt)) if ((fp = fopen(getenv("KCONFIG_CONFIG") ? : ".config", "r"))) read_dotconfig(kc, fp); - // TODO oldconfig, indent, hidden or dependency-forced symbols + // menuconfig + if (*tt=='m') printf("TODO: -m\n"); + + // TODO oldconfig // old style interactive config - } else if (*tt=='c') for (kk = kc; kk; kk = kk->next) { + else if (*tt=='c' || *tt=='o') for (rr = 0, kk = kc; kk; kk = kt) { + kt = kk->next; if (!kk->prompt || !*kk->prompt) continue; + + // Determine indentation level + while (seen && (!kk->depend || (strncmp(kk->depend, seen->seen, + ii = strcspn(kk->depend, " ")) || seen->seen[ii]))) + { + rr = (void *)seen; + seen = seen->next; + free(rr); + } + if (!depends(kc, kk)) continue; + if (*tt=='o') { + if (!strcmp(kk->type, "choice")) { + for (ii = 0; !strcmp(kt->type, "bool"); kt = kt->next) ii += !kt->value; + if (!ii) continue; + kt = kk->next; + } else if (kk->value) continue; + } + if (kk->symbol) { + rr = (void *)seen; + if (!(seen = malloc(sizeof(*seen)))) error_exit("malloc"); + seen->next = (void *)rr; + seen->seen = kk->symbol; + } + + // Display prompt if ((ii = strany(kk->type, (char *[]){"comment", "menu", 0}))) { - dprintf(2, (char *[]){"%s\n", "*\n%s\n*\n", 0}[ii-1], kk->prompt); + if (*tt!='o') + dprintf(2, (char *[]){"%s\n", "*\n%s\n*\n", 0}[ii-1], kk->prompt); continue; } if (!strcmp(kk->type, "choice")) { dprintf(2, "%s\n", kk->prompt ? : "ERROR"); if (!kk->def && !(kk->def = kk->next->symbol)) error_exit("tilt"); - for (ii = 0, kt = kk; (kt = kt->next) && !strcmp(kt->type, "bool");) + for (ii = 0; !strcmp(kt->type, "bool"); kt = kt->next) dprintf(2, "%c %d. %s\n", " >"[!strcmp(kk->def, kt->symbol)], ++ii, kt->prompt); min = 1; dprintf(2, "Choice [1-%d?]: ", max = ii); } else { if (!strcmp(kk->type, "bool")) - sprintf(tt = buf, "%s/?", (kk->def && *kk->def=='y') ? "Y/n" : "N/y"); + sprintf(rr = buf, "%s/?", value(kk) ? "Y/n" : "N/y"); else if (!strcmp(kk->type, "int")) { if (kk->min) sprintf(buf, "%d-%d:", min = atoi(kk->min), max = atoi(kk->max)); else min = 0, max = INT_MAX, *buf = 0; ii = min; if (kk->def) ii = atoi(kk->def); - sprintf((tt = buf)+strlen(buf), "%d", ii); - } else if (!strcmp(kk->type, "string")) tt = kk->def ? : ""; + sprintf((rr = buf)+strlen(buf), "%d", ii); + } else if (!strcmp(kk->type, "string")) rr = kk->def ? : ""; else continue; - dprintf(2, "%s (%s) [%s] ", kk->prompt, kk->symbol, tt); - } - dprintf(2, "\n"); - -/* - if (!(ss = kk->symbol)) continue; - 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') - printf("CONFIG_%s=\"%s\"\n", ss, kk->value ? : kk->def ? : ""); - else printf("CONFIG_%s=%d\n", ss, value(kk)); + for (ii = 0, sen = seen; sen; sen = sen->next) ii++; + dprintf(2, "% *s%s (%s) [%s] ", 2*(ii-1), "", kk->prompt, kk->symbol, rr); } - if (askcfg && !kk->value) { - val = value(kk); - sdef = kk->value ? : kk->def ? : ""; - sprintf(buf, "%c/%c/?", "Yy"[!val], "nN"[!val]); - if (ty=='i') sprintf(buf, "%d", val); - printf("%s (%s) [%s] ", kk->prompt, kk->symbol, ty=='s' ? sdef : buf); - -indentation for dependent symbols -blah (BLAH) [500] -Security Blanket -> 1. None (TOYBOX_LSM_NONE) - 2. SELinux support (TOYBOX_SELINUX) - 3. SMACK support (TOYBOX_SMACK) -choice[1-3?]: x -string (STRING) [string] -*/ + // Read input + if (!(rr = getrimline(stdin))) error_exit("abort"); + if (!*rr) { + free(rr); + continue; + } + if (*rr=='?') { + dprintf(2, "%s\n", kk->help); + kt = kk; + } else if (strchr("ci", *kk->type)) { + if (strcspn(rr+(*rr=='-'), "0123456789") || + (ii = atoi(rr))max) kt = kk; + else if (*kk->type=='i') bump(&kk->value, &rr); + else { + while (ii--) kk = kk->next; + set_val(kk, "y"); + } + } else if (*kk->type=='s') bump(&kk->value, &rr); + else if (strchr("yn", (*rr = tolower(*rr)))) { + rr[1] = 0; + bump(&kk->value, &rr); + } else kt = kk; + free(rr); } -- 2.39.5