archrelease: copy trunk to extra-x86_64
[arch-packages.git] / clang / trunk / PKGBUILD
blobdbcff69f722fb885e66e80b275d573c01d2cfcc6
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=2
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         enable-fstack-protector-strong-by-default.patch)
26 sha256sums=('a6b673ef15377fb46062d164e8ddc4d05c348ff8968f015f7f4af03f51000067'
27             'SKIP'
28             '809a2ef46d46be3b83ca389356404ac041fa6d8f5496cb02ec35d252afb64fd1'
29             'SKIP'
30             '4ad8b2cc8003c86d0078d15d987d84e3a739f24aae9033865c027abae93ee7a4'
31             'SKIP'
32             '8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea'
33             'SKIP'
34             '640ac4858c68cc6d52226afe01a67ad017f95511636b631d826b791c5b11a47e'
35             '7a9ce949579a3b02d4b91b6835c4fb45adc5f743007572fb0e28e6433e48f3a5')
36 validpgpkeys=('474E22316ABF4785A88C6E8EA2C794A986419D8A'  # Tom Stellard <tstellar@redhat.com>
37               'D574BD5D1D0E98895E3BF90044F2485E45D59042') # Tobias Hieta <tobias@hieta.se>
39 # Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid
40 # installing static libraries; inspired by Gentoo
41 _get_distribution_components() {
42   local target
43   ninja -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do
44     case $target in
45       clang-libraries|distribution)
46         continue
47         ;;
48       clang-tidy-headers)
49         continue
50         ;;
51       clang|clangd|clang-*)
52         ;;
53       clang*|findAllSymbols)
54         continue
55         ;;
56     esac
57     echo $target
58   done
61 prepare() {
62   mv cmake{-$pkgver.src,}
63   cd clang-$pkgver.src
64   mkdir build
65   mv "$srcdir/clang-tools-extra-$pkgver.src" tools/extra
66   patch -Np2 -i ../enable-fstack-protector-strong-by-default.patch
68   # https://reviews.llvm.org/D145862
69   patch -Np2 -l -i ../$pkgname-linker-wrapper-tool.patch
71   # Attempt to convert script to Python 3
72   2to3 -wn --no-diffs \
73     tools/extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
76 build() {
77   cd clang-$pkgver.src/build
79   # Build only minimal debug info to reduce size
80   CFLAGS=${CFLAGS/-g /-g1 }
81   CXXFLAGS=${CXXFLAGS/-g /-g1 }
83   local cmake_args=(
84     -G Ninja
85     -DCMAKE_BUILD_TYPE=Release
86     -DCMAKE_INSTALL_PREFIX=/usr
87     -DCMAKE_INSTALL_DOCDIR=share/doc
88     -DCMAKE_SKIP_RPATH=ON
89     -DCLANG_DEFAULT_PIE_ON_LINUX=ON
90     -DCLANG_LINK_CLANG_DYLIB=ON
91     -DENABLE_LINKER_BUILD_ID=ON
92     -DLLVM_BUILD_DOCS=ON
93     -DLLVM_BUILD_TESTS=ON
94     -DLLVM_ENABLE_RTTI=ON
95     -DLLVM_ENABLE_SPHINX=ON
96     -DLLVM_EXTERNAL_LIT=/usr/bin/lit
97     -DLLVM_INCLUDE_DOCS=ON
98     -DLLVM_LINK_LLVM_DYLIB=ON
99     -DLLVM_MAIN_SRC_DIR="$srcdir/llvm-$pkgver.src"
100     -DSPHINX_WARNINGS_AS_ERRORS=OFF
101   )
103   cmake .. "${cmake_args[@]}"
104   local distribution_components=$(_get_distribution_components | paste -sd\;)
105   test -n "$distribution_components"
106   cmake_args+=(-DLLVM_DISTRIBUTION_COMPONENTS="$distribution_components")
108   cmake .. "${cmake_args[@]}"
109   ninja
112 check() {
113   cd clang-$pkgver.src/build
114   LD_LIBRARY_PATH=$PWD/lib ninja check-clang{,-tools}
117 _python_optimize() {
118   python -m compileall "$@"
119   python -O -m compileall "$@"
120   python -OO -m compileall "$@"
123 package() {
124   cd clang-$pkgver.src/build
126   DESTDIR="$pkgdir" ninja install-distribution
127   install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
129   # Remove documentation sources
130   rm -r "$pkgdir"/usr/share/doc/clang{,-tools}/html/{_sources,.buildinfo}
132   # Move scanbuild-py into site-packages and install Python bindings
133   local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
134   install -d "$pkgdir/$site_packages"
135   mv "$pkgdir"/usr/lib/{libear,libscanbuild} "$pkgdir/$site_packages/"
136   cp -a ../bindings/python/clang "$pkgdir/$site_packages/"
138   # Move analyzer scripts out of /usr/libexec
139   mv "$pkgdir"/usr/libexec/* "$pkgdir/usr/lib/clang/"
140   rmdir "$pkgdir/usr/libexec"
141   sed -i 's|libexec|lib/clang|' \
142     "$pkgdir/usr/bin/scan-build" \
143     "$pkgdir/$site_packages/libscanbuild/analyze.py"
145   # Compile Python scripts
146   _python_optimize "$pkgdir/usr/share" "$pkgdir/$site_packages"
149 # vim:set ts=2 sw=2 et: