; Kbuild runs the target compiler from the BusyBox source directory. The ; relative link keeps the sysroot's path out of make's split command words. selected-arch := get-environment-variable("VPAC_TARGET_ARCH") host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } target-arch := if string?(selected-arch) { selected-arch } else { host-arch } musl-build-dep := if string=?(target-arch, "aarch64") { "musl>=1.2.6-4" } else { "musl>=1.2.6-1" } cross-prefix := get-environment-variable("CROSS_COMPILE") prefix := if string?(cross-prefix) { cross-prefix } else { "" } target-cc := string-append("CC=", prefix, "gcc --sysroot=../vinix-sysroot -specs=../vinix-sysroot/usr/lib/musl-gcc-sysroot.specs") run-target := if string=?(host-arch, target-arch) { list() } else { list(string-append("qemu-", target-arch)) } ; Vinix's published Alpine 3.21 miniroot uses this exact aports revision. aports := "https://raw.githubusercontent.com/alpinelinux/aports/284d827a2793963e6dcf88324bd1eb81adff579c/main/busybox/" defpkgbuild(busybox, #:pkgname, "busybox", #:pkgver, "1.38.0", #:pkgrel, 5, #:pkgdesc, "Static shell and Unix utilities for the Vinix release", #:arch, [#:x86-64, #:aarch64], #:url, "https://busybox.net/", #:license, "GPL-2.0-only", #:depends, ["ssl-client"], #:makedepends, [musl-build-dep, "linux-headers"], #:backup, ["etc/securetty", "etc/udhcpc/udhcpc.conf", "etc/logrotate.d/acpid"], #:source, ["https://busybox.net/downloads/busybox-1.38.0.tar.bz2", string-append(aports, "busyboxconfig"), string-append(aports, "dad.if-up"), string-append(aports, "acpid.logrotate"), string-append(aports, "udhcpc.conf"), string-append(aports, "securetty"), string-append(aports, "default.script"), string-append(aports, "0009-properly-fix-wget-https-support.patch")], #:sha256sums, ["34f9ea6ff8636f2c9241153b9114eefa9e65674a45318ae1ef95bb5f31c53bb2", "72a2f2316d06fac2606cc9642018fc7377879c0b0241fc76aa6c9239c810bdf7", "2fd20d1bc67d9ee711990002b24f156635a73f56b8935b2f76592938817fa4e7", "d608a3b7715886b5735def0cc50a6359fd364fac2e0e0a459c588c04be471031", "5b372209e01cda07c87b8afa6d1ab3d7e8daf18a1f2332d744203a6dc289eb1a", "713fcea5109728883b9147e822429133fcc8b5e253afd3c2a197b10cd0bc3b4d", "c4e5a7c4783a7a73dec48dee009ee687015d2de7ff86b269679b95bef2c60e13", "4be0a9d28acaa4c117c694a4816fad4a2d3f78e224676dfc2d1407d3ad0dc17a"], #:prepare, fn() { root := get-environment-variable("VPAC_MAKEPKG_ROOT") if not(string?(root)) { display("Set VPAC_MAKEPKG_ROOT to the absolute path of the installed Vinix build root.") newline() run("false") } run("test", "-f", string-append(root, "/usr/lib/musl-gcc-sysroot.specs")) run("ln", "-s", root, "vinix-sysroot") run("patch", "--batch", "--fuzz=0", "-p1", "-d", "busybox-1.38.0", "-i", "../0009-properly-fix-wget-https-support.patch") run("cp", "busyboxconfig", "busybox-1.38.0/vinix.defconfig") run("sed", "-i", "-e", "s|^# CONFIG_STATIC is not set$|CONFIG_STATIC=y|", "-e", "s|^# CONFIG_INSTALL_APPLET_SYMLINKS is not set$|CONFIG_INSTALL_APPLET_SYMLINKS=y|", "-e", "s|^CONFIG_INSTALL_APPLET_DONT=y$|# CONFIG_INSTALL_APPLET_DONT is not set|", "-e", "$a # CONFIG_SSL_SERVER is not set", "-e", "s|^CONFIG_UNAME_OSNAME=.*|CONFIG_UNAME_OSNAME=\"Vinix\"|", "busybox-1.38.0/vinix.defconfig") run("make", "-C", "busybox-1.38.0", "KBUILD_DEFCONFIG=vinix.defconfig", "defconfig") for-each(fn(option) { run("grep", "-Fx", option, "busybox-1.38.0/.config") }, list("CONFIG_UNAME_OSNAME=\"Vinix\"", "CONFIG_STATIC=y", "CONFIG_RUN_PARTS=y", "CONFIG_FEATURE_USE_INITTAB=y", "CONFIG_FEATURE_WGET_HTTPS=y", "# CONFIG_SSL_CLIENT is not set", "# CONFIG_TLS is not set")) }, #:build, fn() { run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", "make", "-C", "busybox-1.38.0", target-cc, "busybox") }, #:check, fn() { ; Check what the final executable actually linked, and the dependencies ; emitted when compiling ash. Keep the proof in the build transcript. for-each(fn(file) { run("grep", "-Fx", string-append("LOAD ../vinix-sysroot/usr/lib/", file), "busybox-1.38.0/busybox_unstripped.map") }, list("Scrt1.o", "crti.o", "libc.a", "crtn.o")) run("grep", "-F", "../vinix-sysroot/usr/include/stdio.h", "busybox-1.38.0/shell/.ash.o.cmd") run("grep", "-F", "../vinix-sysroot/usr/include/linux/vt.h", "busybox-1.38.0/init/.init.o.cmd") apply(run, append(run-target, list("busybox-1.38.0/busybox", "ash", "-n", "/dev/null"))) apply(run, append(run-target, list("busybox-1.38.0/busybox", "true"))) }, #:package, fn() { run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", "make", "-C", "busybox-1.38.0", target-cc, string-append("CONFIG_PREFIX=", pkgdir()), "install") run("test", "-L", string-append(pkgdir(), "/bin/run-parts")) run("mkdir", "empty-hooks") apply(run, append(run-target, list(string-append(pkgdir(), "/bin/run-parts"), "--test", "empty-hooks"))) run("install", "-Dm644", "busybox-1.38.0/busybox.links", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) run("sed", "-i", "s|^/||", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) ; The desktop supplies its own PID 1. Bootstrap images install busybox-init. run("rm", string-append(pkgdir(), "/sbin/init")) run("sed", "-i", "\\|^sbin/init$|d", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) ; The release's bzip2, ncurses, binutils, xz and vim packages own these commands. ; The corresponding applets remain available through /bin/busybox. for-each(fn(name) { path := string-append("usr/bin/", name) run("test", "-L", string-append(pkgdir(), "/", path)) run("rm", string-append(pkgdir(), "/", path)) run("sed", "-i", string-append("\\|^", path, "$|d"), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) }, list("bunzip2", "bzcat", "bzip2", "clear", "reset", "strings", "lzcat", "lzma", "unlzma", "unxz", "xzcat", "xxd")) ; Alpine 3.21's nologin, cpio and vi applets use these paths. run("ln", "-s", "../bin/busybox", string-append(pkgdir(), "/sbin/nologin")) for-each(fn(name) { run("ln", "-s", "../../bin/busybox", string-append(pkgdir(), "/usr/bin/", name)) }, list("cpio", "vi")) for-each(fn(path) { run("sed", "-i", string-append("$a ", path), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) }, list("sbin/nologin", "usr/bin/cpio", "usr/bin/vi")) ; The published ARM root also exposes these applets under /bin. if string=?(target-arch, "aarch64") { for-each(fn(name) { run("test", "-L", string-append(pkgdir(), "/usr/bin/", name)) run("ln", "-s", "busybox", string-append(pkgdir(), "/bin/", name)) run("sed", "-i", string-append("$a bin/", name), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) }, list("awk", "basename", "cmp", "comm", "cut", "dirname", "du", "env", "expr", "find", "head", "id", "printf", "readlink", "seq", "sort", "tail", "tee", "tr", "uniq", "wc", "which", "whoami", "xargs")) } run("install", "-Dm644", "securetty", string-append(pkgdir(), "/etc/securetty")) run("install", "-Dm644", "udhcpc.conf", string-append(pkgdir(), "/etc/udhcpc/udhcpc.conf")) run("install", "-Dm644", "acpid.logrotate", string-append(pkgdir(), "/etc/logrotate.d/acpid")) run("install", "-Dm755", "default.script", string-append(pkgdir(), "/usr/share/udhcpc/default.script")) for-each(fn(dir) { run("install", "-d", string-append(pkgdir(), "/etc/network/", dir)) }, list("if-down.d", "if-post-down.d", "if-pre-down.d", "if-up.d", "if-post-up.d", "if-pre-up.d")) run("install", "-Dm775", "dad.if-up", string-append(pkgdir(), "/etc/network/if-up.d/dad")) run("install", "-Dm644", "busybox-1.38.0/LICENSE", string-append(pkgdir(), "/usr/share/licenses/busybox/LICENSE")) })