blob: 4e72f295d3b5b5da2b01544ad2ff5965f168315e [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
5LICENSE = "BSD-0-Clause"
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 \
Andrew Geissler2ee498a2020-05-29 15:52:06 -050011 file://mips-no-STKFLT.patch \
12 file://0001-Tackle-SIGEMT-and-SIGSTKFLT-is-not-glibc-specific.patch \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013 "
Andrew Geissler2ee498a2020-05-29 15:52:06 -050014SRC_URI[sha256sum] = "eab28fd29d19d4e61ef09704e5871940e6f35fd35a3bb1285e41f204504b5c01"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015
16SECTION = "base"
17
18TOYBOX_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
27COMPILER_toolchain-clang = "clang"
28COMPILER ?= "gcc"
29
30EXTRA_OEMAKE = 'CROSS_COMPILE="${HOST_PREFIX}" \
31 CC="${COMPILER}" \
32 STRIP="strip" \
33 CFLAGS="${CFLAGS}" \
34 HOSTCC="${BUILD_CC}" CPUS=${@oe.utils.cpu_count()} V=1'
Brad Bishop316dfdd2018-06-25 12:45:53 -040035
36do_configure() {
Andrew Geissler7f40b712020-05-15 14:09:53 -050037 # allow user to define their own defconfig in bbappend, taken from kernel.bbclass
38 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
39 mv "${S}/.config" "${B}/.config"
40 fi
41
42 # Copy defconfig to .config if .config does not exist. This allows
43 # recipes to manage the .config themselves in do_configure_prepend().
44 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
45 cp "${WORKDIR}/defconfig" "${B}/.config"
46 fi
47
48 oe_runmake oldconfig || oe_runmake defconfig
Brad Bishop316dfdd2018-06-25 12:45:53 -040049
50 # Disable killall5 as it isn't managed by update-alternatives
51 sed -e 's/CONFIG_KILLALL5=y/# CONFIG_KILLALL5 is not set/' -i .config
52
53 # Disable swapon as it doesn't handle the '-a' argument used during boot
54 sed -e 's/CONFIG_SWAPON=y/# CONFIG_SWAPON is not set/' -i .config
55}
56
57do_compile() {
58 oe_runmake ${TOYBOX_BIN}
59
60 # Create a list of links needed
61 ${BUILD_CC} -I . scripts/install.c -o generated/instlist
62 ./generated/instlist long | sed -e 's#^#/#' > toybox.links
63}
64
65do_install() {
66 # Install manually instead of using 'make install'
67 install -d ${D}${base_bindir}
68 if grep -q "CONFIG_TOYBOX_SUID=y" ${B}/.config; then
69 install -m 4755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
70 else
71 install -m 0755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
72 fi
73
74 install -d ${D}${sysconfdir}
75 install -m 0644 ${B}/toybox.links ${D}${sysconfdir}
76}
77
Brad Bishop316dfdd2018-06-25 12:45:53 -040078# If you've chosen to install toybox you probably want it to take precedence
79# over busybox where possible but not over other packages
80ALTERNATIVE_PRIORITY = "60"
81
82python do_package_prepend () {
83 # Read links from /etc/toybox.links and create appropriate
84 # update-alternatives variables
85
86 dvar = d.getVar('D')
87 pn = d.getVar('PN')
Andrew Geissler1548c072019-02-22 16:03:50 -060088 target = d.expand("${base_bindir}/toybox")
Brad Bishop316dfdd2018-06-25 12:45:53 -040089
90 f = open('%s/etc/toybox.links' % (dvar), 'r')
91 for alt_link_name in f:
92 alt_link_name = alt_link_name.strip()
93 alt_name = os.path.basename(alt_link_name)
94 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
95 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
96 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
97 f.close()
98}