; 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-3" } 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)) } defpkgbuild(busybox-bootstrap, #:pkgname, "busybox-bootstrap", #:pkgver, "1.38.0", #:pkgrel, 1, #:pkgdesc, "Static musl shell and bootstrap utilities for Vinix", #:arch, [#:x86-64, #:aarch64], #:url, "https://busybox.net/", #:license, "GPL-2.0-only", #:conflicts, ["busybox"], #:makedepends, [musl-build-dep, "linux-headers"], #:source, ["https://busybox.net/downloads/busybox-1.38.0.tar.bz2", "bootstrap.config"], #:sha256sums, ["34f9ea6ff8636f2c9241153b9114eefa9e65674a45318ae1ef95bb5f31c53bb2", "9d8c4fb8ebad6ddbf058e151d807a90ce7687643626e0e4b5357e587718dec00"], #: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") ; Start with everything disabled. BusyBox allnoconfig overrides explicit ; KCONFIG_ALLCONFIG selections, so enable the selected options afterwards. run("make", "-C", "busybox-1.38.0", "allnoconfig") run("cp", "bootstrap.config", "enable.sed") run("sed", "-i", "-e", "/^#/d", "-e", "s/^\\(CONFIG_[A-Z0-9_]*\\)=y$/s|^# \\1 is not set$|\\1=y|/", "enable.sed") run("cp", "busybox-1.38.0/.config", "busybox-1.38.0/vinix.defconfig") run("sed", "-i", "-f", "enable.sed", "busybox-1.38.0/vinix.defconfig") run("make", "-C", "busybox-1.38.0", "KBUILD_DEFCONFIG=vinix.defconfig", "defconfig") run("sed", "-i", "s|^CONFIG_UNAME_OSNAME=.*|CONFIG_UNAME_OSNAME=\"Vinix\"|", "busybox-1.38.0/.config") run("grep", "-Fx", "CONFIG_UNAME_OSNAME=\"Vinix\"", "busybox-1.38.0/.config") }, #: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("install", "-Dm644", "busybox-1.38.0/LICENSE", string-append(pkgdir(), "/usr/share/licenses/busybox-bootstrap/LICENSE")) })