recipe 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # Build recipe for llvm.
  2. #
  3. # Copyright (c) 2021-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=llvm
  19. version=15.0.7
  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. tarname_cmake=cmake-${version}.src.tar.xz
  27. tarname_libunwind=libunwind-${version}.src.tar.xz
  28. # Remote source(s)
  29. fetch="
  30. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname
  31. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_clang
  32. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_compilerrt
  33. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_cmake
  34. https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/$tarname_libunwind
  35. "
  36. homepage=https://llvm.org
  37. license="Apachev2 + LLVM exceptions"
  38. description="
  39. The LLVM compiler.
  40. The LLVM Project is a collection of modular and reusable compiler and
  41. toolchain technologies. Despite its name, LLVM has little to do with
  42. traditional virtual machines. The name \"LLVM\" itself is not an
  43. acronym; it is the full name of the project.
  44. For more information, visit: $homepage
  45. "
  46. # Source documentation
  47. docs="CREDITS.TXT LICENSE.TXT README.txt"
  48. docsdir="${docdir}/${program}-${version}"
  49. # Source directory used by this software
  50. srcdir=${program}-${version}.src
  51. build()
  52. {
  53. unpack "${tardir}/$tarname"
  54. unpack "${tardir}/$tarname_cmake"
  55. mv -f cmake-${version}.src cmake
  56. cd "$srcdir"
  57. cd tools
  58. unpack "${tardir}/$tarname_clang"
  59. mv clang-${version}.src clang
  60. cd ../projects
  61. unpack "${tardir}/$tarname_compilerrt"
  62. mv compiler-rt-${version}.src compiler-rt
  63. unpack "${tardir}/$tarname_libunwind"
  64. mv libunwind-${version}.src libunwind
  65. cd ..
  66. unset -v tarname_clang tarname_compilerrt tarname_cmake tarname_libunwind
  67. # Set sane permissions
  68. chmod -R u+w,go-w,a+rX-s .
  69. # Make sure to point to Python version 3 (Thanks to BLFS!)
  70. grep -rl '#!.*python' | xargs sed -i '1s/python$/python3/'
  71. # Apply a patch from "Alpine Linux"
  72. patch -p2 < "${worktree}/patches/llvm/0001-Disable-dynamic-lib-tests-for-musl-s-dlclose-is-noop.patch"
  73. # Another patch from "Alpine Linux" in order to set the installation prefix, *sigh*
  74. patch -p2 < "${worktree}/patches/llvm/install-prefix.patch"
  75. # Enable SSP in Clang by default (Thanks to BLFS!)
  76. (
  77. cd tools/clang && \
  78. patch -Np2 < "${worktree}/patches/llvm/clang-15.0.6-enable_default_ssp-1.patch"
  79. )
  80. # More patches taken from "Chimera Linux" in order to fix ("hell of") build issues
  81. (
  82. cd projects && \
  83. patch -p1 < "${worktree}/patches/llvm/chimera/0022-HACK-force-link-sanitizers-with-libexecinfo.patch"
  84. )
  85. rm -rf BUILD
  86. mkdir BUILD
  87. cd BUILD
  88. # Thanks to "Slackware Linux" for this instructions
  89. mkdir -p include
  90. # Copy this LLVM libunwind header or it won't be found:
  91. cp -Rpf ../projects/libunwind/include/mach-o include
  92. # Nuke LLVM libunwind as it conflicts with the one already on the system:
  93. rm -r ../projects/libunwind
  94. cmake \
  95. -DCMAKE_C_COMPILER="gcc" \
  96. -DCMAKE_CXX_COMPILER="g++" \
  97. -DCMAKE_C_FLAGS_RELEASE:STRING="$QICFLAGS" \
  98. -DCMAKE_CXX_FLAGS_RELEASE:STRING="$QICXXFLAGS" \
  99. -DCMAKE_EXE_LINKER_FLAGS:STRING="$QILDFLAGS" \
  100. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$QILDFLAGS" \
  101. -DCMAKE_INSTALL_PREFIX=/usr \
  102. -DLLVM_LIBDIR_SUFFIX=${libSuffix} \
  103. -DLLVM_BINUTILS_INCDIR=/usr/include \
  104. -DLLVM_TARGETS_TO_BUILD="host;AMDGPU;BPF" \
  105. -DLLVM_USE_LINKER=gold \
  106. -DCMAKE_INSTALL_MANDIR=$mandir \
  107. -DCMAKE_INSTALL_DOCDIR=$docsdir \
  108. -DCMAKE_BUILD_TYPE=Release \
  109. -DLLVM_BUILD_LLVM_DYLIB=ON \
  110. -DLLVM_LINK_LLVM_DYLIB=ON \
  111. -DCLANG_LINK_CLANG_DYLIB=ON \
  112. -DLLVM_ENABLE_FFI=ON \
  113. -DLLVM_ENABLE_RTTI=ON \
  114. -DLLVM_ENABLE_ZLIB=ON \
  115. -DLLVM_INSTALL_UTILS=ON \
  116. -DLLVM_ENABLE_ASSERTIONS=OFF \
  117. -DLLVM_APPEND_VC_REV=OFF \
  118. -DLLVM_PARALLEL_COMPILE_JOBS=$jobs \
  119. -DLLVM_INCLUDE_BENCHMARKS=OFF \
  120. -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
  121. -G Ninja ..
  122. ninja -j${jobs}
  123. DESTDIR="$destdir" ninja -j${jobs} install
  124. # Strip ELF executables only excluding shared objects
  125. find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
  126. cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  127. # Strip static libraries in order to reduce the package size
  128. find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
  129. cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
  130. # Compress and link man pages (if needed)
  131. if test -d "${destdir}/$mandir"
  132. then
  133. (
  134. cd "${destdir}/$mandir"
  135. find . -type f -exec lzip -9 {} +
  136. find . -type l | while read -r file
  137. do
  138. ln -sf "$(readlink -- "$file").lz" "${file}.lz"
  139. rm -- "$file"
  140. done
  141. )
  142. fi
  143. cd ../
  144. # Copy documentation
  145. mkdir -p "${destdir}/$docsdir"
  146. cp -p $docs "${destdir}/$docsdir"
  147. }