Skip to content

Commit c041603

Browse files
committed
sys-apps/busybox: Import from Gentoo
It's from Gentoo commit 573964683c6f490e3a1ff040ec21c9d3b8d8b154. Signed-off-by: Kai Lueke <[email protected]>
1 parent f094fc2 commit c041603

26 files changed

+1405
-0
lines changed

.github/workflows/portage-stable-packages-list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ sys-apps/acl
581581
sys-apps/attr
582582
sys-apps/azure-vm-utils
583583
sys-apps/bubblewrap
584+
sys-apps/busybox
584585
sys-apps/checkpolicy
585586
sys-apps/config-site
586587
sys-apps/coreutils
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DIST busybox-1.36.1.tar.bz2 2525473 BLAKE2B e515825cb3ab1c520e16b9c2512e9fc72947366a72a0466bff59b507fdffbc78fc9d16b44a26116175fc7a429d849ad944b1bc379d36c6d3a0eb20969997336e SHA512 8c0c754c9ae04b5e6b23596283a7d3a4ef96225fe179f92d6f6a99c69c0caa95b1aa56c267f52d7c807f6cc69e1f0b7dd29a8ac624098f601738f8c0c57980d4
Lines changed: 388 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,388 @@
1+
# Copyright 1999-2025 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
# See `man savedconfig.eclass` for info on how to use USE=savedconfig.
5+
6+
EAPI=8
7+
8+
inherit eapi9-ver flag-o-matic readme.gentoo-r1 savedconfig toolchain-funcs
9+
10+
DESCRIPTION="Utilities for rescue and embedded systems"
11+
HOMEPAGE="https://www.busybox.net/"
12+
if [[ ${PV} == "9999" ]] ; then
13+
MY_P="${P}"
14+
EGIT_REPO_URI="https://git.busybox.net/busybox"
15+
inherit git-r3
16+
else
17+
MY_P="${PN}-${PV/_/-}"
18+
SRC_URI="https://www.busybox.net/downloads/${MY_P}.tar.bz2"
19+
KEYWORDS="~alpha amd64 arm arm64 ~hppa ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 ~sparc x86 ~amd64-linux ~x86-linux"
20+
fi
21+
S="${WORKDIR}/${MY_P}"
22+
23+
LICENSE="GPL-2" # GPL-2 only
24+
SLOT="0"
25+
IUSE="debug livecd make-symlinks math mdev pam selinux sep-usr static syslog systemd"
26+
REQUIRED_USE="pam? ( !static )"
27+
RESTRICT="test"
28+
29+
# TODO: Could make pkgconfig conditional on selinux? bug #782829
30+
RDEPEND="
31+
!static? (
32+
virtual/libc
33+
virtual/libcrypt:=
34+
selinux? ( sys-libs/libselinux )
35+
)
36+
pam? ( sys-libs/pam )
37+
"
38+
DEPEND="${RDEPEND}
39+
static? (
40+
virtual/libcrypt[static-libs]
41+
selinux? ( sys-libs/libselinux[static-libs(+)] )
42+
)
43+
sys-kernel/linux-headers"
44+
BDEPEND="virtual/pkgconfig"
45+
46+
DISABLE_AUTOFORMATTING=yes
47+
DOC_CONTENTS='
48+
If you want a smaller executable, add `-Oz` to your busybox `CFLAGS`.'
49+
50+
busybox_config_option() {
51+
local flag=$1 ; shift
52+
if [[ ${flag} != [yn] && ${flag} != \"* ]] ; then
53+
busybox_config_option $(usex ${flag} y n) "$@"
54+
return
55+
fi
56+
local expr
57+
while [[ $# -gt 0 ]] ; do
58+
case ${flag} in
59+
y) expr="s:.*\<CONFIG_$1\>.*set:CONFIG_$1=y:g" ;;
60+
n) expr="s:CONFIG_$1=y:# CONFIG_$1 is not set:g" ;;
61+
*) expr="s:.*\<CONFIG_$1\>.*:CONFIG_$1=${flag}:g" ;;
62+
esac
63+
sed -i -e "${expr}" .config || die
64+
einfo "$(grep "CONFIG_$1[= ]" .config || echo "Could not find CONFIG_$1 ...")"
65+
shift
66+
done
67+
}
68+
69+
busybox_config_enabled() {
70+
local val=$(sed -n "/^CONFIG_$1=/s:^[^=]*=::p" .config)
71+
case ${val} in
72+
"") return 1 ;;
73+
y) return 0 ;;
74+
*) echo "${val}" | sed -r 's:^"(.*)"$:\1:' ;;
75+
esac
76+
}
77+
78+
# patches go here!
79+
PATCHES=(
80+
"${FILESDIR}"/${PN}-1.26.2-bb.patch
81+
"${FILESDIR}"/${PN}-1.34.1-skip-selinux-search.patch
82+
83+
"${FILESDIR}"/${PN}-1.36.0-fortify-source-3-fixdep.patch
84+
"${FILESDIR}"/${PN}-1.36.1-kernel-6.8.patch
85+
86+
"${FILESDIR}"/${PN}-1.36.1-skip-dynamic-relocations.patch
87+
88+
# "${FILESDIR}"/${P}-*.patch
89+
)
90+
91+
src_prepare() {
92+
default
93+
94+
cp "${FILESDIR}"/ginit.c init/ || die
95+
96+
# flag cleanup
97+
sed -i -r \
98+
-e 's:[[:space:]]?-(Werror|Os|Oz|falign-(functions|jumps|loops|labels)=1|fomit-frame-pointer)\>::g' \
99+
Makefile.flags || die
100+
sed -i \
101+
-e 's:-static-libgcc::' \
102+
Makefile.flags || die
103+
104+
# Print all link lines too
105+
sed -i -e 's:debug=false:debug=true:' scripts/trylink || die
106+
}
107+
108+
bbmake() {
109+
local args=(
110+
V=1
111+
CROSS_COMPILE="${CHOST}-"
112+
AR="${AR}"
113+
CC="${CC}"
114+
HOSTCC="${BUILD_CC}"
115+
HOSTCFLAGS="${BUILD_CFLAGS}"
116+
PKG_CONFIG="${PKG_CONFIG}"
117+
)
118+
emake "${args[@]}" "$@"
119+
}
120+
121+
src_configure() {
122+
unset KBUILD_OUTPUT #88088
123+
export SKIP_STRIP=y
124+
125+
tc-export AR CC BUILD_CC PKG_CONFIG
126+
127+
tc-is-cross-compiler || BUILD_CFLAGS=${CFLAGS}
128+
BUILD_CFLAGS+=" -D_FILE_OFFSET_BITS=64" #930513
129+
130+
append-flags -fno-strict-aliasing #310413
131+
use ppc64 && append-flags -mminimal-toc #130943
132+
133+
# check for a busybox config before making one of our own.
134+
# if one exist lets return and use it.
135+
136+
restore_config .config
137+
if [ -f .config ]; then
138+
yes "" | bbmake -j1 oldconfig
139+
return 0
140+
else
141+
ewarn "Could not locate user configfile, so we will save a default one"
142+
fi
143+
144+
# setting SKIP_SELINUX skips searching for selinux at this stage. We don't
145+
# need to search now in case we end up not needing it after all.
146+
# setup the config file
147+
bbmake -j1 allyesconfig SKIP_SELINUX=$(usex selinux n y) #620918
148+
# nommu forces a bunch of things off which we want on #387555
149+
busybox_config_option n NOMMU
150+
sed -i '/^#/d' .config
151+
yes "" | bbmake -j1 oldconfig SKIP_SELINUX=$(usex selinux n y) #620918
152+
153+
# now turn off stuff we really don't want
154+
busybox_config_option n DMALLOC
155+
busybox_config_option n FEATURE_2_4_MODULES #607548
156+
busybox_config_option n FEATURE_SUID_CONFIG
157+
busybox_config_option n BUILD_AT_ONCE
158+
busybox_config_option n BUILD_LIBBUSYBOX
159+
busybox_config_option n FEATURE_CLEAN_UP
160+
busybox_config_option n MONOTONIC_SYSCALL
161+
busybox_config_option n USE_PORTABLE_CODE
162+
busybox_config_option n WERROR
163+
# CONFIG_MODPROBE_SMALL=y disables depmod.c and uses a smaller one that
164+
# does not support -b. Setting this to no creates slightly larger and
165+
# slightly more useful modutils
166+
busybox_config_option n MODPROBE_SMALL #472464
167+
# triming the BSS size may be dangerous
168+
busybox_config_option n FEATURE_USE_BSS_TAIL
169+
170+
# These cause trouble with musl.
171+
if use elibc_musl; then
172+
busybox_config_option n FEATURE_UTMP
173+
busybox_config_option n EXTRA_COMPAT
174+
busybox_config_option n FEATURE_VI_REGEX_SEARCH
175+
fi
176+
177+
# Disable standalone shell mode when using make-symlinks, else Busybox calls its
178+
# applets by default without looking up in PATH.
179+
# This also enables users to disable a builtin by deleting the corresponding symlink.
180+
if use make-symlinks; then
181+
busybox_config_option n FEATURE_PREFER_APPLETS
182+
busybox_config_option n FEATURE_SH_STANDALONE
183+
fi
184+
185+
# If these are not set and we are using a busybox setup
186+
# all calls to system() will fail.
187+
busybox_config_option y ASH
188+
busybox_config_option y SH_IS_ASH
189+
busybox_config_option n HUSH
190+
busybox_config_option n SH_IS_HUSH
191+
192+
busybox_config_option '"/run"' PID_FILE_PATH
193+
busybox_config_option '"/run/ifstate"' IFUPDOWN_IFSTATE_PATH
194+
195+
busybox_config_option pam PAM
196+
busybox_config_option static STATIC
197+
busybox_config_option syslog {K,SYS}LOGD LOGGER
198+
busybox_config_option systemd FEATURE_SYSTEMD
199+
busybox_config_option math FEATURE_AWK_LIBM
200+
201+
# all the debug options are compiler related, so punt them
202+
busybox_config_option n DEBUG_SANITIZE
203+
busybox_config_option n DEBUG
204+
busybox_config_option y NO_DEBUG_LIB
205+
busybox_config_option n DMALLOC
206+
busybox_config_option n EFENCE
207+
busybox_config_option $(usex debug y n) TFTP_DEBUG
208+
209+
busybox_config_option selinux SELINUX
210+
211+
# this opt only controls mounting with <linux-2.6.23
212+
busybox_config_option n FEATURE_MOUNT_NFS
213+
214+
# glibc-2.26 and later does not ship RPC implientation
215+
busybox_config_option n FEATURE_HAVE_RPC
216+
busybox_config_option n FEATURE_INETD_RPC
217+
218+
# default a bunch of uncommon options to off
219+
local opt
220+
for opt in \
221+
ADD_SHELL \
222+
BEEP BOOTCHARTD \
223+
CRONTAB \
224+
DC DEVFSD DNSD DPKG{,_DEB} \
225+
FAKEIDENTD FBSPLASH FOLD FSCK_MINIX FTP{GET,PUT} \
226+
FEATURE_DEVFS \
227+
HOSTID HUSH \
228+
INETD INOTIFYD IPCALC \
229+
LOCALE_SUPPORT LOGNAME LPD \
230+
MAKEMIME MKFS_MINIX MSH \
231+
OD \
232+
RDEV READPROFILE REFORMIME REMOVE_SHELL RFKILL RUN_PARTS RUNSV{,DIR} \
233+
SLATTACH SMEMCAP SULOGIN SV{,LOGD} \
234+
TASKSET TCPSVD \
235+
RPM RPM2CPIO \
236+
UDPSVD UUDECODE UUENCODE
237+
do
238+
busybox_config_option n ${opt}
239+
done
240+
241+
bbmake -j1 oldconfig
242+
}
243+
244+
src_compile() {
245+
bbmake busybox
246+
247+
# bug #701512
248+
bbmake doc
249+
}
250+
251+
src_install() {
252+
unset KBUILD_OUTPUT #88088
253+
save_config .config
254+
255+
into /
256+
dodir /bin
257+
if use sep-usr ; then
258+
# install /ginit to take care of mounting stuff
259+
exeinto /
260+
newexe busybox_unstripped ginit
261+
dosym /ginit /bin/bb
262+
dosym bb /bin/busybox
263+
else
264+
newbin busybox_unstripped busybox
265+
dosym busybox /bin/bb
266+
fi
267+
if use mdev ; then
268+
dodir /$(get_libdir)/mdev/
269+
use make-symlinks || dosym /bin/bb /sbin/mdev
270+
cp "${S}"/examples/mdev_fat.conf "${ED}"/etc/mdev.conf || die
271+
if [[ ! "$(get_libdir)" == "lib" ]]; then
272+
#831251 - replace lib with lib64 where appropriate
273+
sed -i -e "s:/lib/:/$(get_libdir)/:g" "${ED}"/etc/mdev.conf || die
274+
fi
275+
276+
exeinto /$(get_libdir)/mdev/
277+
doexe "${FILESDIR}"/mdev/*
278+
279+
newinitd "${FILESDIR}"/mdev.initd mdev
280+
fi
281+
if use livecd ; then
282+
dosym busybox /bin/vi
283+
fi
284+
285+
# add busybox daemon's, bug #444718
286+
if busybox_config_enabled FEATURE_NTPD_SERVER; then
287+
newconfd "${FILESDIR}"/ntpd.confd busybox-ntpd
288+
newinitd "${FILESDIR}"/ntpd.initd busybox-ntpd
289+
fi
290+
if busybox_config_enabled SYSLOGD; then
291+
newconfd "${FILESDIR}"/syslogd.confd busybox-syslogd
292+
newinitd "${FILESDIR}"/syslogd.initd busybox-syslogd
293+
fi
294+
if busybox_config_enabled KLOGD; then
295+
newconfd "${FILESDIR}"/klogd.confd busybox-klogd
296+
newinitd "${FILESDIR}"/klogd.initd busybox-klogd
297+
fi
298+
if busybox_config_enabled WATCHDOG; then
299+
newconfd "${FILESDIR}"/watchdog.confd busybox-watchdog
300+
newinitd "${FILESDIR}"/watchdog.initd busybox-watchdog
301+
fi
302+
if busybox_config_enabled UDHCPC; then
303+
sed -i 's:$((metric++)):$metric; metric=$((metric + 1)):' examples/udhcp/simple.script || die #801535
304+
local path=$(busybox_config_enabled UDHCPC_DEFAULT_SCRIPT)
305+
exeinto "${path%/*}"
306+
newexe examples/udhcp/simple.script "${path##*/}"
307+
fi
308+
if busybox_config_enabled UDHCPD; then
309+
insinto /etc
310+
doins examples/udhcp/udhcpd.conf
311+
fi
312+
if busybox_config_enabled ASH && ! use make-symlinks; then
313+
dosym -r /bin/busybox /bin/ash
314+
fi
315+
if busybox_config_enabled CROND; then
316+
newconfd "${FILESDIR}"/crond.confd busybox-crond
317+
newinitd "${FILESDIR}"/crond.initd busybox-crond
318+
fi
319+
320+
# bundle up the symlink files for use later
321+
bbmake DESTDIR="${ED}" install
322+
# for compatibility, provide /usr/bin/env
323+
mkdir -p _install/usr/bin || die
324+
if [[ ! -e _install/usr/bin/env ]]; then
325+
ln -s /bin/env _install/usr/bin/env || die
326+
fi
327+
rm _install/bin/busybox || die
328+
tar cf busybox-links.tar -C _install . || : #;die
329+
insinto /usr/share/${PN}
330+
use make-symlinks && doins busybox-links.tar
331+
332+
dodoc AUTHORS README TODO
333+
334+
cd docs || die
335+
doman busybox.1
336+
docinto txt
337+
dodoc *.txt
338+
docinto pod
339+
dodoc *.pod
340+
docinto html
341+
dodoc *.html
342+
343+
cd ../examples || die
344+
docinto examples
345+
dodoc inittab depmod.pl *.conf *.script undeb unrpm
346+
347+
cd ../networking || die
348+
dodoc httpd_indexcgi.c httpd_post_upload.cgi
349+
350+
readme.gentoo_create_doc
351+
}
352+
353+
pkg_preinst() {
354+
if use make-symlinks ; then
355+
mv "${ED}"/usr/share/${PN}/busybox-links.tar "${T}"/ || die
356+
fi
357+
}
358+
359+
pkg_postinst() {
360+
savedconfig_pkg_postinst
361+
362+
if use make-symlinks ; then
363+
cd "${T}" || die
364+
mkdir _install
365+
tar xf busybox-links.tar -C _install || die
366+
# 907432: cp -n returns error if it skips any file, but that is expected here
367+
# TODO: check if a new coreutils release has a replacement option
368+
cp -nvpPR _install/* "${ROOT}"/
369+
fi
370+
371+
if use sep-usr ; then
372+
elog "In order to use the sep-usr support, you have to update your"
373+
elog "kernel command line. Add the option:"
374+
elog " init=/ginit"
375+
elog "To launch a different init than /sbin/init, use:"
376+
elog " init=/ginit /sbin/yourinit"
377+
elog "To get a rescue shell, you may boot with:"
378+
elog " init=/ginit bb"
379+
fi
380+
381+
if [[ ${MERGE_TYPE} != binary ]] && ! is-flagq -Oz; then
382+
if ver_replacing -le 1.36.1; then
383+
FORCE_PRINT_ELOG=yes
384+
fi
385+
386+
readme.gentoo_print_elog
387+
fi
388+
}

0 commit comments

Comments
 (0)