recipe 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Build recipe for llvm.
  2. #
  3. # Copyright (c) 2021-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=llvm
  19. version=13.0.1
  20. release=1
  21. # Define a category for the output of the package name
  22. pkgcategory=devel
  23. tarname=${program}-${version}.src.tar.xz
  24. tarname_clang=clang-${version}.src.tar.xz
  25. tarname_compilerrt=compiler-rt-${version}.src.tar.xz
  26. # Remote source(s)
  27. fetch="
  28. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname
  29. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_clang
  30. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_compilerrt
  31. "
  32. homepage=https://llvm.org
  33. license="Apachev2 + LLVM exceptions"
  34. description="
  35. The LLVM compiler.
  36. The LLVM Project is a collection of modular and reusable compiler and
  37. toolchain technologies. Despite its name, LLVM has little to do with
  38. traditional virtual machines. The name \"LLVM\" itself is not an
  39. acronym; it is the full name of the project.
  40. For more information, visit: $homepage
  41. "
  42. # Source documentation
  43. docs="CREDITS.TXT LICENSE.TXT README.txt"
  44. docsdir="${docdir}/${program}-${version}"
  45. # Source directory used by this software
  46. srcdir=${program}-${version}.src
  47. build()
  48. {
  49. unpack "${tardir}/$tarname"
  50. cd "$srcdir"
  51. cd tools
  52. unpack "${tardir}/$tarname_clang"
  53. mv clang-${version}.src clang
  54. cd ../projects
  55. unpack "${tardir}/$tarname_compilerrt"
  56. mv compiler-rt-${version}.src compiler-rt
  57. cd ..
  58. unset -v tarname_clang tarname_compilerrt
  59. # Set sane permissions
  60. chmod -R u+w,go-w,a+rX-s .
  61. # Make sure to point to Python version 3 (Thanks to BLFS!)
  62. grep -rl '#!.*python' | xargs sed -i '1s/python$/python3/'
  63. # Set the SANITIZER flag to TRUE for Musl
  64. patch -p0 < "${worktree}/patches/llvm/compiler_rt_sanitizer.diff"
  65. rm -rf BUILD
  66. mkdir BUILD
  67. cd BUILD
  68. cmake CC=gcc CXX=g++ \
  69. -DCMAKE_C_FLAGS_RELEASE:STRING="$QICFLAGS" \
  70. -DCMAKE_CXX_FLAGS_RELEASE:STRING="$QICXXFLAGS" \
  71. -DCMAKE_EXE_LINKER_FLAGS:STRING="$QILDFLAGS -Wl,--no-keep-memory" \
  72. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$QILDFLAGS -Wl,--no-keep-memory" \
  73. -DCMAKE_INSTALL_PREFIX=/usr \
  74. -DLLVM_LIBDIR_SUFFIX=${libSuffix} \
  75. -DLLVM_BINUTILS_INCDIR=/usr/include \
  76. -DCMAKE_INSTALL_MANDIR=$mandir \
  77. -DCMAKE_INSTALL_DOCDIR=$docsdir \
  78. -DCMAKE_BUILD_TYPE=Release \
  79. -DLLVM_BUILD_LLVM_DYLIB=ON \
  80. -DLLVM_LINK_LLVM_DYLIB=ON \
  81. -DLLVM_ENABLE_FFI=ON \
  82. -DLLVM_ENABLE_RTTI=ON \
  83. -DLLVM_ENABLE_ZLIB=ON \
  84. -DLLVM_INSTALL_UTILS=ON \
  85. -DLLVM_ENABLE_ASSERTIONS=OFF \
  86. -DLLVM_APPEND_VC_REV=OFF \
  87. -DLLVM_PARALLEL_COMPILE_JOBS=$jobs \
  88. -DLLVM_INCLUDE_BENCHMARKS=OFF \
  89. -G Ninja ..
  90. ninja -j${jobs}
  91. DESTDIR="$destdir" ninja -j${jobs} install
  92. # Strip ELF executables only excluding shared objects
  93. find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
  94. cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  95. # Strip static libraries in order to reduce the package size
  96. find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
  97. cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
  98. # Compress and link man pages (if needed)
  99. if test -d "${destdir}/$mandir"
  100. then
  101. (
  102. cd "${destdir}/$mandir"
  103. find . -type f -exec lzip -9 {} +
  104. find . -type l | while read -r file
  105. do
  106. ln -sf "$(readlink -- "$file").lz" "${file}.lz"
  107. rm -- "$file"
  108. done
  109. )
  110. fi
  111. cd ../
  112. # Copy documentation
  113. mkdir -p "${destdir}/$docsdir"
  114. cp -p $docs "${destdir}/$docsdir"
  115. }