musl-9999.ebuild 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. inherit eutils flag-o-matic multilib toolchain-funcs
  5. if [[ ${PV} == "9999" ]] ; then
  6. EGIT_REPO_URI="git://git.musl-libc.org/musl"
  7. inherit git-r3
  8. SRC_URI="
  9. http://dev.gentoo.org/~blueness/musl-misc/getconf.c
  10. http://dev.gentoo.org/~blueness/musl-misc/getent.c
  11. http://dev.gentoo.org/~blueness/musl-misc/iconv.c"
  12. KEYWORDS=""
  13. else
  14. SRC_URI="http://www.musl-libc.org/releases/${P}.tar.gz
  15. http://dev.gentoo.org/~blueness/musl-misc/getconf.c
  16. http://dev.gentoo.org/~blueness/musl-misc/getent.c
  17. http://dev.gentoo.org/~blueness/musl-misc/iconv.c"
  18. KEYWORDS="-* ~amd64 ~arm ~mips ~ppc ~x86"
  19. fi
  20. export CBUILD=${CBUILD:-${CHOST}}
  21. export CTARGET=${CTARGET:-${CHOST}}
  22. if [[ ${CTARGET} == ${CHOST} ]] ; then
  23. if [[ ${CATEGORY} == cross-* ]] ; then
  24. export CTARGET=${CATEGORY#cross-}
  25. fi
  26. fi
  27. DESCRIPTION="Light, fast and simple C library focused on standards-conformance and safety"
  28. HOMEPAGE="http://www.musl-libc.org/"
  29. LICENSE="MIT LGPL-2 GPL-2"
  30. SLOT="0"
  31. IUSE="crosscompile_opts_headers-only"
  32. QA_SONAME="/usr/lib/libc.so"
  33. QA_DT_NEEDED="/usr/lib/libc.so"
  34. is_crosscompile() {
  35. [[ ${CHOST} != ${CTARGET} ]]
  36. }
  37. just_headers() {
  38. use crosscompile_opts_headers-only && is_crosscompile
  39. }
  40. pkg_setup() {
  41. if [ ${CTARGET} == ${CHOST} ] ; then
  42. case ${CHOST} in
  43. *-musl*) ;;
  44. *) die "Use sys-devel/crossdev to build a musl toolchain" ;;
  45. esac
  46. fi
  47. }
  48. src_configure() {
  49. tc-getCC ${CTARGET}
  50. just_headers && export CC=true
  51. local sysroot
  52. is_crosscompile && sysroot=/usr/${CTARGET}
  53. ./configure \
  54. --target=${CTARGET} \
  55. --prefix=${sysroot}/usr \
  56. --syslibdir=${sysroot}/lib \
  57. --disable-gcc-wrapper || die
  58. }
  59. src_compile() {
  60. emake obj/include/bits/alltypes.h
  61. just_headers && return 0
  62. emake
  63. $(tc-getCC) ${CFLAGS} "${DISTDIR}"/getconf.c -o "${T}"/getconf || die
  64. $(tc-getCC) ${CFLAGS} "${DISTDIR}"/getent.c -o "${T}"/getent || die
  65. $(tc-getCC) ${CFLAGS} "${DISTDIR}"/iconv.c -o "${T}"/iconv || die
  66. }
  67. src_install() {
  68. local target="install"
  69. just_headers && target="install-headers"
  70. emake DESTDIR="${D}" ${target}
  71. just_headers && return 0
  72. # musl provides ldd via a sym link to its ld.so
  73. local sysroot
  74. is_crosscompile && sysroot=/usr/${CTARGET}
  75. local ldso=$(basename "${D}"${sysroot}/lib/ld-musl-*)
  76. dosym ${sysroot}/lib/${ldso} ${sysroot}/usr/bin/ldd
  77. if [[ ${CATEGORY} != cross-* ]] ; then
  78. local arch=$("${D}"usr/lib/libc.so 2>&1 | sed -n '1s/^musl libc (\(.*\))$/\1/p')
  79. [[ -e "${D}"/lib/ld-musl-${arch}.so.1 ]] || die
  80. cp "${FILESDIR}"/ldconfig.in "${T}" || die
  81. sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die
  82. into /
  83. dosbin "${T}"/ldconfig
  84. into /usr
  85. dobin "${T}"/getconf
  86. dobin "${T}"/getent
  87. dobin "${T}"/iconv
  88. echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00musl || die
  89. doenvd "${T}"/00musl || die
  90. fi
  91. }
  92. pkg_postinst() {
  93. is_crosscompile && return 0
  94. [ "${ROOT}" != "/" ] && return 0
  95. ldconfig || die
  96. # reload init ...
  97. /sbin/telinit U 2>/dev/null
  98. }