sys-apps/groff: stable 1.22.4 for ppc64, bug #704420
[gentoo.git] / sys-apps / busybox / busybox-1.31.1-r2.ebuild
1 # Copyright 1999-2020 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=7
7
8 inherit flag-o-matic 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 ~ia64 ~m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~amd64-linux ~x86-linux"
20 fi
21
22 LICENSE="GPL-2" # GPL-2 only
23 SLOT="0"
24 IUSE="debug ipv6 livecd make-symlinks math mdev pam selinux sep-usr static syslog systemd"
25 REQUIRED_USE="pam? ( !static )"
26 RESTRICT="test"
27
28 COMMON_DEPEND="!static? ( selinux? ( sys-libs/libselinux ) )
29         pam? ( sys-libs/pam )
30         virtual/libcrypt:="
31 DEPEND="${COMMON_DEPEND}
32         static? (
33                 virtual/libcrypt[static-libs]
34                 selinux? ( sys-libs/libselinux[static-libs(+)] )
35         )
36         >=sys-kernel/linux-headers-2.6.39"
37 RDEPEND="${COMMON_DEPEND}
38         mdev? ( !<sys-apps/openrc-0.13 )"
39
40 S="${WORKDIR}/${MY_P}"
41
42 busybox_config_option() {
43         local flag=$1 ; shift
44         if [[ ${flag} != [yn] && ${flag} != \"* ]] ; then
45                 busybox_config_option $(usex ${flag} y n) "$@"
46                 return
47         fi
48         local expr
49         while [[ $# -gt 0 ]] ; do
50                 case ${flag} in
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" ;;
54                 esac
55                 sed -i -e "${expr}" .config || die
56                 einfo "$(grep "CONFIG_$1[= ]" .config || echo "Could not find CONFIG_$1 ...")"
57                 shift
58         done
59 }
60
61 busybox_config_enabled() {
62         local val=$(sed -n "/^CONFIG_$1=/s:^[^=]*=::p" .config)
63         case ${val} in
64         "") return 1 ;;
65         y)  return 0 ;;
66         *)  echo "${val}" | sed -r 's:^"(.*)"$:\1:' ;;
67         esac
68 }
69
70 # patches go here!
71 PATCHES=(
72         "${FILESDIR}"/${PN}-1.26.2-bb.patch
73         "${FILESDIR}"/${PN}-1.31.1-glibc-2.31.patch
74         # "${FILESDIR}"/${P}-*.patch
75 )
76
77 src_prepare() {
78         default
79         unset KBUILD_OUTPUT #88088
80         append-flags -fno-strict-aliasing #310413
81         use ppc64 && append-flags -mminimal-toc #130943
82
83         cp "${FILESDIR}"/ginit.c init/ || die
84
85         # flag cleanup
86         sed -i -r \
87                 -e 's:[[:space:]]?-(Werror|Os|falign-(functions|jumps|loops|labels)=1|fomit-frame-pointer)\>::g' \
88                 Makefile.flags || die
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
92         sed -i \
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):" \
98                 Makefile || die
99         sed -i \
100                 -e 's:-static-libgcc::' \
101                 Makefile.flags || die
102 }
103
104 src_configure() {
105         # check for a busybox config before making one of our own.
106         # if one exist lets return and use it.
107
108         restore_config .config
109         if [ -f .config ]; then
110                 yes "" | emake -j1 -s oldconfig >/dev/null
111                 return 0
112         else
113                 ewarn "Could not locate user configfile, so we will save a default one"
114         fi
115
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
122
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
135
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
141         fi
142
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
149
150         busybox_config_option '"/run"' PID_FILE_PATH
151         busybox_config_option '"/run/ifstate"' IFUPDOWN_IFSTATE_PATH
152
153         # disable ipv6 applets
154         if ! use ipv6; then
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
159         fi
160
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
166
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
171         fi
172
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
180
181         busybox_config_option selinux SELINUX
182
183         # this opt only controls mounting with <linux-2.6.23
184         busybox_config_option n FEATURE_MOUNT_NFS
185
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
189
190         # default a bunch of uncommon options to off
191         local opt
192         for opt in \
193                 ADD_SHELL \
194                 BEEP BOOTCHARTD \
195                 CRONTAB \
196                 DC DEVFSD DNSD DPKG{,_DEB} \
197                 FAKEIDENTD FBSPLASH FOLD FSCK_MINIX FTP{GET,PUT} \
198                 FEATURE_DEVFS \
199                 HOSTID HUSH \
200                 INETD INOTIFYD IPCALC \
201                 LOCALE_SUPPORT LOGNAME LPD \
202                 MAKEMIME MKFS_MINIX MSH \
203                 OD \
204                 RDEV READPROFILE REFORMIME REMOVE_SHELL RFKILL RUN_PARTS RUNSV{,DIR} \
205                 SLATTACH SMEMCAP SULOGIN SV{,LOGD} \
206                 TASKSET TCPSVD \
207                 RPM RPM2CPIO \
208                 UDPSVD UUDECODE UUENCODE
209         do
210                 busybox_config_option n ${opt}
211         done
212
213         emake -j1 oldconfig > /dev/null
214 }
215
216 src_compile() {
217         unset KBUILD_OUTPUT #88088
218         export SKIP_STRIP=y
219
220         emake V=1 busybox
221 }
222
223 src_install() {
224         unset KBUILD_OUTPUT #88088
225         save_config .config
226
227         into /
228         dodir /bin
229         if use sep-usr ; then
230                 # install /ginit to take care of mounting stuff
231                 exeinto /
232                 newexe busybox_unstripped ginit
233                 dosym /ginit /bin/bb
234                 dosym bb /bin/busybox
235         else
236                 newbin busybox_unstripped busybox
237                 dosym busybox /bin/bb
238         fi
239         if use mdev ; then
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
243
244                 exeinto /$(get_libdir)/mdev/
245                 doexe "${FILESDIR}"/mdev/*
246
247                 newinitd "${FILESDIR}"/mdev.initd mdev
248         fi
249         if use livecd ; then
250                 dosym busybox /bin/vi
251         fi
252
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"
257         fi
258         if busybox_config_enabled SYSLOGD; then
259                 newconfd "${FILESDIR}/syslogd.confd" "busybox-syslogd"
260                 newinitd "${FILESDIR}/syslogd.initd" "busybox-syslogd"
261         fi
262         if busybox_config_enabled KLOGD; then
263                 newconfd "${FILESDIR}/klogd.confd" "busybox-klogd"
264                 newinitd "${FILESDIR}/klogd.initd" "busybox-klogd"
265         fi
266         if busybox_config_enabled WATCHDOG; then
267                 newconfd "${FILESDIR}/watchdog.confd" "busybox-watchdog"
268                 newinitd "${FILESDIR}/watchdog.initd" "busybox-watchdog"
269         fi
270         if busybox_config_enabled UDHCPC; then
271                 local path=$(busybox_config_enabled UDHCPC_DEFAULT_SCRIPT)
272                 exeinto "${path%/*}"
273                 newexe examples/udhcp/simple.script "${path##*/}"
274         fi
275         if busybox_config_enabled UDHCPD; then
276                 insinto /etc
277                 doins examples/udhcp/udhcpd.conf
278         fi
279
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
289
290         dodoc AUTHORS README TODO
291
292         cd docs
293         docinto txt
294         dodoc *.txt
295         docinto pod
296         dodoc *.pod
297         docinto html
298         dodoc *.html
299
300         cd ../examples
301         docinto examples
302         dodoc inittab depmod.pl *.conf *.script undeb unrpm
303 }
304
305 pkg_preinst() {
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"
312         fi
313
314         if use make-symlinks ; then
315                 mv "${ED}"/usr/share/${PN}/busybox-links.tar "${T}"/ || die
316         fi
317 }
318
319 pkg_postinst() {
320         savedconfig_pkg_postinst
321
322         if use make-symlinks ; then
323                 cd "${T}" || die
324                 mkdir _install
325                 tar xf busybox-links.tar -C _install || die
326                 cp -vpPR _install/* "${ROOT}"/ || die "copying links for ${x} failed"
327         fi
328
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:"
332                 elog "     init=/ginit"
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"
337         fi
338 }