| 1 | ; Kbuild runs the target compiler from the BusyBox source directory. The |
| 2 | ; relative link keeps the sysroot's path out of make's split command words. |
| 3 | selected-arch := get-environment-variable("VPAC_TARGET_ARCH") |
| 4 | host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } |
| 5 | target-arch := if string?(selected-arch) { selected-arch } else { host-arch } |
| 6 | musl-build-dep := if string=?(target-arch, "aarch64") { "musl>=1.2.6-4" } else { "musl>=1.2.6-1" } |
| 7 | cross-prefix := get-environment-variable("CROSS_COMPILE") |
| 8 | prefix := if string?(cross-prefix) { cross-prefix } else { "" } |
| 9 | target-cc := string-append("CC=", prefix, "gcc --sysroot=../vinix-sysroot -specs=../vinix-sysroot/usr/lib/musl-gcc-sysroot.specs") |
| 10 | run-target := if string=?(host-arch, target-arch) { list() } else { list(string-append("qemu-", target-arch)) } |
| 11 | ; Vinix's published Alpine 3.21 miniroot uses this exact aports revision. |
| 12 | aports := "https://raw.githubusercontent.com/alpinelinux/aports/284d827a2793963e6dcf88324bd1eb81adff579c/main/busybox/" |
| 13 | |
| 14 | defpkgbuild(busybox, |
| 15 | #:pkgname, "busybox", |
| 16 | #:pkgver, "1.38.0", |
| 17 | #:pkgrel, 5, |
| 18 | #:pkgdesc, "Static shell and Unix utilities for the Vinix release", |
| 19 | #:arch, [#:x86-64, #:aarch64], |
| 20 | #:url, "https://busybox.net/", |
| 21 | #:license, "GPL-2.0-only", |
| 22 | #:depends, ["ssl-client"], |
| 23 | #:makedepends, [musl-build-dep, "linux-headers"], |
| 24 | #:backup, ["etc/securetty", "etc/udhcpc/udhcpc.conf", "etc/logrotate.d/acpid"], |
| 25 | #:source, ["https://busybox.net/downloads/busybox-1.38.0.tar.bz2", string-append(aports, "busyboxconfig"), |
| 26 | string-append(aports, "dad.if-up"), string-append(aports, "acpid.logrotate"), |
| 27 | string-append(aports, "udhcpc.conf"), string-append(aports, "securetty"), string-append(aports, "default.script"), |
| 28 | string-append(aports, "0009-properly-fix-wget-https-support.patch")], |
| 29 | #:sha256sums, ["34f9ea6ff8636f2c9241153b9114eefa9e65674a45318ae1ef95bb5f31c53bb2", |
| 30 | "72a2f2316d06fac2606cc9642018fc7377879c0b0241fc76aa6c9239c810bdf7", |
| 31 | "2fd20d1bc67d9ee711990002b24f156635a73f56b8935b2f76592938817fa4e7", |
| 32 | "d608a3b7715886b5735def0cc50a6359fd364fac2e0e0a459c588c04be471031", |
| 33 | "5b372209e01cda07c87b8afa6d1ab3d7e8daf18a1f2332d744203a6dc289eb1a", |
| 34 | "713fcea5109728883b9147e822429133fcc8b5e253afd3c2a197b10cd0bc3b4d", |
| 35 | "c4e5a7c4783a7a73dec48dee009ee687015d2de7ff86b269679b95bef2c60e13", |
| 36 | "4be0a9d28acaa4c117c694a4816fad4a2d3f78e224676dfc2d1407d3ad0dc17a"], |
| 37 | |
| 38 | #:prepare, fn() { |
| 39 | root := get-environment-variable("VPAC_MAKEPKG_ROOT") |
| 40 | if not(string?(root)) { |
| 41 | display("Set VPAC_MAKEPKG_ROOT to the absolute path of the installed Vinix build root.") |
| 42 | newline() |
| 43 | run("false") |
| 44 | } |
| 45 | run("test", "-f", string-append(root, "/usr/lib/musl-gcc-sysroot.specs")) |
| 46 | run("ln", "-s", root, "vinix-sysroot") |
| 47 | |
| 48 | run("patch", "--batch", "--fuzz=0", "-p1", "-d", "busybox-1.38.0", "-i", "../0009-properly-fix-wget-https-support.patch") |
| 49 | run("cp", "busyboxconfig", "busybox-1.38.0/vinix.defconfig") |
| 50 | run("sed", "-i", "-e", "s|^# CONFIG_STATIC is not set$|CONFIG_STATIC=y|", |
| 51 | "-e", "s|^# CONFIG_INSTALL_APPLET_SYMLINKS is not set$|CONFIG_INSTALL_APPLET_SYMLINKS=y|", |
| 52 | "-e", "s|^CONFIG_INSTALL_APPLET_DONT=y$|# CONFIG_INSTALL_APPLET_DONT is not set|", |
| 53 | "-e", "$a # CONFIG_SSL_SERVER is not set", |
| 54 | "-e", "s|^CONFIG_UNAME_OSNAME=.*|CONFIG_UNAME_OSNAME=\"Vinix\"|", "busybox-1.38.0/vinix.defconfig") |
| 55 | run("make", "-C", "busybox-1.38.0", "KBUILD_DEFCONFIG=vinix.defconfig", "defconfig") |
| 56 | for-each(fn(option) { run("grep", "-Fx", option, "busybox-1.38.0/.config") }, |
| 57 | list("CONFIG_UNAME_OSNAME=\"Vinix\"", "CONFIG_STATIC=y", "CONFIG_RUN_PARTS=y", "CONFIG_FEATURE_USE_INITTAB=y", |
| 58 | "CONFIG_FEATURE_WGET_HTTPS=y", "# CONFIG_SSL_CLIENT is not set", "# CONFIG_TLS is not set")) |
| 59 | }, |
| 60 | #:build, fn() { |
| 61 | run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", |
| 62 | "make", "-C", "busybox-1.38.0", target-cc, "busybox") |
| 63 | }, |
| 64 | #:check, fn() { |
| 65 | ; Check what the final executable actually linked, and the dependencies |
| 66 | ; emitted when compiling ash. Keep the proof in the build transcript. |
| 67 | for-each(fn(file) { |
| 68 | run("grep", "-Fx", string-append("LOAD ../vinix-sysroot/usr/lib/", file), |
| 69 | "busybox-1.38.0/busybox_unstripped.map") |
| 70 | }, list("Scrt1.o", "crti.o", "libc.a", "crtn.o")) |
| 71 | run("grep", "-F", "../vinix-sysroot/usr/include/stdio.h", "busybox-1.38.0/shell/.ash.o.cmd") |
| 72 | run("grep", "-F", "../vinix-sysroot/usr/include/linux/vt.h", "busybox-1.38.0/init/.init.o.cmd") |
| 73 | apply(run, append(run-target, list("busybox-1.38.0/busybox", "ash", "-n", "/dev/null"))) |
| 74 | apply(run, append(run-target, list("busybox-1.38.0/busybox", "true"))) |
| 75 | }, |
| 76 | #:package, fn() { |
| 77 | run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", |
| 78 | "make", "-C", "busybox-1.38.0", target-cc, |
| 79 | string-append("CONFIG_PREFIX=", pkgdir()), "install") |
| 80 | run("test", "-L", string-append(pkgdir(), "/bin/run-parts")) |
| 81 | run("mkdir", "empty-hooks") |
| 82 | apply(run, append(run-target, list(string-append(pkgdir(), "/bin/run-parts"), "--test", "empty-hooks"))) |
| 83 | run("install", "-Dm644", "busybox-1.38.0/busybox.links", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 84 | run("sed", "-i", "s|^/||", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 85 | ; The desktop supplies its own PID 1. Bootstrap images install busybox-init. |
| 86 | run("rm", string-append(pkgdir(), "/sbin/init")) |
| 87 | run("sed", "-i", "\\|^sbin/init$|d", string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 88 | ; The release's bzip2, ncurses, binutils, xz and vim packages own these commands. |
| 89 | ; The corresponding applets remain available through /bin/busybox. |
| 90 | for-each(fn(name) { |
| 91 | path := string-append("usr/bin/", name) |
| 92 | run("test", "-L", string-append(pkgdir(), "/", path)) |
| 93 | run("rm", string-append(pkgdir(), "/", path)) |
| 94 | run("sed", "-i", string-append("\\|^", path, "$|d"), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 95 | }, list("bunzip2", "bzcat", "bzip2", "clear", "reset", "strings", "lzcat", "lzma", "unlzma", "unxz", "xzcat", "xxd")) |
| 96 | ; Alpine 3.21's nologin, cpio and vi applets use these paths. |
| 97 | run("ln", "-s", "../bin/busybox", string-append(pkgdir(), "/sbin/nologin")) |
| 98 | for-each(fn(name) { |
| 99 | run("ln", "-s", "../../bin/busybox", string-append(pkgdir(), "/usr/bin/", name)) |
| 100 | }, list("cpio", "vi")) |
| 101 | for-each(fn(path) { |
| 102 | run("sed", "-i", string-append("$a ", path), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 103 | }, list("sbin/nologin", "usr/bin/cpio", "usr/bin/vi")) |
| 104 | ; The published ARM root also exposes these applets under /bin. |
| 105 | if string=?(target-arch, "aarch64") { |
| 106 | for-each(fn(name) { |
| 107 | run("test", "-L", string-append(pkgdir(), "/usr/bin/", name)) |
| 108 | run("ln", "-s", "busybox", string-append(pkgdir(), "/bin/", name)) |
| 109 | run("sed", "-i", string-append("$a bin/", name), string-append(pkgdir(), "/etc/busybox-paths.d/busybox")) |
| 110 | }, list("awk", "basename", "cmp", "comm", "cut", "dirname", "du", "env", "expr", "find", "head", "id", |
| 111 | "printf", "readlink", "seq", "sort", "tail", "tee", "tr", "uniq", "wc", "which", "whoami", "xargs")) |
| 112 | } |
| 113 | run("install", "-Dm644", "securetty", string-append(pkgdir(), "/etc/securetty")) |
| 114 | run("install", "-Dm644", "udhcpc.conf", string-append(pkgdir(), "/etc/udhcpc/udhcpc.conf")) |
| 115 | run("install", "-Dm644", "acpid.logrotate", string-append(pkgdir(), "/etc/logrotate.d/acpid")) |
| 116 | run("install", "-Dm755", "default.script", string-append(pkgdir(), "/usr/share/udhcpc/default.script")) |
| 117 | for-each(fn(dir) { run("install", "-d", string-append(pkgdir(), "/etc/network/", dir)) }, |
| 118 | list("if-down.d", "if-post-down.d", "if-pre-down.d", "if-up.d", "if-post-up.d", "if-pre-up.d")) |
| 119 | run("install", "-Dm775", "dad.if-up", string-append(pkgdir(), "/etc/network/if-up.d/dad")) |
| 120 | run("install", "-Dm644", "busybox-1.38.0/LICENSE", |
| 121 | string-append(pkgdir(), "/usr/share/licenses/busybox/LICENSE")) |
| 122 | }) |
| 123 | |