summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 371e42883979176c1b8fdcd5f2c519ee3c47dcaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#_                   _ _ _  _ _____ _  _
#| | _______   ____ _| | | || |___  | || |
#| |/ / _ \ \ / / _` | | | || |_ / /| || |_
#|   <  __/\ V / (_| | | |__   _/ / |__   _|
#|_|\_\___| \_/ \__,_|_|_|  |_|/_/     |_|

#Maintainer: kevall474 <kevall474@tuta.io> <https://github.com/kevall474>
#Credits: Evangelos Foutras <evangelos@foutrelis.com>
#Credits: Jan "heftig" Steffens <jan.steffens@gmail.com>

pkgname=clang-rc
pkgdesc='C language family frontend for LLVM (rc release)'
url='https://clang.llvm.org/'
pkgver=12.0.0rc5
versiontag=12.0.0-rc5
pkgrel=1
arch=('x86_64')
license=('custom:Apache 2.0 with LLVM Exception')
depends=('llvm-libs' 'gcc' 'compiler-rt')
makedepends=('llvm' 'cmake' 'ninja' 'python-sphinx' 'python2')
optdepends=('openmp: OpenMP support in clang with -fopenmp'
            'python: for scan-view and git-clang-format'
            'llvm: referenced by some clang headers')
conflicts=('clang-analyzer' 'clang-tools-extra' 'clang' 'clang-git' 'clang-stable')
replaces=('clang-analyzer' 'clang-tools-extra')
provides=('clang-analyzer' 'clang-tools-extra' 'clang')
source=("https://github.com/llvm/llvm-project/releases/download/llvmorg-$versiontag/llvm-project-$pkgver.src.tar.xz")
md5sums=('SKIP')

# Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid
# installing static libraries; inspired by Gentoo
_get_distribution_components(){
  local target
  ninja -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do
    case $target in
      clang-libraries|distribution)
        continue
        ;;
      clang-tidy-headers)
        continue
        ;;
      clang|clangd|clang-*)
        ;;
      clang*|findAllSymbols)
        continue
        ;;
    esac
    echo $target
  done
}

prepare(){
  if ! dir llvm-project-$pkgver.src/clang/tools/extra; then
    cp -r llvm-project-$pkgver.src/clang-tools-extra llvm-project-$pkgver.src/clang/tools/extra
  fi
}


build(){
  cd llvm-project-$pkgver.src/clang

  rm -rf build

  mkdir build

  cd build

  cmake .. -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr \
  -DPYTHON_EXECUTABLE=/usr/bin/python \
  -DLLVM_LINK_LLVM_DYLIB=ON \
  -DCLANG_LINK_CLANG_DYLIB=ON \
  -DLLVM_ENABLE_RTTI=ON \
  -DLLVM_BUILD_TESTS=OFF \
  -DLLVM_INCLUDE_DOCS=ON \
  -DLLVM_BUILD_DOCS=OFF \
  -DLLVM_ENABLE_SPHINX=OFF \
  -DSPHINX_WARNINGS_AS_ERRORS=OFF \
  -DLLVM_EXTERNAL_LIT=/usr/bin/lit \
  -DLLVM_MAIN_SRC_DIR="$srcdir/llvm-project-$pkgver.src/llvm"


  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
}

_python2_optimize(){
  python2 -m compileall "$@"
  python2 -O -m compileall "$@"
}

_python3_optimize(){
  python3 -m compileall "$@"
  python3 -O -m compileall "$@"
  python3 -OO -m compileall "$@"
}

#_python_optimize() {
#  python -m compileall "$@"
#  python -O -m compileall "$@"
#  python -OO -m compileall "$@"
#}

package(){
  DESTDIR="$pkgdir" ninja -C llvm-project-$pkgver.src/clang/build/ install-distribution
  install -Dm644 llvm-project-$pkgver.src/clang/LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # Remove documentation sources
  #rm -r "$pkgdir"/usr/share/doc/clang{,-tools}/html/{_sources,.buildinfo}
  #rm -r "$pkgdir"/usr/share/doc/clang/html/{_sources,.buildinfo}

  # Move analyzer scripts out of /usr/libexec
  mv "$pkgdir"/usr/libexec/{ccc,c++}-analyzer "$pkgdir/usr/lib/clang/"
  rmdir "$pkgdir/usr/libexec"
  sed -i 's|libexec|lib/clang|' "$pkgdir/usr/bin/scan-build"

  # Install Python bindings
  for _py in 2.7 3.9; do
    install -d "$pkgdir/usr/lib/python$_py/site-packages"
    cp -a llvm-project-$pkgver.src/clang/bindings/python/clang "$pkgdir/usr/lib/python$_py/site-packages/"
    _python${_py%%.*}_optimize "$pkgdir/usr/lib/python$_py"
  done

  # Fix shebang in Python 2 script
  sed -i '1s|/usr/bin/env python$|&2|' "$pkgdir"/usr/share/clang/run-find-all-symbols.py
  touch -d @$SOURCE_DATE_EPOCH "$pkgdir"/usr/share/clang/run-find-all-symbols.py

  # Compile Python scripts
  _python2_optimize "$pkgdir/usr/share/clang"
  _python3_optimize "$pkgdir/usr/share" -x 'clang-include-fixer|run-find-all-symbols'

  #_py="3.9"
  #cd llvm-project
  # Install Python bindings and optimize them
  #cp -a llvm/bindings/python/llvm  "$pkgdir"/usr/lib/python$_py/site-packages/
  #cp -a clang/bindings/python/clang  "$pkgdir"/usr/lib/python$_py/site-packages/
  #_python_optimize "$pkgdir"/usr/lib/python$_py/site-packages

  #optimize other python files except 2 problem cases
  #_python_optimize "$pkgdir"/usr/share -x 'clang-include-fixer|run-find-all-symbols'
}