recipe 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Build recipe for musl.
  2. #
  3. # Copyright (c) 2015-2023 Matias Fonzo, <selk@dragora.org>.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Exit immediately on any error
  17. set -e
  18. program=musl
  19. version=1.2.3
  20. release=6
  21. # Define a category for the output of the package name
  22. pkgcategory=libs
  23. tarname=${program}-${version}.tar.gz
  24. # Remote source(s)
  25. fetch=https://www.musl-libc.org/releases/$tarname
  26. #fetch="
  27. # https://dragora.mirror.garr.it/current/sources/$tarname
  28. # rsync://rsync.dragora.org/current/sources/$tarname
  29. #"
  30. description="
  31. A powerful standard C/POSIX library (version $version).
  32. Musl is a new standard library to power a new generation of Linux-based
  33. devices. Musl is lightweight, fast, simple, free, and strives to be
  34. correct in the sense of standards-conformance and safety.
  35. "
  36. homepage=https://www.musl-libc.org
  37. license="MIT Expat variant"
  38. # Source documentation
  39. docs="COPYRIGHT README VERSION WHATSNEW"
  40. docsdir="${docdir}/${program}"
  41. # Limit package name to the program name
  42. full_pkgname="${program}@${pkgcategory}"
  43. build()
  44. {
  45. unpack "${tardir}/$tarname"
  46. cd "$srcdir"
  47. # Set sane permissions
  48. chmod -R u+w,go-w,a+rX-s .
  49. patch -Np0 -i "${worktree}/patches/musl/musl-utmp_path.diff"
  50. #patch -Np1 -i "${worktree}/patches/musl/branch-updates.diff"
  51. # Fix debugger tracking of shared libraries on mips with PIE main program
  52. patch -Np1 -i "${worktree}/patches/musl/f897461d4fe72bb71854a6d0662de83008caccb7"
  53. # Fix wrong sigaction syscall ABI on mips*, or1k, microblaze, riscv64
  54. patch -Np1 -i "${worktree}/patches/musl/269d193820342dc109f39909d78fb30f4c978f76"
  55. # Support DT_RELR relative relocation format
  56. patch -Np1 -i "${worktree}/patches/musl/d32dadd60efb9d3b255351a3b532f8e4c3dd0db1"
  57. # Process DT_RELR relocations in ldso-startup/static-pie
  58. patch -Np1 -i "${worktree}/patches/musl/6f3ead0ae16deb9f0004b275e29a276c9712ee3c"
  59. # Fix double-processing of DT_RELR relocations in ldso relocating itself
  60. patch -Np1 -i "${worktree}/patches/musl/29e4319178cbc2a4e9f058a99ae8098d4b6ac055"
  61. # Do not use the compiler runtime library from the temporary system,
  62. # the toolchain must be adjusted until the native GCC take place
  63. if cc -print-libgcc-file-name | grep -q '^/tools'
  64. then
  65. patch -Np1 -i "${worktree}/patches/musl/musl-nolibcc_stage1.diff"
  66. fi
  67. ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
  68. $configure_args \
  69. --libdir=/usr/lib${libSuffix} \
  70. --syslibdir=/lib \
  71. --enable-shared \
  72. --enable-static \
  73. --enable-optimize \
  74. --enable-debug
  75. make -j${jobs}
  76. make -j${jobs} install DESTDIR="$destdir"
  77. # Provide minimal libssp_nonshared.a
  78. cc -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
  79. -o __stack_chk_fail_local.o
  80. ar rc libssp_nonshared.a __stack_chk_fail_local.o
  81. ranlib libssp_nonshared.a
  82. cp -p libssp_nonshared.a "${destdir}/usr/lib${libSuffix}"
  83. strip -g "${destdir}/usr/lib${libSuffix}/libssp_nonshared.a"
  84. # To print shared library dependencies
  85. mkdir -p "${destdir}/usr/bin"
  86. ln -sf /usr/lib${libSuffix}/libc.so "${destdir}/usr/bin/ldd"
  87. # Create dynamic linker runtime file taking -$(ARCH) as reference
  88. for file in "${destdir}"/lib/ld-musl-*.so.1
  89. do
  90. ld_path="${file##*/}" # Basename
  91. ld_path="${ld_path%%.so.1}.path" # Get the rid of .so.1
  92. export ld_path
  93. break;
  94. done
  95. unset -v file
  96. if test -n "$ld_path"
  97. then
  98. mkdir -p "${destdir}/etc"
  99. if test -n "$libSuffix"
  100. then
  101. cat << EOF > "${destdir}"/etc/$ld_path
  102. /lib
  103. /lib${libSuffix}
  104. /usr/local/lib
  105. /usr/local/lib${libSuffix}
  106. /usr/lib
  107. /usr/lib${libSuffix}
  108. /usr/$(gcc -dumpmachine)/lib
  109. /opt/trinity/lib
  110. /opt/trinity/lib${libSuffix}
  111. /opt/trinity/lib/trinity
  112. /opt/trinity/lib${libSuffix}/trinity
  113. EOF
  114. else
  115. cat << EOF > "${destdir}"/etc/$ld_path
  116. /lib
  117. /usr/local/lib
  118. /usr/lib
  119. /usr/$(gcc -dumpmachine)/lib
  120. /opt/trinity/lib
  121. /opt/trinity/lib/trinity
  122. EOF
  123. fi
  124. chmod 644 "${destdir}"/etc/$ld_path
  125. touch "${destdir}/etc/.graft-config"
  126. else
  127. echo "WARNING: \$ld_path is empty." 1>&2
  128. fi
  129. # Add to the post-install script a symlink for compatibility,
  130. # as some 'configure' scripts still have the Glibc name "ld.so.conf".
  131. mkdir -p "${destdir}/var/lib/qi"
  132. cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"
  133. # Adjust the toolchain only once (as needed)
  134. if test -x /tools/bin/adjust-toolchain
  135. then
  136. /tools/bin/adjust-toolchain && chmod 644 /tools/bin/adjust-toolchain
  137. fi
  138. # A symlink for compatibility
  139. if test ! -e "\${rootdir}/etc/ld.so.conf"
  140. then
  141. ( cd -- "\${rootdir}/etc" && ln -sf $ld_path ld.so.conf )
  142. fi
  143. EOF
  144. unset -v ld_path
  145. # Copy documentation
  146. mkdir -p "${destdir}/$docsdir"
  147. cp -p $docs "${destdir}/$docsdir"
  148. }