busybox-1.25.1.ebuild 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # See `man savedconfig.eclass` for info on how to use USE=savedconfig.
  4. EAPI="5"
  5. inherit eutils flag-o-matic savedconfig toolchain-funcs multilib
  6. DESCRIPTION="Utilities for rescue and embedded systems"
  7. HOMEPAGE="https://www.busybox.net/"
  8. if [[ ${PV} == "9999" ]] ; then
  9. MY_P=${PN}
  10. EGIT_REPO_URI="git://busybox.net/busybox.git"
  11. inherit git-2
  12. else
  13. MY_P=${PN}-${PV/_/-}
  14. SRC_URI="https://www.busybox.net/downloads/${MY_P}.tar.bz2"
  15. KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~amd64-linux ~arm-linux ~x86-linux"
  16. fi
  17. LICENSE="GPL-2" # GPL-2 only
  18. SLOT="0"
  19. IUSE="debug ipv6 livecd make-symlinks math mdev pam selinux sep-usr static syslog systemd"
  20. REQUIRED_USE="pam? ( !static )"
  21. RESTRICT="test"
  22. COMMON_DEPEND="!static? ( selinux? ( sys-libs/libselinux ) )
  23. pam? ( sys-libs/pam )"
  24. DEPEND="${COMMON_DEPEND}
  25. static? ( selinux? ( sys-libs/libselinux[static-libs(+)] ) )
  26. >=sys-kernel/linux-headers-2.6.39"
  27. RDEPEND="${COMMON_DEPEND}
  28. mdev? ( !<sys-apps/openrc-0.13 )"
  29. S=${WORKDIR}/${MY_P}
  30. busybox_config_option() {
  31. local flag=$1 ; shift
  32. if [[ ${flag} != [yn] ]] ; then
  33. busybox_config_option $(usex ${flag} y n) "$@"
  34. return
  35. fi
  36. while [[ $# -gt 0 ]] ; do
  37. if [[ ${flag} == "y" ]] ; then
  38. sed -i -e "s:.*\<CONFIG_$1\>.*set:CONFIG_$1=y:g" .config
  39. else
  40. sed -i -e "s:CONFIG_$1=y:# CONFIG_$1 is not set:g" .config
  41. fi
  42. einfo $(grep "CONFIG_$1[= ]" .config || echo Could not find CONFIG_$1 ...)
  43. shift
  44. done
  45. }
  46. busybox_config_enabled() {
  47. local val=$(sed -n "/^CONFIG_$1=/s:^[^=]*=::p" .config)
  48. case ${val} in
  49. "") return 1 ;;
  50. y) return 0 ;;
  51. *) echo "${val}" | sed -r 's:^"(.*)"$:\1:' ;;
  52. esac
  53. }
  54. src_prepare() {
  55. unset KBUILD_OUTPUT #88088
  56. append-flags -fno-strict-aliasing #310413
  57. use ppc64 && append-flags -mminimal-toc #130943
  58. # patches go here!
  59. epatch "${FILESDIR}"/${PN}-1.19.0-bb.patch
  60. epatch "${FILESDIR}"/${P}-*.patch
  61. cp "${FILESDIR}"/ginit.c init/ || die
  62. # flag cleanup
  63. sed -i -r \
  64. -e 's:[[:space:]]?-(Werror|Os|falign-(functions|jumps|loops|labels)=1|fomit-frame-pointer)\>::g' \
  65. Makefile.flags || die
  66. #sed -i '/bbsh/s:^//::' include/applets.h
  67. sed -i '/^#error Aborting compilation./d' applets/applets.c || die
  68. use elibc_glibc && sed -i 's:-Wl,--gc-sections::' Makefile
  69. sed -i \
  70. -e "/^CROSS_COMPILE/s:=.*:= ${CHOST}-:" \
  71. -e "/^AR\>/s:=.*:= $(tc-getAR):" \
  72. -e "/^CC\>/s:=.*:= $(tc-getCC):" \
  73. -e "/^HOSTCC/s:=.*:= $(tc-getBUILD_CC):" \
  74. -e "/^PKG_CONFIG\>/s:=.*:= $(tc-getPKG_CONFIG):" \
  75. Makefile || die
  76. sed -i \
  77. -e 's:-static-libgcc::' \
  78. Makefile.flags || die
  79. }
  80. src_configure() {
  81. # check for a busybox config before making one of our own.
  82. # if one exist lets return and use it.
  83. restore_config .config
  84. if [ -f .config ]; then
  85. yes "" | emake -j1 -s oldconfig >/dev/null
  86. return 0
  87. else
  88. ewarn "Could not locate user configfile, so we will save a default one"
  89. fi
  90. # setup the config file
  91. emake -j1 -s allyesconfig >/dev/null
  92. # nommu forces a bunch of things off which we want on #387555
  93. busybox_config_option n NOMMU
  94. sed -i '/^#/d' .config
  95. yes "" | emake -j1 -s oldconfig >/dev/null
  96. # now turn off stuff we really don't want
  97. busybox_config_option n DMALLOC
  98. busybox_config_option n FEATURE_SUID_CONFIG
  99. busybox_config_option n BUILD_AT_ONCE
  100. busybox_config_option n BUILD_LIBBUSYBOX
  101. busybox_config_option n FEATURE_CLEAN_UP
  102. busybox_config_option n MONOTONIC_SYSCALL
  103. busybox_config_option n USE_PORTABLE_CODE
  104. busybox_config_option n WERROR
  105. # triming the BSS size may be dangerous
  106. busybox_config_option n FEATURE_USE_BSS_TAIL
  107. # If these are not set and we are using a uclibc/busybox setup
  108. # all calls to system() will fail.
  109. busybox_config_option y ASH
  110. busybox_config_option n HUSH
  111. # disable ipv6 applets
  112. if ! use ipv6; then
  113. busybox_config_option n FEATURE_IPV6
  114. busybox_config_option n TRACEROUTE6
  115. busybox_config_option n PING6
  116. busybox_config_option n UDHCPC6
  117. fi
  118. busybox_config_option pam PAM
  119. busybox_config_option static STATIC
  120. busybox_config_option syslog {K,SYS}LOGD LOGGER
  121. busybox_config_option systemd FEATURE_SYSTEMD
  122. busybox_config_option math FEATURE_AWK_LIBM
  123. # all the debug options are compiler related, so punt them
  124. busybox_config_option n DEBUG_SANITIZE
  125. busybox_config_option n DEBUG
  126. busybox_config_option y NO_DEBUG_LIB
  127. busybox_config_option n DMALLOC
  128. busybox_config_option n EFENCE
  129. busybox_config_option $(usex debug y n) TFTP_DEBUG
  130. busybox_config_option selinux SELINUX
  131. # this opt only controls mounting with <linux-2.6.23
  132. busybox_config_option n FEATURE_MOUNT_NFS
  133. # default a bunch of uncommon options to off
  134. local opt
  135. for opt in \
  136. ADD_SHELL \
  137. BEEP BOOTCHARTD \
  138. CRONTAB \
  139. DC DEVFSD DNSD DPKG{,_DEB} \
  140. FAKEIDENTD FBSPLASH FOLD FSCK_MINIX FTP{GET,PUT} \
  141. FEATURE_DEVFS \
  142. HOSTID HUSH \
  143. INETD INOTIFYD IPCALC \
  144. LOCALE_SUPPORT LOGNAME LPD \
  145. MAKEMIME MKFS_MINIX MSH \
  146. OD \
  147. RDEV READPROFILE REFORMIME REMOVE_SHELL RFKILL RUN_PARTS RUNSV{,DIR} \
  148. SLATTACH SMEMCAP SULOGIN SV{,LOGD} \
  149. TASKSET TCPSVD \
  150. RPM RPM2CPIO \
  151. UDPSVD UUDECODE UUENCODE
  152. do
  153. busybox_config_option n ${opt}
  154. done
  155. emake -j1 oldconfig > /dev/null
  156. }
  157. src_compile() {
  158. unset KBUILD_OUTPUT #88088
  159. export SKIP_STRIP=y
  160. emake V=1 busybox
  161. }
  162. src_install() {
  163. unset KBUILD_OUTPUT #88088
  164. save_config .config
  165. into /
  166. dodir /bin
  167. if use sep-usr ; then
  168. # install /ginit to take care of mounting stuff
  169. exeinto /
  170. newexe busybox_unstripped ginit
  171. dosym /ginit /bin/bb
  172. dosym bb /bin/busybox
  173. else
  174. newbin busybox_unstripped busybox
  175. dosym busybox /bin/bb
  176. fi
  177. if use mdev ; then
  178. dodir /$(get_libdir)/mdev/
  179. use make-symlinks || dosym /bin/bb /sbin/mdev
  180. cp "${S}"/examples/mdev_fat.conf "${ED}"/etc/mdev.conf
  181. exeinto /$(get_libdir)/mdev/
  182. doexe "${FILESDIR}"/mdev/*
  183. newinitd "${FILESDIR}"/mdev.initd mdev
  184. fi
  185. if use livecd ; then
  186. dosym busybox /bin/vi
  187. fi
  188. # add busybox daemon's, bug #444718
  189. if busybox_config_enabled FEATURE_NTPD_SERVER; then
  190. newconfd "${FILESDIR}/ntpd.confd" "busybox-ntpd"
  191. newinitd "${FILESDIR}/ntpd.initd" "busybox-ntpd"
  192. fi
  193. if busybox_config_enabled SYSLOGD; then
  194. newconfd "${FILESDIR}/syslogd.confd" "busybox-syslogd"
  195. newinitd "${FILESDIR}/syslogd.initd" "busybox-syslogd"
  196. fi
  197. if busybox_config_enabled KLOGD; then
  198. newconfd "${FILESDIR}/klogd.confd" "busybox-klogd"
  199. newinitd "${FILESDIR}/klogd.initd" "busybox-klogd"
  200. fi
  201. if busybox_config_enabled WATCHDOG; then
  202. newconfd "${FILESDIR}/watchdog.confd" "busybox-watchdog"
  203. newinitd "${FILESDIR}/watchdog.initd" "busybox-watchdog"
  204. fi
  205. if busybox_config_enabled UDHCPC; then
  206. local path=$(busybox_config_enabled UDHCPC_DEFAULT_SCRIPT)
  207. exeinto "${path%/*}"
  208. newexe examples/udhcp/simple.script "${path##*/}"
  209. fi
  210. if busybox_config_enabled UDHCPD; then
  211. insinto /etc
  212. doins examples/udhcp/udhcpd.conf
  213. fi
  214. # bundle up the symlink files for use later
  215. emake DESTDIR="${ED}" install
  216. rm _install/bin/busybox
  217. # for compatibility, provide /usr/bin/env
  218. mkdir -p _install/usr/bin
  219. ln -s /bin/env _install/usr/bin/env
  220. tar cf busybox-links.tar -C _install . || : #;die
  221. insinto /usr/share/${PN}
  222. use make-symlinks && doins busybox-links.tar
  223. dodoc AUTHORS README TODO
  224. cd docs
  225. docinto txt
  226. dodoc *.txt
  227. docinto pod
  228. dodoc *.pod
  229. dohtml *.html
  230. cd ../examples
  231. docinto examples
  232. dodoc inittab depmod.pl *.conf *.script undeb unrpm
  233. }
  234. pkg_preinst() {
  235. if use make-symlinks && [[ ! ${VERY_BRAVE_OR_VERY_DUMB} == "yes" ]] && [[ ${ROOT} == "/" ]] ; then
  236. ewarn "setting USE=make-symlinks and emerging to / is very dangerous."
  237. ewarn "it WILL overwrite lots of system programs like: ls bash awk grep (bug 60805 for full list)."
  238. ewarn "If you are creating a binary only and not merging this is probably ok."
  239. ewarn "set env VERY_BRAVE_OR_VERY_DUMB=yes if this is really what you want."
  240. die "silly options will destroy your system"
  241. fi
  242. if use make-symlinks ; then
  243. mv "${ED}"/usr/share/${PN}/busybox-links.tar "${T}"/ || die
  244. fi
  245. }
  246. pkg_postinst() {
  247. savedconfig_pkg_postinst
  248. if use make-symlinks ; then
  249. cd "${T}" || die
  250. mkdir _install
  251. tar xf busybox-links.tar -C _install || die
  252. cp -vpPR _install/* "${ROOT}"/ || die "copying links for ${x} failed"
  253. fi
  254. if use sep-usr ; then
  255. elog "In order to use the sep-usr support, you have to update your"
  256. elog "kernel command line. Add the option:"
  257. elog " init=/ginit"
  258. elog "To launch a different init than /sbin/init, use:"
  259. elog " init=/ginit /sbin/yourinit"
  260. elog "To get a rescue shell, you may boot with:"
  261. elog " init=/ginit bb"
  262. fi
  263. }