archrelease: copy trunk to extra-x86_64
[arch-packages.git] / clang / trunk / PKGBUILD
blob288b0885b64b91694e1a3a8e4869babc4b386a17
1 # Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
2 # Contributor: Jan "heftig" Steffens <jan.steffens@gmail.com>
4 pkgname=clang
5 pkgver=15.0.7
6 pkgrel=9
7 pkgdesc="C language family frontend for LLVM"
8 arch=('x86_64')
9 url="https://clang.llvm.org/"
10 license=('custom:Apache 2.0 with LLVM Exception')
11 depends=('llvm-libs' 'gcc' 'compiler-rt')
12 makedepends=('llvm' 'cmake' 'ninja' 'python-sphinx' 'python-recommonmark')
13 optdepends=('openmp: OpenMP support in clang with -fopenmp'
14             'python: for scan-view and git-clang-format'
15             'llvm: referenced by some clang headers')
16 provides=("clang-analyzer=$pkgver" "clang-tools-extra=$pkgver")
17 conflicts=('clang-analyzer' 'clang-tools-extra')
18 replaces=('clang-analyzer' 'clang-tools-extra')
19 _source_base=https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver
20 source=($_source_base/clang-$pkgver.src.tar.xz{,.sig}
21         $_source_base/clang-tools-extra-$pkgver.src.tar.xz{,.sig}
22         $_source_base/llvm-$pkgver.src.tar.xz{,.sig}
23         $_source_base/cmake-$pkgver.src.tar.xz{,.sig}
24         $pkgname-linker-wrapper-tool.patch::https://github.com/llvm/llvm-project/commit/c2aabcfc8395.patch
25         $pkgname-structured-bindings-r1.patch::https://github.com/llvm/llvm-project/commit/127bf4438542.patch
26         $pkgname-bitfield-value-capture.patch::https://github.com/llvm/llvm-project/commit/a1a71b7dc97b.patch
27         enable-fstack-protector-strong-by-default.patch)
28 sha256sums=('a6b673ef15377fb46062d164e8ddc4d05c348ff8968f015f7f4af03f51000067'
29             'SKIP'
30             '809a2ef46d46be3b83ca389356404ac041fa6d8f5496cb02ec35d252afb64fd1'
31             'SKIP'
32             '4ad8b2cc8003c86d0078d15d987d84e3a739f24aae9033865c027abae93ee7a4'
33             'SKIP'
34             '8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea'
35             'SKIP'
36             '640ac4858c68cc6d52226afe01a67ad017f95511636b631d826b791c5b11a47e'
37             '6092fa872e2a706de12d1efb0626a4e9ef9854014edc68edb5ebac2ad27e2d9f'
38             'd432e706fd99e7817ea0cbb02795918a781a11e4f5e6d304d53fffec9856b6f4'
39             '7a9ce949579a3b02d4b91b6835c4fb45adc5f743007572fb0e28e6433e48f3a5')
40 validpgpkeys=('474E22316ABF4785A88C6E8EA2C794A986419D8A'  # Tom Stellard <tstellar@redhat.com>
41               'D574BD5D1D0E98895E3BF90044F2485E45D59042') # Tobias Hieta <tobias@hieta.se>
43 # Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid
44 # installing static libraries; inspired by Gentoo
45 _get_distribution_components() {
46   local target
47   ninja -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do
48     case $target in
49       clang-libraries|distribution)
50         continue
51         ;;
52       clang-tidy-headers)
53         continue
54         ;;
55       clang|clangd|clang-*)
56         ;;
57       clang*|findAllSymbols)
58         continue
59         ;;
60     esac
61     echo $target
62   done
65 prepare() {
66   mv cmake{-$pkgver.src,}
67   cd clang-$pkgver.src
68   mkdir build
69   mv "$srcdir/clang-tools-extra-$pkgver.src" tools/extra
70   patch -Np2 -i ../enable-fstack-protector-strong-by-default.patch
72   # https://reviews.llvm.org/D145862
73   patch -Np2 -l -i ../$pkgname-linker-wrapper-tool.patch
75   # https://reviews.llvm.org/D122768 (needed for Chromium 113)
76   sed 's|clang-tools-extra|clang/tools/extra|g' \
77     ../$pkgname-structured-bindings-r1.patch | patch -Np2
79   # https://reviews.llvm.org/D131202 (regression caused by the above)
80   patch -Np2 -i ../$pkgname-bitfield-value-capture.patch
82   # Attempt to convert script to Python 3
83   2to3 -wn --no-diffs \
84     tools/extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
87 build() {
88   cd clang-$pkgver.src/build
90   # Build only minimal debug info to reduce size
91   CFLAGS=${CFLAGS/-g /-g1 }
92   CXXFLAGS=${CXXFLAGS/-g /-g1 }
94   local cmake_args=(
95     -G Ninja
96     -DCMAKE_BUILD_TYPE=Release
97     -DCMAKE_INSTALL_PREFIX=/usr
98     -DCMAKE_INSTALL_DOCDIR=share/doc
99     -DCMAKE_SKIP_RPATH=ON
100     -DCLANG_DEFAULT_PIE_ON_LINUX=ON
101     -DCLANG_LINK_CLANG_DYLIB=ON
102     -DENABLE_LINKER_BUILD_ID=ON
103     -DLLVM_BUILD_DOCS=ON
104     -DLLVM_BUILD_TESTS=ON
105     -DLLVM_ENABLE_RTTI=ON
106     -DLLVM_ENABLE_SPHINX=ON
107     -DLLVM_EXTERNAL_LIT=/usr/bin/lit
108     -DLLVM_INCLUDE_DOCS=ON
109     -DLLVM_LINK_LLVM_DYLIB=ON
110     -DLLVM_MAIN_SRC_DIR="$srcdir/llvm-$pkgver.src"
111     -DSPHINX_WARNINGS_AS_ERRORS=OFF
112   )
114   cmake .. "${cmake_args[@]}"
115   local distribution_components=$(_get_distribution_components | paste -sd\;)
116   test -n "$distribution_components"
117   cmake_args+=(-DLLVM_DISTRIBUTION_COMPONENTS="$distribution_components")
119   cmake .. "${cmake_args[@]}"
120   ninja
123 check() {
124   cd clang-$pkgver.src/build
125   LD_LIBRARY_PATH=$PWD/lib ninja check-clang{,-tools}
128 _python_optimize() {
129   python -m compileall "$@"
130   python -O -m compileall "$@"
131   python -OO -m compileall "$@"
134 package() {
135   cd clang-$pkgver.src/build
137   DESTDIR="$pkgdir" ninja install-distribution
138   install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
140   # Remove documentation sources
141   rm -r "$pkgdir"/usr/share/doc/clang{,-tools}/html/{_sources,.buildinfo}
143   # Move scanbuild-py into site-packages and install Python bindings
144   local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
145   install -d "$pkgdir/$site_packages"
146   mv "$pkgdir"/usr/lib/{libear,libscanbuild} "$pkgdir/$site_packages/"
147   cp -a ../bindings/python/clang "$pkgdir/$site_packages/"
149   # Move analyzer scripts out of /usr/libexec
150   mv "$pkgdir"/usr/libexec/* "$pkgdir/usr/lib/clang/"
151   rmdir "$pkgdir/usr/libexec"
152   sed -i 's|libexec|lib/clang|' \
153     "$pkgdir/usr/bin/scan-build" \
154     "$pkgdir/$site_packages/libscanbuild/analyze.py"
156   # Compile Python scripts
157   _python_optimize "$pkgdir/usr/share" "$pkgdir/$site_packages"
160 # vim:set ts=2 sw=2 et: