blob: 34415680050f82b41f3d7eb8f9f96214f92ebb18 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001SUMMARY = "Toybox combines common utilities together into a single executable."
2HOMEPAGE = "http://www.landley.net/toybox/"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003DEPENDS = "attr virtual/crypt"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004
Andrew Geissler9aee5002022-03-30 16:27:02 +00005LICENSE = "0BSD"
Andrew Geissler2ee498a2020-05-29 15:52:06 -05006LIC_FILES_CHKSUM = "file://LICENSE;md5=78659a599b9325da368f2f1eb88f19c7"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007
Brad Bishopba6de432019-05-21 08:07:33 -04008inherit cml1 update-alternatives
9
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080010SRC_URI = "http://www.landley.net/toybox/downloads/${BPN}-${PV}.tar.gz \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011 "
Andrew Geisslerd5838332022-05-27 11:33:10 -050012SRC_URI[sha256sum] = "b508bf336f82cb0739b77111f945931d1a143b5a53905cb753cd2607cfdd1494"
Brad Bishop316dfdd2018-06-25 12:45:53 -040013
14SECTION = "base"
15
Patrick Williams213cb262021-08-07 19:21:33 -050016RDEPENDS:${PN} = "${@["", "toybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'toybox')]}"
Andrew Geissler89770b02020-06-13 10:40:47 -050017
Brad Bishop316dfdd2018-06-25 12:45:53 -040018TOYBOX_BIN = "generated/unstripped/toybox"
19
Andrew Geissler2ee498a2020-05-29 15:52:06 -050020# 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
25CFLAGS += "${TOOLCHAIN_OPTIONS} ${TUNE_CCARGS}"
26
Patrick Williams213cb262021-08-07 19:21:33 -050027COMPILER:toolchain-clang = "clang"
Andrew Geissler2ee498a2020-05-29 15:52:06 -050028COMPILER ?= "gcc"
29
Andrew Geisslerd688a012020-09-18 13:36:00 -050030PACKAGECONFIG ??= "no-iconv no-getconf"
31
32PACKAGECONFIG[no-iconv] = ",,"
33PACKAGECONFIG[no-getconf] = ",,"
34
Andrew Geissler2ee498a2020-05-29 15:52:06 -050035EXTRA_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 Bishop316dfdd2018-06-25 12:45:53 -040040
41do_configure() {
Andrew Geissler7f40b712020-05-15 14:09:53 -050042 # 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 Williams213cb262021-08-07 19:21:33 -050048 # recipes to manage the .config themselves in do_configure:prepend().
Andrew Geissler7f40b712020-05-15 14:09:53 -050049 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 Bishop316dfdd2018-06-25 12:45:53 -040054
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 Geissler89770b02020-06-13 10:40:47 -050060
61 # Enable init if toybox was set as init manager
Andrew Geisslerd688a012020-09-18 13:36:00 -050062 if ${@bb.utils.contains('VIRTUAL-RUNTIME_init_manager','toybox','true','false',d)}; then
Andrew Geissler89770b02020-06-13 10:40:47 -050063 sed -e 's/# CONFIG_INIT is not set/CONFIG_INIT=y/' -i .config
64 fi
Brad Bishop316dfdd2018-06-25 12:45:53 -040065}
66
67do_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 Geisslerd688a012020-09-18 13:36:00 -050073 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 Bishop316dfdd2018-06-25 12:45:53 -040079}
80
81do_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 Bishop316dfdd2018-06-25 12:45:53 -040094# If you've chosen to install toybox you probably want it to take precedence
95# over busybox where possible but not over other packages
96ALTERNATIVE_PRIORITY = "60"
97
Patrick Williams213cb262021-08-07 19:21:33 -050098python do_package:prepend () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040099 # 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 Geissler1548c072019-02-22 16:03:50 -0600104 target = d.expand("${base_bindir}/toybox")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400105
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 Williams213cb262021-08-07 19:21:33 -0500110 d.appendVar('ALTERNATIVE:%s' % (pn), ' ' + alt_name)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400111 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
112 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
113 f.close()
114}