Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | SUMMARY = "Toybox combines common utilities together into a single executable." |
| 2 | HOMEPAGE = "http://www.landley.net/toybox/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 3 | DEPENDS = "attr virtual/crypt" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 4 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 5 | LICENSE = "0BSD" |
Andrew Geissler | 2ee498a | 2020-05-29 15:52:06 -0500 | [diff] [blame] | 6 | LIC_FILES_CHKSUM = "file://LICENSE;md5=78659a599b9325da368f2f1eb88f19c7" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 7 | |
Brad Bishop | ba6de43 | 2019-05-21 08:07:33 -0400 | [diff] [blame] | 8 | inherit cml1 update-alternatives |
| 9 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 10 | SRC_URI = "http://www.landley.net/toybox/downloads/${BPN}-${PV}.tar.gz \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 11 | " |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 12 | SRC_URI[sha256sum] = "b508bf336f82cb0739b77111f945931d1a143b5a53905cb753cd2607cfdd1494" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 13 | |
| 14 | SECTION = "base" |
| 15 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 16 | RDEPENDS:${PN} = "${@["", "toybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'toybox')]}" |
Andrew Geissler | 89770b0 | 2020-06-13 10:40:47 -0500 | [diff] [blame] | 17 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 18 | TOYBOX_BIN = "generated/unstripped/toybox" |
| 19 | |
Andrew Geissler | 2ee498a | 2020-05-29 15:52:06 -0500 | [diff] [blame] | 20 | # Toybox is strict on what CC, CFLAGS and CROSS_COMPILE variables should contain. |
| 21 | # Fix CC, CFLAGS, CROSS_COMPILE to match expectations. |
| 22 | # CC = compiler name |
| 23 | # CFLAGS = only compiler flags |
| 24 | # CROSS_COMPILE = compiler prefix |
| 25 | CFLAGS += "${TOOLCHAIN_OPTIONS} ${TUNE_CCARGS}" |
| 26 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 27 | COMPILER:toolchain-clang = "clang" |
Andrew Geissler | 2ee498a | 2020-05-29 15:52:06 -0500 | [diff] [blame] | 28 | COMPILER ?= "gcc" |
| 29 | |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 30 | PACKAGECONFIG ??= "no-iconv no-getconf" |
| 31 | |
| 32 | PACKAGECONFIG[no-iconv] = ",," |
| 33 | PACKAGECONFIG[no-getconf] = ",," |
| 34 | |
Andrew Geissler | 2ee498a | 2020-05-29 15:52:06 -0500 | [diff] [blame] | 35 | EXTRA_OEMAKE = 'CROSS_COMPILE="${HOST_PREFIX}" \ |
| 36 | CC="${COMPILER}" \ |
| 37 | STRIP="strip" \ |
| 38 | CFLAGS="${CFLAGS}" \ |
| 39 | HOSTCC="${BUILD_CC}" CPUS=${@oe.utils.cpu_count()} V=1' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 40 | |
| 41 | do_configure() { |
Andrew Geissler | 7f40b71 | 2020-05-15 14:09:53 -0500 | [diff] [blame] | 42 | # allow user to define their own defconfig in bbappend, taken from kernel.bbclass |
| 43 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then |
| 44 | mv "${S}/.config" "${B}/.config" |
| 45 | fi |
| 46 | |
| 47 | # Copy defconfig to .config if .config does not exist. This allows |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 48 | # recipes to manage the .config themselves in do_configure:prepend(). |
Andrew Geissler | 7f40b71 | 2020-05-15 14:09:53 -0500 | [diff] [blame] | 49 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then |
| 50 | cp "${WORKDIR}/defconfig" "${B}/.config" |
| 51 | fi |
| 52 | |
| 53 | oe_runmake oldconfig || oe_runmake defconfig |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 54 | |
| 55 | # Disable killall5 as it isn't managed by update-alternatives |
| 56 | sed -e 's/CONFIG_KILLALL5=y/# CONFIG_KILLALL5 is not set/' -i .config |
| 57 | |
| 58 | # Disable swapon as it doesn't handle the '-a' argument used during boot |
| 59 | sed -e 's/CONFIG_SWAPON=y/# CONFIG_SWAPON is not set/' -i .config |
Andrew Geissler | 89770b0 | 2020-06-13 10:40:47 -0500 | [diff] [blame] | 60 | |
| 61 | # Enable init if toybox was set as init manager |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 62 | if ${@bb.utils.contains('VIRTUAL-RUNTIME_init_manager','toybox','true','false',d)}; then |
Andrew Geissler | 89770b0 | 2020-06-13 10:40:47 -0500 | [diff] [blame] | 63 | sed -e 's/# CONFIG_INIT is not set/CONFIG_INIT=y/' -i .config |
| 64 | fi |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | do_compile() { |
| 68 | oe_runmake ${TOYBOX_BIN} |
| 69 | |
| 70 | # Create a list of links needed |
| 71 | ${BUILD_CC} -I . scripts/install.c -o generated/instlist |
| 72 | ./generated/instlist long | sed -e 's#^#/#' > toybox.links |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 73 | if ${@bb.utils.contains('PACKAGECONFIG','no-iconv','true','false',d)}; then |
| 74 | sed -i -e '/iconv$/d' toybox.links |
| 75 | fi |
| 76 | if ${@bb.utils.contains('PACKAGECONFIG','no-getconf','true','false',d)}; then |
| 77 | sed -i -e '/getconf$/d' toybox.links |
| 78 | fi |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | do_install() { |
| 82 | # Install manually instead of using 'make install' |
| 83 | install -d ${D}${base_bindir} |
| 84 | if grep -q "CONFIG_TOYBOX_SUID=y" ${B}/.config; then |
| 85 | install -m 4755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox |
| 86 | else |
| 87 | install -m 0755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox |
| 88 | fi |
| 89 | |
| 90 | install -d ${D}${sysconfdir} |
| 91 | install -m 0644 ${B}/toybox.links ${D}${sysconfdir} |
| 92 | } |
| 93 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 94 | # If you've chosen to install toybox you probably want it to take precedence |
| 95 | # over busybox where possible but not over other packages |
| 96 | ALTERNATIVE_PRIORITY = "60" |
| 97 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 98 | python do_package:prepend () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 99 | # Read links from /etc/toybox.links and create appropriate |
| 100 | # update-alternatives variables |
| 101 | |
| 102 | dvar = d.getVar('D') |
| 103 | pn = d.getVar('PN') |
Andrew Geissler | 1548c07 | 2019-02-22 16:03:50 -0600 | [diff] [blame] | 104 | target = d.expand("${base_bindir}/toybox") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 105 | |
| 106 | f = open('%s/etc/toybox.links' % (dvar), 'r') |
| 107 | for alt_link_name in f: |
| 108 | alt_link_name = alt_link_name.strip() |
| 109 | alt_name = os.path.basename(alt_link_name) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 110 | d.appendVar('ALTERNATIVE:%s' % (pn), ' ' + alt_name) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 111 | d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name) |
| 112 | d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target) |
| 113 | f.close() |
| 114 | } |