blob: 1513255c462f10ebe778b3506f2986b26a5652f5 [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
Andrew Geisslerd688a012020-09-18 13:36:00 -050032PACKAGECONFIG ??= "no-iconv no-getconf"
33
34PACKAGECONFIG[no-iconv] = ",,"
35PACKAGECONFIG[no-getconf] = ",,"
36
Andrew Geissler2ee498a2020-05-29 15:52:06 -050037EXTRA_OEMAKE = 'CROSS_COMPILE="${HOST_PREFIX}" \
38 CC="${COMPILER}" \
39 STRIP="strip" \
40 CFLAGS="${CFLAGS}" \
41 HOSTCC="${BUILD_CC}" CPUS=${@oe.utils.cpu_count()} V=1'
Brad Bishop316dfdd2018-06-25 12:45:53 -040042
43do_configure() {
Andrew Geissler7f40b712020-05-15 14:09:53 -050044 # allow user to define their own defconfig in bbappend, taken from kernel.bbclass
45 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
46 mv "${S}/.config" "${B}/.config"
47 fi
48
49 # Copy defconfig to .config if .config does not exist. This allows
50 # recipes to manage the .config themselves in do_configure_prepend().
51 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
52 cp "${WORKDIR}/defconfig" "${B}/.config"
53 fi
54
55 oe_runmake oldconfig || oe_runmake defconfig
Brad Bishop316dfdd2018-06-25 12:45:53 -040056
57 # Disable killall5 as it isn't managed by update-alternatives
58 sed -e 's/CONFIG_KILLALL5=y/# CONFIG_KILLALL5 is not set/' -i .config
59
60 # Disable swapon as it doesn't handle the '-a' argument used during boot
61 sed -e 's/CONFIG_SWAPON=y/# CONFIG_SWAPON is not set/' -i .config
Andrew Geissler89770b02020-06-13 10:40:47 -050062
63 # Enable init if toybox was set as init manager
Andrew Geisslerd688a012020-09-18 13:36:00 -050064 if ${@bb.utils.contains('VIRTUAL-RUNTIME_init_manager','toybox','true','false',d)}; then
Andrew Geissler89770b02020-06-13 10:40:47 -050065 sed -e 's/# CONFIG_INIT is not set/CONFIG_INIT=y/' -i .config
66 fi
Brad Bishop316dfdd2018-06-25 12:45:53 -040067}
68
69do_compile() {
70 oe_runmake ${TOYBOX_BIN}
71
72 # Create a list of links needed
73 ${BUILD_CC} -I . scripts/install.c -o generated/instlist
74 ./generated/instlist long | sed -e 's#^#/#' > toybox.links
Andrew Geisslerd688a012020-09-18 13:36:00 -050075 if ${@bb.utils.contains('PACKAGECONFIG','no-iconv','true','false',d)}; then
76 sed -i -e '/iconv$/d' toybox.links
77 fi
78 if ${@bb.utils.contains('PACKAGECONFIG','no-getconf','true','false',d)}; then
79 sed -i -e '/getconf$/d' toybox.links
80 fi
Brad Bishop316dfdd2018-06-25 12:45:53 -040081}
82
83do_install() {
84 # Install manually instead of using 'make install'
85 install -d ${D}${base_bindir}
86 if grep -q "CONFIG_TOYBOX_SUID=y" ${B}/.config; then
87 install -m 4755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
88 else
89 install -m 0755 ${B}/${TOYBOX_BIN} ${D}${base_bindir}/toybox
90 fi
91
92 install -d ${D}${sysconfdir}
93 install -m 0644 ${B}/toybox.links ${D}${sysconfdir}
94}
95
Brad Bishop316dfdd2018-06-25 12:45:53 -040096# If you've chosen to install toybox you probably want it to take precedence
97# over busybox where possible but not over other packages
98ALTERNATIVE_PRIORITY = "60"
99
100python do_package_prepend () {
101 # Read links from /etc/toybox.links and create appropriate
102 # update-alternatives variables
103
104 dvar = d.getVar('D')
105 pn = d.getVar('PN')
Andrew Geissler1548c072019-02-22 16:03:50 -0600106 target = d.expand("${base_bindir}/toybox")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400107
108 f = open('%s/etc/toybox.links' % (dvar), 'r')
109 for alt_link_name in f:
110 alt_link_name = alt_link_name.strip()
111 alt_name = os.path.basename(alt_link_name)
112 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
113 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
114 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
115 f.close()
116}