1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # See `man savedconfig.eclass` for info on how to use USE=savedconfig.
8 inherit flag-o-matic savedconfig toolchain-funcs
10 DESCRIPTION="Utilities for rescue and embedded systems"
11 HOMEPAGE="https://www.busybox.net/"
12 if [[ ${PV} == "9999" ]] ; then
14 EGIT_REPO_URI="https://git.busybox.net/busybox"
18 SRC_URI="https://www.busybox.net/downloads/${MY_P}.tar.bz2"
19 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~amd64-linux ~x86-linux"
22 LICENSE="GPL-2" # GPL-2 only
24 IUSE="debug ipv6 livecd make-symlinks math mdev pam selinux sep-usr static syslog systemd"
25 REQUIRED_USE="pam? ( !static )"
28 COMMON_DEPEND="!static? ( selinux? ( sys-libs/libselinux ) )
31 DEPEND="${COMMON_DEPEND}
33 virtual/libcrypt[static-libs]
34 selinux? ( sys-libs/libselinux[static-libs(+)] )
36 >=sys-kernel/linux-headers-2.6.39"
37 RDEPEND="${COMMON_DEPEND}
38 mdev? ( !<sys-apps/openrc-0.13 )"
40 S="${WORKDIR}/${MY_P}"
42 busybox_config_option() {
44 if [[ ${flag} != [yn] && ${flag} != \"* ]] ; then
45 busybox_config_option $(usex ${flag} y n) "$@"
49 while [[ $# -gt 0 ]] ; do
51 y) expr="s:.*\<CONFIG_$1\>.*set:CONFIG_$1=y:g" ;;
52 n) expr="s:CONFIG_$1=y:# CONFIG_$1 is not set:g" ;;
53 *) expr="s:.*\<CONFIG_$1\>.*:CONFIG_$1=${flag}:g" ;;
55 sed -i -e "${expr}" .config || die
56 einfo "$(grep "CONFIG_$1[= ]" .config || echo "Could not find CONFIG_$1 ...")"
61 busybox_config_enabled() {
62 local val=$(sed -n "/^CONFIG_$1=/s:^[^=]*=::p" .config)
66 *) echo "${val}" | sed -r 's:^"(.*)"$:\1:' ;;
72 "${FILESDIR}"/${PN}-1.26.2-bb.patch
73 "${FILESDIR}"/${PN}-1.31.1-glibc-2.31.patch
74 # "${FILESDIR}"/${P}-*.patch
79 unset KBUILD_OUTPUT #88088
80 append-flags -fno-strict-aliasing #310413
81 use ppc64 && append-flags -mminimal-toc #130943
83 cp "${FILESDIR}"/ginit.c init/ || die
87 -e 's:[[:space:]]?-(Werror|Os|falign-(functions|jumps|loops|labels)=1|fomit-frame-pointer)\>::g' \
89 #sed -i '/bbsh/s:^//::' include/applets.h
90 sed -i '/^#error Aborting compilation./d' applets/applets.c || die
91 use elibc_glibc && sed -i 's:-Wl,--gc-sections::' Makefile
93 -e "/^CROSS_COMPILE/s:=.*:= ${CHOST}-:" \
94 -e "/^AR\>/s:=.*:= $(tc-getAR):" \
95 -e "/^CC\>/s:=.*:= $(tc-getCC):" \
96 -e "/^HOSTCC/s:=.*:= $(tc-getBUILD_CC):" \
97 -e "/^PKG_CONFIG\>/s:=.*:= $(tc-getPKG_CONFIG):" \
100 -e 's:-static-libgcc::' \
101 Makefile.flags || die
105 # check for a busybox config before making one of our own.
106 # if one exist lets return and use it.
108 restore_config .config
109 if [ -f .config ]; then
110 yes "" | emake -j1 -s oldconfig >/dev/null
113 ewarn "Could not locate user configfile, so we will save a default one"
116 # setup the config file
117 emake -j1 -s allyesconfig >/dev/null
118 # nommu forces a bunch of things off which we want on #387555
119 busybox_config_option n NOMMU
120 sed -i '/^#/d' .config
121 yes "" | emake -j1 -s oldconfig >/dev/null
123 # now turn off stuff we really don't want
124 busybox_config_option n DMALLOC
125 busybox_config_option n FEATURE_2_4_MODULES #607548
126 busybox_config_option n FEATURE_SUID_CONFIG
127 busybox_config_option n BUILD_AT_ONCE
128 busybox_config_option n BUILD_LIBBUSYBOX
129 busybox_config_option n FEATURE_CLEAN_UP
130 busybox_config_option n MONOTONIC_SYSCALL
131 busybox_config_option n USE_PORTABLE_CODE
132 busybox_config_option n WERROR
133 # triming the BSS size may be dangerous
134 busybox_config_option n FEATURE_USE_BSS_TAIL
136 # These cause trouble with musl.
137 if use elibc_musl; then
138 busybox_config_option n FEATURE_UTMP
139 busybox_config_option n EXTRA_COMPAT
140 busybox_config_option n FEATURE_VI_REGEX_SEARCH
143 # If these are not set and we are using a uclibc/busybox setup
144 # all calls to system() will fail.
145 busybox_config_option y ASH
146 busybox_config_option y SH_IS_ASH
147 busybox_config_option n HUSH
148 busybox_config_option n SH_IS_HUSH
150 busybox_config_option '"/run"' PID_FILE_PATH
151 busybox_config_option '"/run/ifstate"' IFUPDOWN_IFSTATE_PATH
153 # disable ipv6 applets
155 busybox_config_option n FEATURE_IPV6
156 busybox_config_option n TRACEROUTE6
157 busybox_config_option n PING6
158 busybox_config_option n UDHCPC6
161 busybox_config_option pam PAM
162 busybox_config_option static STATIC
163 busybox_config_option syslog {K,SYS}LOGD LOGGER
164 busybox_config_option systemd FEATURE_SYSTEMD
165 busybox_config_option math FEATURE_AWK_LIBM
167 # disable features that uClibc doesn't (yet?) provide.
168 if use elibc_uclibc; then
169 busybox_config_option n FEATURE_SYNC_FANCY #567598
170 busybox_config_option n NSENTER
173 # all the debug options are compiler related, so punt them
174 busybox_config_option n DEBUG_SANITIZE
175 busybox_config_option n DEBUG
176 busybox_config_option y NO_DEBUG_LIB
177 busybox_config_option n DMALLOC
178 busybox_config_option n EFENCE
179 busybox_config_option $(usex debug y n) TFTP_DEBUG
181 busybox_config_option selinux SELINUX
183 # this opt only controls mounting with <linux-2.6.23
184 busybox_config_option n FEATURE_MOUNT_NFS
186 # glibc-2.26 and later does not ship RPC implientation
187 busybox_config_option n FEATURE_HAVE_RPC
188 busybox_config_option n FEATURE_INETD_RPC
190 # default a bunch of uncommon options to off
196 DC DEVFSD DNSD DPKG{,_DEB} \
197 FAKEIDENTD FBSPLASH FOLD FSCK_MINIX FTP{GET,PUT} \
200 INETD INOTIFYD IPCALC \
201 LOCALE_SUPPORT LOGNAME LPD \
202 MAKEMIME MKFS_MINIX MSH \
204 RDEV READPROFILE REFORMIME REMOVE_SHELL RFKILL RUN_PARTS RUNSV{,DIR} \
205 SLATTACH SMEMCAP SULOGIN SV{,LOGD} \
208 UDPSVD UUDECODE UUENCODE
210 busybox_config_option n ${opt}
213 emake -j1 oldconfig > /dev/null
217 unset KBUILD_OUTPUT #88088
224 unset KBUILD_OUTPUT #88088
229 if use sep-usr ; then
230 # install /ginit to take care of mounting stuff
232 newexe busybox_unstripped ginit
234 dosym bb /bin/busybox
236 newbin busybox_unstripped busybox
237 dosym busybox /bin/bb
240 dodir /$(get_libdir)/mdev/
241 use make-symlinks || dosym /bin/bb /sbin/mdev
242 cp "${S}"/examples/mdev_fat.conf "${ED}"/etc/mdev.conf
244 exeinto /$(get_libdir)/mdev/
245 doexe "${FILESDIR}"/mdev/*
247 newinitd "${FILESDIR}"/mdev.initd mdev
250 dosym busybox /bin/vi
253 # add busybox daemon's, bug #444718
254 if busybox_config_enabled FEATURE_NTPD_SERVER; then
255 newconfd "${FILESDIR}/ntpd.confd" "busybox-ntpd"
256 newinitd "${FILESDIR}/ntpd.initd" "busybox-ntpd"
258 if busybox_config_enabled SYSLOGD; then
259 newconfd "${FILESDIR}/syslogd.confd" "busybox-syslogd"
260 newinitd "${FILESDIR}/syslogd.initd" "busybox-syslogd"
262 if busybox_config_enabled KLOGD; then
263 newconfd "${FILESDIR}/klogd.confd" "busybox-klogd"
264 newinitd "${FILESDIR}/klogd.initd" "busybox-klogd"
266 if busybox_config_enabled WATCHDOG; then
267 newconfd "${FILESDIR}/watchdog.confd" "busybox-watchdog"
268 newinitd "${FILESDIR}/watchdog.initd" "busybox-watchdog"
270 if busybox_config_enabled UDHCPC; then
271 local path=$(busybox_config_enabled UDHCPC_DEFAULT_SCRIPT)
273 newexe examples/udhcp/simple.script "${path##*/}"
275 if busybox_config_enabled UDHCPD; then
277 doins examples/udhcp/udhcpd.conf
280 # bundle up the symlink files for use later
281 emake DESTDIR="${ED}" install
282 rm _install/bin/busybox
283 # for compatibility, provide /usr/bin/env
284 mkdir -p _install/usr/bin
285 ln -s /bin/env _install/usr/bin/env
286 tar cf busybox-links.tar -C _install . || : #;die
287 insinto /usr/share/${PN}
288 use make-symlinks && doins busybox-links.tar
290 dodoc AUTHORS README TODO
302 dodoc inittab depmod.pl *.conf *.script undeb unrpm
306 if use make-symlinks && [[ ! ${VERY_BRAVE_OR_VERY_DUMB} == "yes" ]] && [[ ${ROOT} == "/" ]] ; then
307 ewarn "setting USE=make-symlinks and emerging to / is very dangerous."
308 ewarn "it WILL overwrite lots of system programs like: ls bash awk grep (bug 60805 for full list)."
309 ewarn "If you are creating a binary only and not merging this is probably ok."
310 ewarn "set env VERY_BRAVE_OR_VERY_DUMB=yes if this is really what you want."
311 die "silly options will destroy your system"
314 if use make-symlinks ; then
315 mv "${ED}"/usr/share/${PN}/busybox-links.tar "${T}"/ || die
320 savedconfig_pkg_postinst
322 if use make-symlinks ; then
325 tar xf busybox-links.tar -C _install || die
326 cp -vpPR _install/* "${ROOT}"/ || die "copying links for ${x} failed"
329 if use sep-usr ; then
330 elog "In order to use the sep-usr support, you have to update your"
331 elog "kernel command line. Add the option:"
333 elog "To launch a different init than /sbin/init, use:"
334 elog " init=/ginit /sbin/yourinit"
335 elog "To get a rescue shell, you may boot with:"
336 elog " init=/ginit bb"