# Contributor Eric Molitor # Contributor Patrick Gansterer # Contributor Travis Tilley # Contributor omni # Maintainer: Natanael Copa pkgname=clang16 pkgver=16.0.6 pkgrel=3 _llvmver=${pkgver%%.*} pkgdesc="C language family front-end for LLVM" arch="all" url="https://llvm.org/" license="Apache-2.0 WITH LLVM-exception" options="!check" # fail to build install="$pkgname.pre-upgrade" makedepends=" cmake help2man libxml2-dev llvm$_llvmver-dev llvm$_llvmver-static llvm$_llvmver-test-utils samurai python3 " checkdepends="diffutils bash gtest-dev" depends_dev="$pkgname=$pkgver-r$pkgrel" subpackages=" $pkgname-static $pkgname-headers $pkgname-libclang $pkgname-libs $pkgname-dev $pkgname-ccache $pkgname-extra-tools:extra " 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/cmake-$pkgver.src.tar.xz 10-add-musl-triples.patch 30-Enable-stack-protector-by-default-for-Alpine-Linux.patch clang-default-fno-semantic-interposition.patch clang-001-fortify-include.patch clang-002-fortify-enable.patch clang-003-as-needed.patch 9008-Clang-Support-more-stdio-builtins.patch 9012-Call-printName-to-get-name-of-Decl.patch " builddir="$srcdir/clang-$pkgver.src" prepare() { mv "$srcdir/clang-tools-extra-$pkgver.src" "$builddir/tools/extra" default_prepare mv "$srcdir"/cmake-${pkgver//_/}.src "$srcdir"/cmake } # Whether is this package the default (latest) clang version. _default_clang="yes" if [ "$_default_clang" = yes ]; then subpackages=" $subpackages $pkgname-doc $pkgname-analyzer::noarch $pkgname-bash-completion:bash:noarch $pkgname-emacs::noarch py3-$pkgname:python:noarch " provides="clang=$pkgver-r$pkgrel" replaces="clang" depends_dev="$depends_dev $pkgname-extra-tools=$pkgver-r$pkgrel" fi build() { local python_version=$(python3 -V | sed 's/.*\([0-9]\{1,\}\.[0-9]\{1,\}\)\..*/\1/') if [ $_default_clang = yes ]; then local extras=ON else local extras=OFF fi cmake -B build -G Ninja -Wno-dev \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm$_llvmver \ -DCMAKE_MODULE_PATH="$srcdir/cmake-$pkgver.src/Modules" \ -DCLANG_BUILT_STANDALONE=ON \ -DCLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang$_llvmver \ -DCLANG_ENABLE_ARCMT=$extras \ -DCLANG_ENABLE_STATIC_ANALYZER=$extras \ -DCLANG_INCLUDE_TESTS="$(want_check && echo ON || echo OFF)" \ -DCMAKE_INSTALL_RPATH=/usr/lib/llvm$_llvmver/lib \ -DCLANG_LINK_CLANG_DYLIB=ON \ -DCLANG_PLUGIN_SUPPORT=ON \ -DCLANG_PYTHON_BINDINGS_VERSIONS="$python_version" \ -DCLANG_SYSTEMZ_DEFAULT_ARCH=z196 \ -DCLANG_VENDOR=Alpine \ -DENABLE_LINKER_BUILD_ID=ON \ -DLIBCLANG_BUILD_STATIC=ON ninja -C build clang-tblgen ninja -C build if [ "$_default_clang" = yes ]; then help2man --no-info \ --source "Alpine" \ --name "Alpine Clang $pkgver-r$pkgrel" \ --version-string "$pkgver-r$pkgrel" \ --help-option "--help-hidden" \ ./build/bin/clang > clang.1 fi } check() { ninja -C build check-all } package() { # the libraries should always exactly match, not just by soname # gcc is for libgcc-dev which we don't have split depends=" $pkgname-headers=$pkgver-r$pkgrel $pkgname-libs=$pkgver-r$pkgrel fortify-headers>=1.1-r2 gcc libstdc++-dev llvm$_llvmver-linker-tools musl-dev " # create system config # clang doesn't really have a way to set default -march abi options, so use the system config dir # see the clang UsersManual for how this config directory is parsed / fallback order. # this is set based on our gcc baseline. see the --with arguments in main/gcc. mkdir -p "$pkgdir"/etc/clang$_llvmver case "$CARCH" in x86_64) # unsurprisingly, this is the same as gcc touch config.cfg ;; x86) # clang defaults to pentium4 on i*86- triples. # see https://github.com/llvm/llvm-project/issues/61347 cat > config.cfg <<-EOF -march=pentium-m -mfpmath=sse EOF ;; armhf) # clang defaults to 'armv6' for armhf, i.e. no -zk. # -zk is also a deprecated name for -kz. cat > config.cfg <<-EOF -march=armv6kz -mfpu=vfp -mtune=arm1176jzf-s EOF ;; armv7) # clang defaults to neon fpu and non-thumb. # XXX: but seemingly changing it from this makes it not really work on armv7 # cat > config.cfg <<-EOF # -mfpu=vfpv3-d16 # -mthumb # EOF touch config.cfg ;; s390x) # this is correct, as this is the one thing that we have a build-time -D for. # see -DCLANG_SYSTEMZ_DEFAULT_ARCH. touch config.cfg ;; ppc64le) # this is seemingly correct, clang defaults to secureplt for musl and elfv2. touch config.cfg ;; riscv64) # this is correct, as clang defaults to rvXLENimafdc (-gc) for non-unknown. # this is our target already. touch config.cfg ;; aarch64) # XXX: this defaults to # CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8"); # is that correct? armv8 is always neon, but the others are unclear. # the output still runs on an rpi4 that normally doesn't have "crypto", so maybe that is misleading # (Gnu.cpp) touch config.cfg ;; esac # the target triple being built for # in LLVM, we set -DLLVM_DEFAULT_TARGET_TRIPLE to the same thing, # so that is the default triple, and one of the checked files. # it's possible to do CBUILD-clang.cfg and similar to make it per-tool mv config.cfg "$pkgdir"/etc/clang$_llvmver/$CBUILD.cfg DESTDIR="$pkgdir" cmake --install build mkdir -p "$pkgdir"/usr/bin install -Dm644 build/lib/libclang.a -t "$pkgdir"/usr/lib/llvm$_llvmver/lib/ if [ $_default_clang = "yes" ]; then rm "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-format-bbedit.applescript \ "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-doc-default-stylesheet.css \ "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/index.js mkdir -p "$pkgdir"/usr/share/bash-completion/completions mv "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/bash-autocomplete.sh \ "$pkgdir"/usr/share/bash-completion/completions/clang mkdir -p "$pkgdir"/usr/share/emacs/site-lisp mv "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-*.el \ "$pkgdir"/usr/share/emacs/site-lisp rmdir -p usr/lib/llvm$_llvmver/share/emacs || true mv "$pkgdir"/usr/lib/llvm$_llvmver/share/man "$pkgdir"/usr/share/ # XXX: scan-build specifically needs to stay in llvm path, but scan-view has to not be # everything uses different path lookup logic.. mv "$pkgdir"/usr/lib/llvm$_llvmver/share/scan-view "$pkgdir"/usr/share/ local sitedir=$(python3 -c "import site; print(site.getsitepackages()[0])") mv "$pkgdir"/usr/lib/llvm$_llvmver/lib/python3* "$pkgdir"/usr/lib mkdir -p "$pkgdir"/"$sitedir" mv "$pkgdir"/usr/lib/llvm$_llvmver/lib/libscanbuild "$pkgdir"/"$sitedir" # symlink everything in the bin dir, # into /usr/bin. local clangexes=" analyze-build amdgpu-arch c-index-test clang clang-cl clang-cpp clang-include-cleaner clang-linker-wrapper clang-pseudo clang++ clang-$_llvmver clang-apply-replacements clang-change-namespace clang-check clang-doc clang-extdef-mapping clang-format clang-include-fixer clang-move clang-offload-bundler clang-offload-packager clang-query clang-refactor clang-rename clang-reorder-fields clang-repl clang-scan-deps clang-tidy clangd diagtool find-all-symbols git-clang-format hmaptool intercept-build modularize nvptx-arch pp-trace run-clang-tidy scan-build scan-build-py scan-view " for clangexe in $clangexes; do ln -sfv ../lib/llvm$_llvmver/bin/$clangexe "$pkgdir"/usr/bin/$clangexe done ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang++-$_llvmver install -Dm644 "$builddir"/clang.1 -t "$pkgdir"/usr/share/man/man1/ else ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang-$_llvmver ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang++-$_llvmver # delete things we don't want non-latest of rm -r "$pkgdir"/usr/lib/llvm$_llvmver/share rm -r "$pkgdir"/usr/lib/llvm$_llvmver/lib/python3* fi local libs=" libclang-cpp.so libclang-cpp.so.$_llvmver libclang.so libclang.so.$_llvmver libclang.so.$pkgver " for lib in $libs; do ln -sfv ../lib/llvm$_llvmver/lib/$lib "$pkgdir"/usr/lib/$lib done # compat symlink back to fix clang with -no-canonical-prefixes mkdir -p "$pkgdir"/usr/lib/clang/ ln -sfv ../llvm$_llvmver/lib/clang/$_llvmver "$pkgdir"/usr/lib/clang/$_llvmver } dev() { default_dev _default_replace # move cmake to -dev amove usr/lib/llvm$_llvmver/lib/cmake/clang # create cmakedir symlinks, so find_package works # llvm does the same thing- versioned, plus unversioned default. mkdir -p "$subpkgdir"/usr/lib/cmake ln -sfv ../llvm$_llvmver/lib/cmake/clang "$subpkgdir"/usr/lib/cmake/clang$_llvmver if [ $_default_clang = yes ]; then ln -sfv clang$_llvmver "$subpkgdir"/usr/lib/cmake/clang fi } static() { default_static _default_replace } bash() { default_bashcomp _default_replace } libs() { default_libs # this can fail depending on the symlinks and is already moved amove usr/lib/libclang-cpp.so.* || true amove usr/lib/llvm$_llvmver/lib/libclang-cpp.so* _default_replace } libclang() { _default_replace replaces="$replaces clang-libs" depends="$pkgname-headers=$pkgver-r$pkgrel" # we add an extra subpackage for this so things that link to libclang don't # have to pull libclang-cpp too (separate) amove usr/lib/libclang.so.* amove usr/lib/llvm$_llvmver/lib/libclang.so* } analyzer() { pkgdesc="Clang source code analysis framework" depends="$pkgname=$pkgver-r$pkgrel py3-$pkgname=$pkgver-r$pkgrel perl python3" _default_replace amove \ usr/bin/scan* \ usr/bin/analyze-build* \ usr/bin/intercept-build* \ usr/lib/llvm$_llvmver/bin/scan* \ usr/lib/llvm$_llvmver/bin/analyze-build* \ usr/lib/llvm$_llvmver/bin/intercept-build* \ usr/lib/llvm$_llvmver/libexec/*-analyzer* \ usr/lib/llvm$_llvmver/libexec/analyze-* \ usr/lib/llvm$_llvmver/libexec/intercept-* \ usr/lib/llvm$_llvmver/lib/libear* \ usr/lib/llvm$_llvmver/share/scan-build \ usr/share/scan-view } headers() { _default_replace amove usr/lib/llvm$_llvmver/lib/clang/$_llvmver/include } extra() { pkgdesc="Extra tools built using Clang's tooling APIs" _default_replace if [ "$_default_clang" = "yes" ]; then amove \ usr/bin/amdgpu-arch \ usr/bin/clang-apply-replacements* \ usr/bin/clang-change-namespace* \ usr/bin/clang-check* \ usr/bin/clang-doc* \ usr/bin/clang-extdef-mapping* \ usr/bin/clang-format* \ usr/bin/clang-include-cleaner* \ usr/bin/clang-include-fixer* \ usr/bin/clang-move* \ usr/bin/clang-offload-bundler* \ usr/bin/clang-pseudo* \ usr/bin/clang-query* \ usr/bin/clang-refactor* \ usr/bin/clang-rename* \ usr/bin/clang-reorder-fields* \ usr/bin/clang-repl* \ usr/bin/clang-scan-deps* \ usr/bin/clang-tidy* \ usr/bin/clangd* \ usr/bin/c-index-test* \ usr/bin/diagtool* \ usr/bin/find-all-symbols* \ usr/bin/git-clang-format* \ usr/bin/hmaptool* \ usr/bin/modularize* \ usr/bin/nvptx-arch \ usr/bin/pp-trace* \ usr/bin/run-clang-tidy* fi amove \ usr/lib/llvm$_llvmver/bin/clang-apply-replacements* \ usr/lib/llvm$_llvmver/bin/clang-change-namespace* \ usr/lib/llvm$_llvmver/bin/clang-check* \ usr/lib/llvm$_llvmver/bin/clang-doc* \ usr/lib/llvm$_llvmver/bin/clang-extdef-mapping* \ usr/lib/llvm$_llvmver/bin/clang-format* \ usr/lib/llvm$_llvmver/bin/clang-include-cleaner* \ usr/lib/llvm$_llvmver/bin/clang-include-fixer* \ usr/lib/llvm$_llvmver/bin/clang-move* \ usr/lib/llvm$_llvmver/bin/clang-offload-bundler* \ usr/lib/llvm$_llvmver/bin/clang-pseudo* \ usr/lib/llvm$_llvmver/bin/clang-query* \ usr/lib/llvm$_llvmver/bin/clang-refactor* \ usr/lib/llvm$_llvmver/bin/clang-rename* \ usr/lib/llvm$_llvmver/bin/clang-reorder-fields* \ usr/lib/llvm$_llvmver/bin/clang-repl* \ usr/lib/llvm$_llvmver/bin/clang-scan-deps* \ usr/lib/llvm$_llvmver/bin/clang-tidy* \ usr/lib/llvm$_llvmver/bin/clangd* \ usr/lib/llvm$_llvmver/bin/c-index-test* \ usr/lib/llvm$_llvmver/bin/diagtool* \ usr/lib/llvm$_llvmver/bin/find-all-symbols* \ usr/lib/llvm$_llvmver/bin/git-clang-format* \ usr/lib/llvm$_llvmver/bin/hmaptool* \ usr/lib/llvm$_llvmver/bin/modularize* \ usr/lib/llvm$_llvmver/bin/pp-trace* \ usr/lib/llvm$_llvmver/bin/run-clang-tidy* \ usr/lib/llvm$_llvmver/share/clang/clang* \ usr/lib/llvm$_llvmver/share/clang/run-find-all-symbols.py } emacs() { _default_replace pkgdesc="clang plugin for emacs" install_if="$pkgname-extra-tools=$pkgver-r$pkgrel emacs" amove usr/share/emacs } python() { pkgdesc="Clang Python Bindings" depends="$pkgname-libs=$pkgver-r$pkgrel python3" provides="py3-clang=$pkgver-r$pkgrel" replaces="py3-clang" amove usr/lib/python* } ccache() { _default_replace pkgdesc="$pkgdesc (ccache symlinks)" install_if="$pkgname=$pkgver-r$pkgrel ccache" replaces="$replaces ccache" mkdir -p "$subpkgdir"/usr/lib/ccache/bin ln -sfv ../../../bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang-$_llvmver ln -sfv ../../../bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang++-$_llvmver if [ "$_default_clang" = yes ]; then ln -sfv ../../../bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang++ ln -sfv ../../../bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang fi } _default_replace() { if [ "$_default_clang" = yes ]; then replaces="clang${subpkgname#"$pkgname"} clang15${subpkgname#"$pkgname"}" provides="clang${subpkgname#"$pkgname"}=$pkgver-r$pkgrel" fi } sha512sums=" 92c65b882e1504f4a9b8a3f6b8a24061505987aaacc8bb835115b4e4d74ac3a8c98343a308567b07c6b42bb99877c300bce3c4a5a25ada77abe65606aa25188d clang-16.0.6.src.tar.xz ec1a0834f223e393d24c11586b744167a41cea6c39d1bb18c433d2fb736501950fdff42f1eb0caa13c75bcb8ef9ac309eb0687644307698ec0420ff8a769c710 clang-tools-extra-16.0.6.src.tar.xz 52ecd941d2d85a5b668caa5d0d40480cb6a97b3bf1174e634c2a93e9ef6d03670ca7e96abb0a60cb33ba537b93d5788754dab1f2f45c1f623f788162717d088b cmake-16.0.6.src.tar.xz 5809d931656cac13b91bc91aac63df072b0403708ac718bf01546d9d520ff2c4163ee11411439dce5bb683a3bfa044b62443b6f66a1419c9086d20e79a018071 10-add-musl-triples.patch 92653a1197e2fab42ba81c00cb5f8b3a6c42c8f88d4cf3d0eff71db50f8c7c745f816681540d8b0e2275c8fa7f82bc3af33623eb1c81028a62269ea21821142f 30-Enable-stack-protector-by-default-for-Alpine-Linux.patch 6896d6c5358b8b83c97c7cb31f60042f33a1326cfad093a0f23dcacd10ef418f845964f6de948a5873494dae5180e51a4b2b0cec937aa5597765362779da6f35 clang-default-fno-semantic-interposition.patch aa2dff990278e0258763934eaa528827baa1733eeb7dc36cc7f1500a4919b8d11870a0522f20f210d454322e3faf5945e9afaeffc9f3a3c4fd422b706370a663 clang-001-fortify-include.patch 751f8acef2bfd1b50c065dea2ad0c3a20cadd4ff4c842ae519b5085c48372127b49a75d3fd0bd32291f5a69119340e5568a9fba6d94e6f354b14233986f61328 clang-002-fortify-enable.patch 5f98f147d7d66315e9a56ae6fee602a053d40e57a8b1ee4f2ef1764203bb6fdb9082c8e825c535a9388213a38b49d2702b1e936fcf56560c4a2a56b7e6dd232c clang-003-as-needed.patch 0928f379068e0bf819074f9cefad6247705c2571a08e995036e8432becdae0daf81dbc02548097fb544bb0c3fe02cac4039eb7d0dfcd51d03c3952ec3524b727 9008-Clang-Support-more-stdio-builtins.patch 1d6d1dd5719ff1e93e55c8fd0fde115a0145d0d27c53e9a60bcf32a2e55afceac0dc28c41e1e2b1d2e5c1b8a16350c080b6c34b72595381f433e01130b52d162 9012-Call-printName-to-get-name-of-Decl.patch "