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