musl-9999.ebuild 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # Copyright 1999-2024 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=8
  4. inherit crossdev flag-o-matic toolchain-funcs prefix
  5. DESCRIPTION="Light, fast and simple C library focused on standards-conformance and safety"
  6. HOMEPAGE="https://musl.libc.org"
  7. if [[ ${PV} == "9999" ]] ; then
  8. EGIT_REPO_URI="https://git.musl-libc.org/git/musl"
  9. inherit git-r3
  10. else
  11. VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/musl.asc
  12. inherit verify-sig
  13. SRC_URI="https://musl.libc.org/releases/${P}.tar.gz"
  14. SRC_URI+=" verify-sig? ( https://musl.libc.org/releases/${P}.tar.gz.asc )"
  15. KEYWORDS="-* ~amd64 ~arm ~arm64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~x86"
  16. BDEPEND="verify-sig? ( sec-keys/openpgp-keys-musl )"
  17. fi
  18. GETENT_COMMIT="93a08815f8598db442d8b766b463d0150ed8e2ab"
  19. GETENT_FILE="musl-getent-${GETENT_COMMIT}.c"
  20. SRC_URI+="
  21. https://dev.gentoo.org/~blueness/musl-misc/getconf.c
  22. https://gitlab.alpinelinux.org/alpine/aports/-/raw/${GETENT_COMMIT}/main/musl/getent.c -> ${GETENT_FILE}
  23. https://dev.gentoo.org/~blueness/musl-misc/iconv.c
  24. "
  25. LICENSE="MIT LGPL-2 GPL-2"
  26. SLOT="0"
  27. IUSE="crypt headers-only split-usr"
  28. QA_SONAME="usr/lib/libc.so"
  29. QA_DT_NEEDED="usr/lib/libc.so"
  30. # bug #830213
  31. QA_PRESTRIPPED="usr/lib/crtn.o"
  32. # We want crypt on by default for this as sys-libs/libxcrypt isn't (yet?)
  33. # built as part as crossdev. Also, elide the blockers when in cross-*,
  34. # as it doesn't make sense to block the normal CBUILD libxcrypt at all
  35. # there when we're installing into /usr/${CHOST} anyway.
  36. if is_crosspkg ; then
  37. IUSE="${IUSE/crypt/+crypt}"
  38. else
  39. RDEPEND="crypt? ( !sys-libs/libxcrypt[system] )"
  40. PDEPEND="!crypt? ( sys-libs/libxcrypt[system] )"
  41. fi
  42. PATCHES=(
  43. "${FILESDIR}"/musl-1.2.4-libcompat_time32.patch
  44. "${FILESDIR}"/musl-1.2.4-elfutils-0.190-relr.patch
  45. "${FILESDIR}"/musl-1.2.2-gethostid.patch
  46. "${FILESDIR}"/Make-scheduler-functions-Linux-compatible.patch
  47. "${FILESDIR}"/Add-rpmalloc-for-musl.patch
  48. "${FILESDIR}"/use-optimized-memcpy-memset.patch
  49. "${FILESDIR}"/fix-strdupa.patch
  50. )
  51. just_headers() {
  52. use headers-only && target_is_not_host
  53. }
  54. pkg_setup() {
  55. if [[ ${CTARGET} == ${CHOST} ]] ; then
  56. case ${CHOST} in
  57. *-musl*) ;;
  58. *) die "Use sys-devel/crossdev to build a musl toolchain" ;;
  59. esac
  60. fi
  61. # Fix for bug #667126, copied from glibc ebuild:
  62. # make sure host make.conf doesn't pollute us
  63. if target_is_not_host || tc-is-cross-compiler ; then
  64. CHOST=${CTARGET} strip-unsupported-flags
  65. fi
  66. }
  67. src_unpack() {
  68. if [[ ${PV} == 9999 ]] ; then
  69. git-r3_src_unpack
  70. elif use verify-sig ; then
  71. # We only verify the release; not the additional (fixed, safe) files
  72. # we download.
  73. # (Seem to get IPC error on verifying in cross?)
  74. ! target_is_not_host && verify-sig_verify_detached "${DISTDIR}"/${P}.tar.gz{,.asc}
  75. fi
  76. default
  77. }
  78. src_prepare() {
  79. default
  80. mkdir "${WORKDIR}"/misc || die
  81. cp "${DISTDIR}"/getconf.c "${WORKDIR}"/misc/getconf.c || die
  82. cp "${DISTDIR}/${GETENT_FILE}" "${WORKDIR}"/misc/getent.c || die
  83. cp "${DISTDIR}"/iconv.c "${WORKDIR}"/misc/iconv.c || die
  84. }
  85. src_configure() {
  86. strip-flags && filter-lto # Prevent issues caused by aggressive optimizations & bug #877343
  87. tc-getCC ${CTARGET}
  88. just_headers && export CC=true
  89. local sysroot
  90. target_is_not_host && sysroot=/usr/${CTARGET}
  91. ./configure \
  92. --target=${CTARGET} \
  93. --prefix="${EPREFIX}${sysroot}/usr" \
  94. --syslibdir="${EPREFIX}${sysroot}/lib" \
  95. --with-malloc=rpmalloc \
  96. --disable-gcc-wrapper || die
  97. }
  98. src_compile() {
  99. emake obj/include/bits/alltypes.h
  100. just_headers && return 0
  101. emake
  102. if ! is_crosspkg ; then
  103. emake -C "${T}" getconf getent iconv \
  104. CC="$(tc-getCC)" \
  105. CFLAGS="${CFLAGS}" \
  106. CPPFLAGS="${CPPFLAGS}" \
  107. LDFLAGS="${LDFLAGS}" \
  108. VPATH="${WORKDIR}/misc"
  109. fi
  110. $(tc-getCC) ${CPPFLAGS} ${CFLAGS} -c -o libssp_nonshared.o "${FILESDIR}"/stack_chk_fail_local.c || die
  111. $(tc-getAR) -rcs libssp_nonshared.a libssp_nonshared.o || die
  112. }
  113. src_install() {
  114. local target="install"
  115. just_headers && target="install-headers"
  116. emake DESTDIR="${D}" ${target}
  117. just_headers && return 0
  118. # musl provides ldd via a sym link to its ld.so
  119. local sysroot=
  120. target_is_not_host && sysroot=/usr/${CTARGET}
  121. local ldso=$(basename "${ED}${sysroot}"/lib/ld-musl-*)
  122. dosym -r "${sysroot}/lib/${ldso}" "${sysroot}/usr/bin/ldd"
  123. if ! use crypt ; then
  124. # Allow sys-libs/libxcrypt[system] to provide it instead
  125. rm "${ED}/usr/include/crypt.h" || die
  126. rm "${ED}/usr/$(get_libdir)/libcrypt.a" || die
  127. fi
  128. if ! is_crosspkg ; then
  129. # Fish out of config:
  130. # ARCH = ...
  131. # SUBARCH = ...
  132. # and print $(ARCH)$(SUBARCH).
  133. local arch=$(awk '{ k[$1] = $3 } END { printf("%s%s", k["ARCH"], k["SUBARCH"]); }' config.mak)
  134. # The musl build system seems to create a symlink:
  135. # ${D}/lib/ld-musl-${arch}.so.1 -> /usr/lib/libc.so.1 (absolute)
  136. # During cross or within prefix, there's no guarantee that the host is
  137. # using musl so that file may not exist. Use a relative symlink within
  138. # ${D} instead.
  139. rm "${ED}"/lib/ld-musl-${arch}.so.1 || die
  140. if use split-usr; then
  141. dosym ../usr/lib/libc.so /lib/ld-musl-${arch}.so.1
  142. # If it's still a dead symlink, OK, we really do need to abort.
  143. [[ -e "${ED}"/lib/ld-musl-${arch}.so.1 ]] || die
  144. else
  145. dosym libc.so /usr/lib/ld-musl-${arch}.so.1
  146. [[ -e "${ED}"/usr/lib/ld-musl-${arch}.so.1 ]] || die
  147. fi
  148. cp "${FILESDIR}"/ldconfig.in-r3 "${T}"/ldconfig.in || die
  149. sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die
  150. eprefixify "${T}"/ldconfig
  151. into /
  152. dosbin "${T}"/ldconfig
  153. into /usr
  154. dobin "${T}"/getconf
  155. dobin "${T}"/getent
  156. dobin "${T}"/iconv
  157. echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00musl || die
  158. doenvd "${T}"/00musl
  159. fi
  160. if target_is_not_host ; then
  161. into /usr/${CTARGET}
  162. dolib.a libssp_nonshared.a
  163. else
  164. dolib.a libssp_nonshared.a
  165. fi
  166. }
  167. pkg_preinst() {
  168. # Nothing to do if just installing headers
  169. just_headers && return
  170. # Prepare /etc/ld.so.conf.d/ for files
  171. mkdir -p "${EROOT}"/etc/ld.so.conf.d
  172. }
  173. pkg_postinst() {
  174. target_is_not_host && return 0
  175. [[ -n "${ROOT}" ]] && return 0
  176. ldconfig || die
  177. }