blob: 5d453219f2c675a065f1a28c9c7bf13a78fabbb7 [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
Andrew Geissler89770b02020-06-13 10:40:47 -050018RDEPENDS_${PN} = "${@["", "toybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'toybox')]}"
19
Brad Bishop316dfdd2018-06-25 12:45:53 -040020TOYBOX_BIN = "generated/unstripped/toybox"
21
Andrew Geissler2ee498a2020-05-29 15:52:06 -050022# Toybox is strict on what CC, CFLAGS and CROSS_COMPILE variables should contain.
23# Fix CC, CFLAGS, CROSS_COMPILE to match expectations.
24# CC = compiler name
25# CFLAGS = only compiler flags
26# CROSS_COMPILE = compiler prefix
27CFLAGS += "${TOOLCHAIN_OPTIONS} ${TUNE_CCARGS}"
28
29COMPILER_toolchain-clang = "clang"
30COMPILER ?= "gcc"
31
32EXTRA_OEMAKE = 'CROSS_COMPILE="${HOST_PREFIX}" \
33 CC="${COMPILER}" \
34 STRIP="strip" \
35 CFLAGS="${CFLAGS}" \
36 HOSTCC="${BUILD_CC}" CPUS=${@oe.utils.cpu_count()} V=1'
Brad Bishop316dfdd2018-06-25 12:45:53 -040037
38do_configure() {
Andrew Geissler7f40b712020-05-15 14:09:53 -050039 # allow user to define their own defconfig in bbappend, taken from kernel.bbclass
40 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
41 mv "${S}/.config" "${B}/.config"
42 fi
43
44 # Copy defconfig to .config if .config does not exist. This allows
45 # recipes to manage the .config themselves in do_configure_prepend().
46 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
47 cp "${WORKDIR}/defconfig" "${B}/.config"
48 fi
49
50 oe_runmake oldconfig || oe_runmake defconfig
Brad Bishop316dfdd2018-06-25 12:45:53 -040051
52 # Disable killall5 as it isn't managed by update-alternatives
53 sed -e 's/CONFIG_KILLALL5=y/# CONFIG_KILLALL5 is not set/' -i .config
54
55 # Disable swapon as it doesn't handle the '-a' argument used during boot
56 sed -e 's/CONFIG_SWAPON=y/# CONFIG_SWAPON is not set/' -i .config
Andrew Geissler89770b02020-06-13 10:40:47 -050057
58 # Enable init if toybox was set as init manager
59 if [[ ${VIRTUAL-RUNTIME_init_manager} == *"toybox"* ]]; then
60 sed -e 's/# CONFIG_INIT is not set/CONFIG_INIT=y/' -i .config
61 fi
Brad Bishop316dfdd2018-06-25 12:45:53 -040062}
63
64do_compile() {
65 oe_runmake ${TOYBOX_BIN}
66
67 # Create a list of links needed
68 ${BUILD_CC} -I . scripts/install.c -o generated/instlist
69 ./generated/instlist long | sed -e 's#^#/#' > toybox.links
70}
71
72do_install() {
73 # Install manually instead of using 'make install'
74 install -d ${D}${base_bindir}
75 if grep -q "CONFIG_TOYBOX_SUID=y" ${B}/.config; then
76 install -m 4755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
77 else
78 install -m 0755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
79 fi
80
81 install -d ${D}${sysconfdir}
82 install -m 0644 ${B}/toybox.links ${D}${sysconfdir}
83}
84
Brad Bishop316dfdd2018-06-25 12:45:53 -040085# If you've chosen to install toybox you probably want it to take precedence
86# over busybox where possible but not over other packages
87ALTERNATIVE_PRIORITY = "60"
88
89python do_package_prepend () {
90 # Read links from /etc/toybox.links and create appropriate
91 # update-alternatives variables
92
93 dvar = d.getVar('D')
94 pn = d.getVar('PN')
Andrew Geissler1548c072019-02-22 16:03:50 -060095 target = d.expand("${base_bindir}/toybox")
Brad Bishop316dfdd2018-06-25 12:45:53 -040096
97 f = open('%s/etc/toybox.links' % (dvar), 'r')
98 for alt_link_name in f:
99 alt_link_name = alt_link_name.strip()
100 alt_name = os.path.basename(alt_link_name)
101 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
102 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
103 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
104 f.close()
105}