sys-devel/clang: Bump to 8.0.0rc3
[gentoo.git] / sys-devel / clang / clang-8.0.0_rc3.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
7 # (needed due to CMAKE_BUILD_TYPE != Gentoo)
8 CMAKE_MIN_VERSION=3.7.0-r1
9 PYTHON_COMPAT=( python2_7 )
10
11 inherit cmake-utils eapi7-ver flag-o-matic llvm \
12         multilib-minimal multiprocessing pax-utils prefix python-single-r1 \
13         toolchain-funcs
14
15 MY_P=cfe-${PV/_/}.src
16 EXTRA_P=clang-tools-extra-${PV/_/}.src
17 LLVM_P=llvm-${PV/_/}.src
18
19 DESCRIPTION="C language family frontend for LLVM"
20 HOMEPAGE="https://llvm.org/"
21 SRC_URI="https://prereleases.llvm.org/${PV/_//}/${MY_P}.tar.xz
22         https://prereleases.llvm.org/${PV/_//}/${EXTRA_P}.tar.xz
23         test? ( https://prereleases.llvm.org/${PV/_//}/${LLVM_P}.tar.xz )"
24 #       !doc? ( https://dev.gentoo.org/~mgorny/dist/llvm/llvm-${PV}-manpages.tar.bz2 )"
25
26 # Keep in sync with sys-devel/llvm
27 ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
28         NVPTX PowerPC Sparc SystemZ X86 XCore )
29 ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
30 LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
31
32 LICENSE="UoI-NCSA"
33 SLOT="$(ver_cut 1)"
34 KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~x86 ~amd64-fbsd ~amd64-linux ~ppc-macos ~x64-macos ~x86-macos"
35 IUSE="debug default-compiler-rt default-libcxx doc +static-analyzer
36         test xml z3 kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
37 RESTRICT="!test? ( test )"
38
39 RDEPEND="
40         ~sys-devel/llvm-${PV}:${SLOT}=[debug=,${LLVM_TARGET_USEDEPS// /,},${MULTILIB_USEDEP}]
41         static-analyzer? (
42                 dev-lang/perl:*
43                 z3? ( >=sci-mathematics/z3-4.7.1:0=[${MULTILIB_USEDEP}] )
44         )
45         xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
46         ${PYTHON_DEPS}"
47 # configparser-3.2 breaks the build (3.3 or none at all are fine)
48 DEPEND="${RDEPEND}
49         doc? ( dev-python/sphinx )
50         xml? ( virtual/pkgconfig )
51         !!<dev-python/configparser-3.3.0.2
52         ${PYTHON_DEPS}"
53 RDEPEND="${RDEPEND}
54         !<sys-devel/llvm-4.0.0_rc:0
55         !sys-devel/clang:0"
56 PDEPEND="
57         sys-devel/clang-common
58         ~sys-devel/clang-runtime-${PV}
59         default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
60         default-libcxx? ( >=sys-libs/libcxx-${PV} )"
61
62 REQUIRED_USE="${PYTHON_REQUIRED_USE}
63         || ( ${ALL_LLVM_TARGETS[*]} )"
64
65 # We need extra level of indirection for CLANG_RESOURCE_DIR
66 S=${WORKDIR}/x/y/${MY_P}
67
68 # least intrusive of all
69 CMAKE_BUILD_TYPE=RelWithDebInfo
70
71 PATCHES=(
72         # add Prefix include paths for Darwin
73         "${FILESDIR}"/6.0.1/darwin_prefix-include-paths.patch
74 )
75
76 # Multilib notes:
77 # 1. ABI_* flags control ABIs libclang* is built for only.
78 # 2. clang is always capable of compiling code for all ABIs for enabled
79 #    target. However, you will need appropriate crt* files (installed
80 #    e.g. by sys-devel/gcc and sys-libs/glibc).
81 # 3. ${CHOST}-clang wrappers are always installed for all ABIs included
82 #    in the current profile (i.e. alike supported by sys-devel/gcc).
83 #
84 # Therefore: use sys-devel/clang[${MULTILIB_USEDEP}] only if you need
85 # multilib clang* libraries (not runtime, not wrappers).
86
87 pkg_setup() {
88         LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
89         python-single-r1_pkg_setup
90 }
91
92 src_unpack() {
93         # create extra parent dir for CLANG_RESOURCE_DIR
94         mkdir -p x/y || die
95         cd x/y || die
96
97         einfo "Unpacking ${MY_P}.tar.xz ..."
98         tar -xf "${DISTDIR}/${MY_P}.tar.xz" || die
99         einfo "Unpacking ${EXTRA_P}.tar.xz ..."
100         tar -xf "${DISTDIR}/${EXTRA_P}.tar.xz" || die
101
102         mv "${EXTRA_P}" "${S}"/tools/extra || die
103         if use test; then
104                 einfo "Unpacking parts of ${LLVM_P}.tar.xz ..."
105                 tar -xf "${DISTDIR}/${LLVM_P}.tar.xz" \
106                         "${LLVM_P}"/lib/Testing/Support \
107                         "${LLVM_P}"/utils/{lit,llvm-lit,unittest} || die
108                 mv "${LLVM_P}" "${WORKDIR}"/llvm || die
109         fi
110
111 #       if ! use doc; then
112 #               einfo "Unpacking llvm-${PV}-manpages.tar.bz2 ..."
113 #               tar -xf "${DISTDIR}/llvm-${PV}-manpages.tar.bz2" || die
114 #       fi
115 }
116
117 src_prepare() {
118         cmake-utils_src_prepare
119         eprefixify lib/Frontend/InitHeaderSearch.cpp
120 }
121
122 multilib_src_configure() {
123         local llvm_version=$(llvm-config --version) || die
124         local clang_version=$(ver_cut 1-3 "${llvm_version}")
125
126         local mycmakeargs=(
127                 # ensure that the correct llvm-config is used
128                 -DLLVM_CONFIG="$(type -P "${CHOST}-llvm-config")"
129                 -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
130                 -DCMAKE_INSTALL_MANDIR="${EPREFIX}/usr/lib/llvm/${SLOT}/share/man"
131                 # relative to bindir
132                 -DCLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"
133
134                 -DBUILD_SHARED_LIBS=ON
135                 -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
136                 -DLLVM_BUILD_TESTS=$(usex test)
137
138                 # these are not propagated reliably, so redefine them
139                 -DLLVM_ENABLE_EH=ON
140                 -DLLVM_ENABLE_RTTI=ON
141
142                 -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
143                 # libgomp support fails to find headers without explicit -I
144                 # furthermore, it provides only syntax checking
145                 -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
146
147                 # override default stdlib and rtlib
148                 -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
149                 -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
150
151                 -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
152                 -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
153                 # z3 is not multilib-friendly
154                 -DCLANG_ANALYZER_ENABLE_Z3_SOLVER=$(usex z3)
155         )
156         use test && mycmakeargs+=(
157                 -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
158                 -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
159         )
160
161         if multilib_is_native_abi; then
162                 mycmakeargs+=(
163                         # normally copied from LLVM_INCLUDE_DOCS but the latter
164                         # is lacking value in stand-alone builds
165                         -DCLANG_INCLUDE_DOCS=$(usex doc)
166                         -DCLANG_TOOLS_EXTRA_INCLUDE_DOCS=$(usex doc)
167                 )
168                 use doc && mycmakeargs+=(
169                         -DLLVM_BUILD_DOCS=ON
170                         -DLLVM_ENABLE_SPHINX=ON
171                         -DCLANG_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/html"
172                         -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/tools-extra"
173                         -DSPHINX_WARNINGS_AS_ERRORS=OFF
174                 )
175                 use z3 && mycmakeargs+=(
176                         -DZ3_INCLUDE_DIR="${EPREFIX}/usr/include/z3"
177                 )
178         else
179                 mycmakeargs+=(
180                         -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF
181                 )
182         fi
183
184         if [[ -n ${EPREFIX} ]]; then
185                 mycmakeargs+=(
186                         -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
187                 )
188         fi
189
190         if tc-is-cross-compiler; then
191                 [[ -x "/usr/bin/clang-tblgen" ]] \
192                         || die "/usr/bin/clang-tblgen not found or usable"
193                 mycmakeargs+=(
194                         -DCMAKE_CROSSCOMPILING=ON
195                         -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
196                 )
197         fi
198
199         # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
200         use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
201         cmake-utils_src_configure
202 }
203
204 multilib_src_compile() {
205         cmake-utils_src_compile
206
207         # provide a symlink for tests
208         if [[ ! -L ${WORKDIR}/lib/clang ]]; then
209                 mkdir -p "${WORKDIR}"/lib || die
210                 ln -s "${BUILD_DIR}/$(get_libdir)/clang" "${WORKDIR}"/lib/clang || die
211         fi
212 }
213
214 multilib_src_test() {
215         # respect TMPDIR!
216         local -x LIT_PRESERVES_TMP=1
217         cmake-utils_src_make check-clang
218         multilib_is_native_abi && cmake-utils_src_make check-clang-tools
219 }
220
221 src_install() {
222         MULTILIB_WRAPPED_HEADERS=(
223                 /usr/include/clang/Config/config.h
224         )
225
226         multilib-minimal_src_install
227
228         # Move runtime headers to /usr/lib/clang, where they belong
229         mv "${ED%/}"/usr/include/clangrt "${ED%/}"/usr/lib/clang || die
230         # move (remaining) wrapped headers back
231         mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die
232
233         # Apply CHOST and version suffix to clang tools
234         # note: we use two version components here (vs 3 in runtime path)
235         local llvm_version=$(llvm-config --version) || die
236         local clang_version=$(ver_cut 1 "${llvm_version}")
237         local clang_full_version=$(ver_cut 1-3 "${llvm_version}")
238         local clang_tools=( clang clang++ clang-cl clang-cpp )
239         local abi i
240
241         # cmake gives us:
242         # - clang-X
243         # - clang -> clang-X
244         # - clang++, clang-cl, clang-cpp -> clang
245         # we want to have:
246         # - clang-X
247         # - clang++-X, clang-cl-X, clang-cpp-X -> clang-X
248         # - clang, clang++, clang-cl, clang-cpp -> clang*-X
249         # also in CHOST variant
250         for i in "${clang_tools[@]:1}"; do
251                 rm "${ED%/}/usr/lib/llvm/${SLOT}/bin/${i}" || die
252                 dosym "clang-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}-${clang_version}"
253                 dosym "${i}-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}"
254         done
255
256         # now create target symlinks for all supported ABIs
257         for abi in $(get_all_abis); do
258                 local abi_chost=$(get_abi_CHOST "${abi}")
259                 for i in "${clang_tools[@]}"; do
260                         dosym "${i}-${clang_version}" \
261                                 "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}-${clang_version}"
262                         dosym "${abi_chost}-${i}-${clang_version}" \
263                                 "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}"
264                 done
265         done
266
267         # Remove unnecessary headers on FreeBSD, bug #417171
268         if use kernel_FreeBSD; then
269                 rm "${ED}"usr/lib/clang/${clang_full_version}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
270         fi
271 }
272
273 multilib_src_install() {
274         cmake-utils_src_install
275
276         # move headers to /usr/include for wrapping & ABI mismatch checks
277         # (also drop the version suffix from runtime headers)
278         rm -rf "${ED%/}"/usr/include || die
279         mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die
280         mv "${ED%/}"/usr/lib/llvm/${SLOT}/$(get_libdir)/clang "${ED%/}"/usr/include/clangrt || die
281 }
282
283 multilib_src_install_all() {
284         python_fix_shebang "${ED}"
285         if use static-analyzer; then
286                 python_optimize "${ED}"usr/lib/llvm/${SLOT}/share/scan-view
287         fi
288
289 #       # install pre-generated manpages
290 #       if ! use doc; then
291 #               insinto "/usr/lib/llvm/${SLOT}/share/man/man1"
292 #               doins "${WORKDIR}/x/y/llvm-${PV}-manpages/clang"/*.1
293 #       fi
294 #
295         docompress "/usr/lib/llvm/${SLOT}/share/man"
296         # match 'html' non-compression
297         use doc && docompress -x "/usr/share/doc/${PF}/tools-extra"
298         # +x for some reason; TODO: investigate
299         use static-analyzer && fperms a-x "/usr/lib/llvm/${SLOT}/share/man/man1/scan-build.1"
300 }
301
302 pkg_postinst() {
303         if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
304                 eselect compiler-shadow update all
305         fi
306
307         elog "You can find additional utility scripts in:"
308         elog "  ${EROOT}/usr/lib/llvm/${SLOT}/share/clang"
309         elog "To use these scripts, you will need Python 2.7. Some of them are vim"
310         elog "integration scripts (with instructions inside). The run-clang-tidy.py"
311         elog "scripts requires the following additional package:"
312         elog "  dev-python/pyyaml"
313 }
314
315 pkg_postrm() {
316         if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
317                 eselect compiler-shadow clean all
318         fi
319 }