From 228cb983eb2850525b4488d0925b946ce17993f2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 11 Feb 2026 17:41:22 -0600 Subject: [PATCH] Simplify build dependencies, shrink Makefile, move more config plumbing over to new stuff, teach scripts/genconfig.sh to create .config files, add scripts/prereq/use.sh --- Makefile | 64 +++++++++++++++---------- kconfig/Makefile | 32 +++---------- {kconfig => scripts}/android_miniconfig | 0 {kconfig => scripts}/freebsd_miniconfig | 0 scripts/genconfig.sh | 2 + scripts/help.txt | 29 ++++++++--- scripts/kconfig.c | 4 +- {kconfig => scripts}/macos_miniconfig | 0 scripts/prereq/use.sh | 29 +++++++++++ scripts/recreate-prereq.sh | 11 +++-- 10 files changed, 106 insertions(+), 65 deletions(-) rename {kconfig => scripts}/android_miniconfig (100%) rename {kconfig => scripts}/freebsd_miniconfig (100%) rename {kconfig => scripts}/macos_miniconfig (100%) create mode 100755 scripts/prereq/use.sh diff --git a/Makefile b/Makefile index 52215300..61f728c2 100644 --- a/Makefile +++ b/Makefile @@ -1,51 +1,64 @@ -# Makefile for toybox. -# Copyright 2006 Rob Landley +# Simple makefile wrapper, see "make help". Mostly calls various build scripts: -# If people set these on the make command line, use 'em -# Note that CC defaults to "cc" so the one in configure doesn't get -# used when scripts/make.sh and such called through "make". - -HOSTCC?=cc +# scripts/make.sh - compile toybox +# scripts/install.sh - install toybox +# scripts/genconfig.sh - create/modify .config file +# scripts/test.sh - run tests against command(s) +# scripts/single.sh - build standalone command(s) +# scripts/change.sh - build all commands standalone +# mkroot/mkroot.sh - build self-contained test system bootable under qemu export CROSS_COMPILE CFLAGS OPTIMIZE LDOPTIMIZE CC HOSTCC V STRIP ASAN all: toybox -KCONFIG_CONFIG ?= .config -KCONFIG_TOP ?= Config.in +export KCONFIG_CONFIG ?= .config -toybox generated/unstripped/toybox: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/*.c scripts/*.sh Config.in +toybox generated/unstripped/toybox: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/*.c scripts/*.sh scripts/make.sh .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 \ + defconfig randconfig allyesconfig allnoconfig silentoldconfig \ + macos_defconfig bsd_defconfig android_defconfig + .SUFFIXES: # Disable legacy behavior include kconfig/Makefile -include .singlemake -$(KCONFIG_CONFIG): $(KCONFIG_TOP) - @if [ -e "$(KCONFIG_CONFIG)" ]; then $(MAKE) silentoldconfig; \ +$(KCONFIG_CONFIG): Config.in generated/Config.in + @if [ -e "$(KCONFIG_CONFIG)" ]; then \ + KCONFIG_ALLCONFIG=$(KCONFIG_CONFIG) scripts/genconfig.sh -d; \ else echo "Not configured (run '$(MAKE) defconfig' or '$(MAKE) menuconfig')";\ exit 1; fi -$(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 scripts/kconfig.c - scripts/genconfig.sh -defconfig: $(KCONFIG_TOP) generated/Config.in - generated/unstripped/kconfig -d > $(KCONFIG_CONFIG) +defconfig: + scripts/genconfig.sh -d + +randconfig: + scripts/genconfig.sh -r + +allyesconfig: + scripts/genconfig.sh -y + +allnoconfig: + scripts/genconfig.sh -n + +silentoldconfig: + KCONFIG_ALLCONFIG=$(KCONFIG_CONFIG) scripts/genconfig.sh -d -randconfig: $(KCONFIG_TOP) generated/Config.in - generated/unstripped/kconfig -r > $(KCONFIG_CONFIG) +macos_defconfig: + KCONFIG_ALLCONFIG=scripts/macos_miniconfig scripts/genconfig.sh -n -allyesconfig: $(KCONFIG_TOP) generated/Config.in - generated/unstripped/kconfig -y > $(KCONFIG_CONFIG) +bsd_defconfig: + KCONFIG_ALLCONFIG=scripts/bsd_miniconfig scripts/genconfig.sh -n -allnoconfig: $(KCONFIG_TOP) generated/Config.in - generated/unstripped/kconfig -n > $(KCONFIG_CONFIG) +android_defconfig: + KCONFIG_ALLCONFIG=scripts/android_miniconfig scripts/genconfig.sh -n # Development targets baseline: generated/unstripped/toybox @@ -79,6 +92,7 @@ root_clean: clean:: @chmod -fR 700 generated 2>/dev/null || true @rm -rf toybox generated change install .singleconfig* + @rm -rf prereq prereq.mini toybox-prereq @echo cleaned # If singlemake was in generated/ "make clean; make test_ls" wouldn't work. @@ -94,7 +108,7 @@ root: mkroot/mkroot.sh $(MAKEFLAGS) run_root: - cd root/"$${CROSS:-host}" && ./run-qemu.sh + root/"$${CROSS:-host}"/run-qemu.sh help:: @cat scripts/help.txt diff --git a/kconfig/Makefile b/kconfig/Makefile index 352a6021..1331434c 100644 --- a/kconfig/Makefile +++ b/kconfig/Makefile @@ -5,45 +5,25 @@ KCONFIG_TOP = Config.in KCONFIG_PROJECT = ToyBox obj = ./kconfig -PHONY += clean help oldconfig menuconfig config silentoldconfig +PHONY += clean help oldconfig menuconfig config 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) -silentoldconfig: $(obj)/conf $(KCONFIG_TOP) - yes '' | $< -o $(KCONFIG_TOP) > /dev/null - -KCONFIG_ALLCONFIG ?= /dev/null - -macos_defconfig: $(obj)/conf $(KCONFIG_TOP) - KCONFIG_ALLCONFIG=$(obj)/macos_miniconfig $< -n $(KCONFIG_TOP) > /dev/null - -bsd_defconfig: $(obj)/conf $(KCONFIG_TOP) - KCONFIG_ALLCONFIG=$(obj)/freebsd_miniconfig $< -n $(KCONFIG_TOP) > /dev/null - -android_defconfig: $(obj)/conf $(KCONFIG_TOP) - KCONFIG_ALLCONFIG=$(obj)/android_miniconfig $< -n $(KCONFIG_TOP) > /dev/null # 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' - @echo ' silentoldconfig - Same as oldconfig, but quietly' - @echo ' randconfig - New config with random answer to all options' - @echo ' allyesconfig - New config where all options are accepted with yes' - @echo " This may not actually compile, it's a starting point" - @echo ' for further configuration (probably with menuconfig)' - @echo ' allnoconfig - New config where all options are answered with no' - @echo ' (NOP binary, starting point for further configuration)' - @echo ' macos_defconfig - Select commands known to build on macosx' - @echo ' bsd_defconfig - Select commands known to build on freebsd' - @echo ' android_defconfig - Select commands available on android' # Cheesy build @@ -55,12 +35,12 @@ SHIPPED = kconfig/zconf.tab.c kconfig/lex.zconf.c kconfig/zconf.hash.c gen_config.h: .config kconfig/mconf: $(SHIPPED) - $(HOSTCC) -o $@ kconfig/mconf.c kconfig/zconf.tab.c \ + cc -o $@ kconfig/mconf.c kconfig/zconf.tab.c \ kconfig/lxdialog/*.c -lcurses -DCURSES_LOC="" \ -DKBUILD_NO_NLS=1 -DPROJECT_NAME=\"$(KCONFIG_PROJECT)\" kconfig/conf: $(SHIPPED) - $(HOSTCC) -o $@ kconfig/conf.c kconfig/zconf.tab.c -DKBUILD_NO_NLS=1 \ + cc -o $@ kconfig/conf.c kconfig/zconf.tab.c -DKBUILD_NO_NLS=1 \ -DPROJECT_NAME=\"$(KCONFIG_PROJECT)\" clean:: diff --git a/kconfig/android_miniconfig b/scripts/android_miniconfig similarity index 100% rename from kconfig/android_miniconfig rename to scripts/android_miniconfig diff --git a/kconfig/freebsd_miniconfig b/scripts/freebsd_miniconfig similarity index 100% rename from kconfig/freebsd_miniconfig rename to scripts/freebsd_miniconfig diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index a1c6e2b5..1e0ac798 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -94,3 +94,5 @@ echo -e ".PHONY: $WORKING $PENDING" | $SED 's/ \([^ ]\)/ test_\1/g' ) > .singlemake brun kconfig -h > "$GENDIR"/help.h || exit 1 + +[ $# -ne 1 ] || brun kconfig "$1" > "${KCONFIG_CONFIG:-.config}" diff --git a/scripts/help.txt b/scripts/help.txt index 77245074..fd6d1f8d 100644 --- a/scripts/help.txt +++ b/scripts/help.txt @@ -1,28 +1,43 @@ toybox - Build unified toybox with commands selected in .config - defconfig - Write .config with default answers (max sane 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 + 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 + COMMANDNAME - Build individual toybox command as a standalone binary. list - List COMMANDNAMEs you can build standalone. list_example - List example commands (often used by the test suite) list_pending - List unfinished COMMANDNAMEs out of toys/pending. change - Build each command standalone under change/. - baseline - Create toybox_old for use by bloatcheck. - bloatcheck - Report size differences between old and current versions + 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 to show all failures. + 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/ controlled by - CROSS= cross compile (see scripts/mcm-buildall.sh) - LINUX= build kernel from this source, configured for qemu - run_root - boot toyroot under qemu, I.E. cd root/$CROSS && ./qemu-*.sh + + root - Build/package root filesystem under root/ by calling + 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 + run_root - boot toyroot under qemu by calling root/$CROSS/run-qemu.sh 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 9c269754..c7e49a92 100644 --- a/scripts/kconfig.c +++ b/scripts/kconfig.c @@ -191,7 +191,7 @@ int value(struct kconfig *kc) if (*kc->type!='b') return atoi(s); if (kc->value) return *kc->value=='y'; if (cfgtype==1 || !*kc->prompt) return *s=='y'; - if (cfgtype==4) return random()&1; + if (cfgtype==3) return random()&1; return !!cfgtype; } @@ -312,7 +312,7 @@ void options(char *opt) // TODO if ((fp = fopen(getenv("KCONFIG_CONFIG") ? : ".config"))) // read_dotconfig(kc, fp); - if (-1 != (cfgtype = strany(opt, (char *[]){"-n", "-d", "-y", 0})-1)) { + if (-1 != (cfgtype = strany(opt, (char *[]){"-n", "-d", "-y", "-r", 0})-1)) { time_t t = time(0); struct tm *tt = localtime(&t); char buf[64]; diff --git a/kconfig/macos_miniconfig b/scripts/macos_miniconfig similarity index 100% rename from kconfig/macos_miniconfig rename to scripts/macos_miniconfig diff --git a/scripts/prereq/use.sh b/scripts/prereq/use.sh new file mode 100755 index 00000000..1abc8b24 --- /dev/null +++ b/scripts/prereq/use.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# usage: use.sh [miniconfig] + +# Hermetic build using toybox-prereq, optionally using a miniconfig + +if [ ! -x toybox-prereq ] +then + echo building toybox-prereq + scripts/prereq/build.sh || exit 1 +fi + +# Install prerequisites into subdir and prepend to path +rm -rf prereq && mkdir -p prereq && cp toybox-prereq prereq/toybox && +for i in $(prereq/toybox); do ln -sf toybox prereq/$i; done && +export PATH="$PWD/prereq:$PATH" && + +# Are we using a miniconfig? +if [ -z "$1" ] +then + ARG=-d +else + ARG=-n + export KCONFIG_ALLCONFIG="$1" +fi + +# Run configure and build +scripts/genconfig.sh $ARG && +scripts/make.sh diff --git a/scripts/recreate-prereq.sh b/scripts/recreate-prereq.sh index 84228ad3..86891d87 100755 --- a/scripts/recreate-prereq.sh +++ b/scripts/recreate-prereq.sh @@ -16,16 +16,17 @@ CMDLIST="$(echo toybox; echo ln; ./toybox cut -DF 1 log.txt | sort -u | grep -v # Create minimal dependency-free build -make clean allnoconfig KCONFIG_ALLCONFIG=prereq.mini -make toybox -cat > scripts/prereq/build.sh << 'EOF' +make clean allnoconfig KCONFIG_ALLCONFIG=prereq.mini && +make toybox && +cat > scripts/prereq/build.sh << 'EOF' && #!/bin/sh BUILD='cc -funsigned-char -I scripts/prereq -I . -Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing -DTOYBOX_VERSION=""' LINK='' EOF -grep -A999 FILES= generated/build.sh >> scripts/prereq/build.sh -sed -i 's/ toybox$/&-prereq/' scripts/prereq/build.sh +grep -A999 FILES= generated/build.sh >> scripts/prereq/build.sh && +sed -i 's/ toybox$/&-prereq/' scripts/prereq/build.sh && +chmod +x scripts/prereq/build.sh || exit 1 # harvest stripped down headers -- 2.39.5