recipe 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Build recipe for musl.
  2. #
  3. # Copyright (c) 2015-2022 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=1
  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. # Do not use the compiler runtime library from the temporary system,
  52. # the toolchain must be adjusted until the native GCC take place
  53. if cc -print-libgcc-file-name | grep -q '^/tools'
  54. then
  55. patch -Np1 -i "${worktree}/patches/musl/musl-nolibcc_stage1.diff"
  56. fi
  57. ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
  58. $configure_args \
  59. --libdir=/usr/lib${libSuffix} \
  60. --syslibdir=/lib \
  61. --enable-shared \
  62. --enable-static \
  63. --enable-optimize
  64. make -j${jobs}
  65. make -j${jobs} install DESTDIR="$destdir"
  66. # Provide minimal libssp_nonshared.a
  67. cc -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
  68. -o __stack_chk_fail_local.o
  69. ar rc libssp_nonshared.a __stack_chk_fail_local.o
  70. ranlib libssp_nonshared.a
  71. cp -p libssp_nonshared.a "${destdir}/usr/lib${libSuffix}"
  72. strip -g "${destdir}/usr/lib${libSuffix}/libssp_nonshared.a"
  73. # To print shared library dependencies
  74. mkdir -p "${destdir}/usr/bin"
  75. ln -sf /usr/lib${libSuffix}/libc.so "${destdir}/usr/bin/ldd"
  76. # Create dynamic linker runtime file taking -$(ARCH) as reference
  77. for file in "${destdir}"/lib/ld-musl-*.so.1
  78. do
  79. ld_path="${file##*/}" # Basename
  80. ld_path="${ld_path%%.so.1}.path" # Get the rid of .so.1
  81. export ld_path
  82. break;
  83. done
  84. unset -v file
  85. if test -n "$ld_path"
  86. then
  87. mkdir -p "${destdir}/etc"
  88. if test -n "$libSuffix"
  89. then
  90. cat << EOF > "${destdir}"/etc/$ld_path
  91. /lib
  92. /lib${libSuffix}
  93. /usr/local/lib
  94. /usr/local/lib${libSuffix}
  95. /usr/lib
  96. /usr/lib${libSuffix}
  97. /usr/$(gcc -dumpmachine)/lib
  98. /opt/trinity/lib
  99. /opt/trinity/lib${libSuffix}
  100. /opt/trinity/lib/trinity
  101. /opt/trinity/lib${libSuffix}/trinity
  102. EOF
  103. else
  104. cat << EOF > "${destdir}"/etc/$ld_path
  105. /lib
  106. /usr/local/lib
  107. /usr/lib
  108. /usr/$(gcc -dumpmachine)/lib
  109. /opt/trinity/lib
  110. /opt/trinity/lib/trinity
  111. EOF
  112. fi
  113. chmod 644 "${destdir}"/etc/$ld_path
  114. touch "${destdir}/etc/.graft-config"
  115. else
  116. echo "WARNING: \$ld_path is empty." 1>&2
  117. fi
  118. # Add to the post-install script a symlink for compatibility,
  119. # as some 'configure' scripts still have the Glibc name "ld.so.conf".
  120. mkdir -p "${destdir}/var/lib/qi"
  121. cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"
  122. # Adjust the toolchain only once (as needed)
  123. if test -x /tools/bin/adjust-toolchain
  124. then
  125. /tools/bin/adjust-toolchain && chmod 644 /tools/bin/adjust-toolchain
  126. fi
  127. # A symlink for compatibility
  128. if test ! -e "\${rootdir}/etc/ld.so.conf"
  129. then
  130. ( cd -- "\${rootdir}/etc" && ln -sf $ld_path ld.so.conf )
  131. fi
  132. EOF
  133. unset -v ld_path
  134. # Copy documentation
  135. mkdir -p "${destdir}/$docsdir"
  136. cp -p $docs "${destdir}/$docsdir"
  137. }