busybox-9999.ebuild 8.7 KB

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