pkgname=clang pkgver=19.1.6 pkgrel=2 pkgdesc="C language family frontend for LLVM" arch=('x86_64') url="https://clang.llvm.org/" license=('Apache-2.0 WITH LLVM-exception') depends=('llvm-libs' 'gcc' 'compiler-rt') makedepends=('llvm' 'cmake' 'ninja' 'python-sphinx' 'python-myst-parser') options=('!emptydirs') source=(https://github.com/llvm/llvm-project/releases/download/llvmorg-${pkgver}/clang-${pkgver}.src.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${pkgver}/clang-tools-extra-${pkgver}.src.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${pkgver}/llvm-${pkgver}.src.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${pkgver}/cmake-${pkgver}.src.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${pkgver}/third-party-${pkgver}.src.tar.xz enable-fstack-protector-strong-by-default.patch) sha256sums=(6358cbb3e14687ca2f3465c61cffc65589b448aaa912ec2c163ef9fc046e8a89 417a7d0048d8eb62dbaa8461f1fd474eb6493b09e14d050b39cc1f051e8b71d1 ad1a3b125ff014ded290094088de40efb9193ce81a24278184230b7d401f8a3e 9c7ec82d9a240dc2287b8de89d6881bb64ceea0dcd6ce133c34ef65bda22d99e 0e8048333bab2ba3607910e5d074259f08dccf00615778d03a2a55416718eb45 ef319e65f927718e1d3b1a23c480d686b1d292e2a0bf27229540964f9734117a) # Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid # installing static libraries; inspired by Gentoo _get_distribution_components() { local target ninja -C flarebird-build -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do case ${target} in clang-libraries|distribution) continue ;; clang|clangd|clang-*) ;; clang*|findAllSymbols) continue ;; esac echo ${target} done } prepare() { rename -v -- "-${pkgver}.src" '' {cmake,third-party}-${pkgver}.src cd clang-${pkgver}.src mv ${srcdir}/clang-tools-extra-${pkgver}.src tools/extra patch -Np2 -i ${srcdir}/enable-fstack-protector-strong-by-default.patch # Fix hardcoded test path sed -i 's/clang-tools-extra/tools\/extra/g' tools/extra/test/clang-doc/enum.cpp sed -i 's/clang-tools-extra/tools\/extra/g' tools/extra/test/clang-doc/namespace.cpp } build() { cd clang-${pkgver}.src # Build only minimal debug info to reduce size CFLAGS=${CFLAGS/-g /-g1 } CXXFLAGS=${CXXFLAGS/-g /-g1 } local cmake_args=( -B flarebird-build -G Ninja -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr -D LLVM_LIBDIR_SUFFIX=64 -D CMAKE_INSTALL_DOCDIR=share/doc -D CMAKE_SKIP_RPATH=ON -D CLANG_DEFAULT_PIE_ON_LINUX=ON -D CLANG_LINK_CLANG_DYLIB=ON -D ENABLE_LINKER_BUILD_ID=ON -D LLVM_BUILD_DOCS=ON -D LLVM_BUILD_TESTS=ON -D LLVM_ENABLE_RTTI=ON -D LLVM_ENABLE_SPHINX=ON -D LLVM_EXTERNAL_LIT=/usr/bin/lit -D LLVM_INCLUDE_DOCS=ON -D LLVM_LINK_LLVM_DYLIB=ON -D LLVM_MAIN_SRC_DIR="${srcdir}/llvm-${pkgver}.src" -D SPHINX_WARNINGS_AS_ERRORS=OFF -D CLANG_VENDOR=Flarebird ) cmake ${cmake_args[@]} local distribution_components=$(`_get_distribution_components | paste -sd\;`) test -n ${distribution_components} cmake_args+=(-DLLVM_DISTRIBUTION_COMPONENTS=${distribution_components}) cmake ${cmake_args[@]} ninja -C flarebird-build } _python_optimize() { python3 -m compileall "$@" python3 -O -m compileall "$@" python3 -OO -m compileall "$@" } package() { cd clang-${pkgver}.src DESTDIR=${pkgdir} ninja -C flarebird-build install # Remove documentation sources rm -r ${pkgdir}/usr/share/doc/clang{,-tools}/html/{_sources,.buildinfo} # Move scanbuild-py into site-packages and install Python bindings local site_packages=$(python3 -c "import site; print(site.getsitepackages()[0])") install -d ${pkgdir}/${site_packages} mv ${pkgdir}/usr/lib/{libear,libscanbuild} ${pkgdir}/${site_packages}/ cp -a bindings/python/clang ${pkgdir}/${site_packages}/ # ln -sv clang ${pkgdir}/usr/bin/${CHOST}-clang # ln -sv clang++ ${pkgdir}/usr/bin/${CHOST}-clang++ }