vinix-ports / busybox / PKGBUILD.vile
68 lines · 65 sloc · 3.65 KB · 303760f602f6aca9f6fdd77feebe81bdd3255865
Raw
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.
3selected-arch := get-environment-variable("VPAC_TARGET_ARCH")
4host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" }
5target-arch := if string?(selected-arch) { selected-arch } else { host-arch }
6cross-prefix := get-environment-variable("CROSS_COMPILE")
7prefix := if string?(cross-prefix) { cross-prefix } else { "" }
8target-cc := string-append("CC=", prefix, "gcc --sysroot=../vinix-sysroot -specs=../vinix-sysroot/usr/lib/musl-gcc-sysroot.specs")
9run-target := if string=?(host-arch, target-arch) { list() } else { list(string-append("qemu-", target-arch)) }
10
11defpkgbuild(busybox,
12 #:pkgname, "busybox",
13 #:pkgver, "1.38.0",
14 #:pkgrel, 4,
15 #:pkgdesc, "Static musl shell and bootstrap utilities for Vinix",
16 #:arch, [#:x86-64, #:aarch64],
17 #:url, "https://busybox.net/",
18 #:license, "GPL-2.0-only",
19 #:makedepends, ["musl=1.2.6-1", "linux-headers"],
20 #:source, ["https://busybox.net/downloads/busybox-1.38.0.tar.bz2", "bootstrap.config"],
21 #:sha256sums, ["34f9ea6ff8636f2c9241153b9114eefa9e65674a45318ae1ef95bb5f31c53bb2",
22 "9d8c4fb8ebad6ddbf058e151d807a90ce7687643626e0e4b5357e587718dec00"],
23
24 #:prepare, fn() {
25 root := get-environment-variable("VPAC_MAKEPKG_ROOT")
26 if not(string?(root)) {
27 display("Set VPAC_MAKEPKG_ROOT to the absolute path of the installed Vinix build root.")
28 newline()
29 run("false")
30 }
31 run("test", "-f", string-append(root, "/usr/lib/musl-gcc-sysroot.specs"))
32 run("ln", "-s", root, "vinix-sysroot")
33
34 ; Start with everything disabled. BusyBox allnoconfig overrides explicit
35 ; KCONFIG_ALLCONFIG selections, so enable the selected options afterwards.
36 run("make", "-C", "busybox-1.38.0", "allnoconfig")
37 run("cp", "bootstrap.config", "enable.sed")
38 run("sed", "-i", "-e", "/^#/d", "-e",
39 "s/^\\(CONFIG_[A-Z0-9_]*\\)=y$/s|^# \\1 is not set$|\\1=y|/", "enable.sed")
40 run("cp", "busybox-1.38.0/.config", "busybox-1.38.0/vinix.defconfig")
41 run("sed", "-i", "-f", "enable.sed", "busybox-1.38.0/vinix.defconfig")
42 run("make", "-C", "busybox-1.38.0", "KBUILD_DEFCONFIG=vinix.defconfig", "defconfig")
43 run("sed", "-i", "s|^CONFIG_UNAME_OSNAME=.*|CONFIG_UNAME_OSNAME=\"Vinix\"|", "busybox-1.38.0/.config")
44 run("grep", "-Fx", "CONFIG_UNAME_OSNAME=\"Vinix\"", "busybox-1.38.0/.config")
45 },
46 #:build, fn() {
47 run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH",
48 "make", "-C", "busybox-1.38.0", target-cc, "busybox")
49 },
50 #:check, fn() {
51 ; Check what the final executable actually linked, and the dependencies
52 ; emitted when compiling ash. Keep the proof in the build transcript.
53 for-each(fn(file) {
54 run("grep", "-Fx", string-append("LOAD ../vinix-sysroot/usr/lib/", file),
55 "busybox-1.38.0/busybox_unstripped.map")
56 }, list("Scrt1.o", "crti.o", "libc.a", "crtn.o"))
57 run("grep", "-F", "../vinix-sysroot/usr/include/stdio.h", "busybox-1.38.0/shell/.ash.o.cmd")
58 run("grep", "-F", "../vinix-sysroot/usr/include/linux/vt.h", "busybox-1.38.0/init/.init.o.cmd")
59 apply(run, append(run-target, list("busybox-1.38.0/busybox", "ash", "-n", "/dev/null")))
60 apply(run, append(run-target, list("busybox-1.38.0/busybox", "true")))
61 },
62 #:package, fn() {
63 run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH",
64 "make", "-C", "busybox-1.38.0", target-cc,
65 string-append("CONFIG_PREFIX=", pkgdir()), "install")
66 run("install", "-Dm644", "busybox-1.38.0/LICENSE",
67 string-append(pkgdir(), "/usr/share/licenses/busybox/LICENSE"))
68 })
69