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