1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 PYTHON_COMPAT=( python2_7 pypy )
9 inherit eutils flag-o-matic multibuild multilib \
10 multilib-minimal python-r1 toolchain-funcs pax-utils check-reqs prefix
12 DESCRIPTION="Low Level Virtual Machine"
13 HOMEPAGE="http://llvm.org/"
14 SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz
15 clang? ( http://llvm.org/releases/${PV}/compiler-rt-${PV}.src.tar.xz
16 http://llvm.org/releases/${PV}/cfe-${PV}.src.tar.xz
17 http://llvm.org/releases/${PV}/clang-tools-extra-${PV}.src.tar.xz )
18 !doc? ( https://dev.gentoo.org/~voyageur/distfiles/${PN}-3.5.0-manpages.tar.bz2 )"
22 KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x64-freebsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
23 IUSE="clang debug doc gold libedit +libffi multitarget ncurses ocaml python
24 +static-analyzer test xml video_cards_radeon
25 kernel_Darwin kernel_FreeBSD"
30 python? ( ${PYTHON_DEPS} )
35 xml? ( dev-libs/libxml2:2= )
37 gold? ( >=sys-devel/binutils-2.22:*[cxx] )
38 libedit? ( dev-libs/libedit:0=[${MULTILIB_USEDEP}] )
39 libffi? ( >=virtual/libffi-3.0.13-r1:0=[${MULTILIB_USEDEP}] )
40 ncurses? ( >=sys-libs/ncurses-5.9-r3:5=[${MULTILIB_USEDEP}] )
41 ocaml? ( dev-lang/ocaml:0= )"
42 # configparser-3.2 breaks the build (3.3 or none at all are fine)
43 DEPEND="${COMMON_DEPEND}
47 >=sys-devel/flex-2.5.4
48 >=sys-devel/bison-1.875d
49 || ( >=sys-devel/gcc-3.0 >=sys-devel/gcc-apple-4.2.1
50 ( >=sys-freebsd/freebsd-lib-9.1-r10 sys-libs/libcxx )
52 || ( >=sys-devel/binutils-2.18 >=sys-devel/binutils-apple-5.1 )
53 clang? ( xml? ( virtual/pkgconfig ) )
54 doc? ( dev-python/sphinx )
55 libffi? ( virtual/pkgconfig )
56 !!<dev-python/configparser-3.3.0.2
58 RDEPEND="${COMMON_DEPEND}
59 clang? ( !<=sys-devel/clang-${PV}-r99
60 !>=sys-devel/clang-9999 )
61 abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r2
62 !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
63 PDEPEND="clang? ( =sys-devel/clang-${PV}-r100 )"
65 # pypy gives me around 1700 unresolved tests due to open file limit
66 # being exceeded. probably GC does not close them fast enough.
67 REQUIRED_USE="${PYTHON_REQUIRED_USE}
68 test? ( || ( $(python_gen_useflags 'python*') ) )"
72 # Some people actually override that in make.conf. That sucks since
73 # we need to run install per-directory, and ninja can't do that...
74 # so why did it call itself ninja in the first place?
75 CMAKE_MAKEFILE_GENERATOR=emake
79 # !clang !debug !multitarget -O2 400
80 # !clang !debug multitarget -O2 550
81 # clang !debug !multitarget -O2 950
82 # clang !debug multitarget -O2 1200
83 # !clang debug multitarget -O2 5G
84 # clang !debug multitarget -O0 -g 12G
85 # clang debug multitarget -O2 16G
86 # clang debug multitarget -O0 -g 14G
89 use clang && build_size=1200
92 ewarn "USE=debug is known to increase the size of package considerably"
93 ewarn "and cause the tests to fail."
96 (( build_size *= 14 ))
97 elif is-flagq '-g?(gdb)?([1-9])'; then
98 ewarn "The C++ compiler -g option is known to increase the size of the package"
99 ewarn "considerably. If you run out of space, please consider removing it."
102 (( build_size *= 10 ))
105 # Multiply by number of ABIs :).
106 local abis=( $(multilib_get_enabled_abis) )
107 (( build_size *= ${#abis[@]} ))
109 local CHECKREQS_DISK_BUILD=${build_size}M
110 check-reqs_pkg_pretend
112 if [[ ${MERGE_TYPE} != binary ]]; then
113 echo 'int main() {return 0;}' > "${T}"/test.cxx || die
114 ebegin "Trying to build a C++11 test program"
115 if ! $(tc-getCXX) -std=c++11 -o /dev/null "${T}"/test.cxx; then
116 eerror "LLVM-${PV} requires C++11-capable C++ compiler. Your current compiler"
117 eerror "does not seem to support -std=c++11 option. Please upgrade your compiler"
118 eerror "to gcc-4.7 or an equivalent version supporting C++11."
119 die "Currently active compiler does not support -std=c++11"
132 rm -f "${S}"/tools/clang "${S}"/projects/compiler-rt \
133 || die "symlinks removal failed"
136 mv "${WORKDIR}"/cfe-${PV}.src "${S}"/tools/clang \
137 || die "clang source directory move failed"
138 mv "${WORKDIR}"/compiler-rt-${PV}.src "${S}"/projects/compiler-rt \
139 || die "compiler-rt source directory move failed"
140 mv "${WORKDIR}"/clang-tools-extra-${PV}.src "${S}"/tools/clang/tools/extra \
141 || die "clang-tools-extra source directory move failed"
146 epatch "${FILESDIR}"/${PN}-3.2-nodoctargz.patch
147 epatch "${FILESDIR}"/${PN}-3.5-gcc-4.9.patch
148 epatch "${FILESDIR}"/${PN}-3.5-gentoo-install.patch
149 # Make ocaml warnings non-fatal, bug #537308
150 sed -e "/RUN/s/-warn-error A//" -i test/Bindings/Ocaml/*ml || die
153 # Automatically select active system GCC's libraries, bugs #406163 and #417913
154 epatch "${FILESDIR}"/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
156 epatch "${FILESDIR}"/clang-3.5-gentoo-install.patch
157 epatch "${FILESDIR}"/clang-3.4-darwin_prefix-include-paths.patch
158 eprefixify tools/clang/lib/Frontend/InitHeaderSearch.cpp
161 if use prefix && use clang; then
162 sed -i -e "/^CFLAGS /s@-Werror@-I${EPREFIX}/usr/include@" \
163 projects/compiler-rt/make/platform/clang_*.mk || die
169 tools/llvm-config/llvm-config.cpp
171 use clang && sub_files+=(
172 tools/clang/lib/Driver/Tools.cpp
173 tools/clang/tools/scan-build/scan-build
176 # unfortunately ./configure won't listen to --mandir and the-like, so take
178 # note: we're setting the main libdir intentionally.
179 # where per-ABI is appropriate, we use $(GENTOO_LIBDIR) make.
180 einfo "Fixing install dirs"
181 sed -e "s,@libdir@,$(get_libdir),g" \
182 -e "s,@PF@,${PF},g" \
183 -e "s,@EPREFIX@,${EPREFIX},g" \
184 -i "${sub_files[@]}" \
185 || die "install paths sed failed"
188 # constantly fails for a long time, likely due to our patches
189 rm tools/clang/test/Driver/cross-linux.c || die
198 multilib_src_configure() {
199 # disable timestamps since they confuse ccache
202 --enable-keep-symbols
204 --with-optimize-option=
205 $(tc-is-static-only && echo --disable-shared)
206 $(use_enable !debug optimized)
207 $(use_enable debug assertions)
208 $(use_enable debug expensive-checks)
209 $(use_enable libedit)
210 $(use_enable ncurses terminfo)
214 # well, it's used only by clang executable c-index-test
215 if multilib_is_native_abi && use clang && use xml; then
216 conf_flags+=( XML2CONFIG="$(tc-getPKG_CONFIG) libxml-2.0" )
218 conf_flags+=( ac_cv_prog_XML2CONFIG="" )
221 local targets bindings
222 if use multitarget; then
226 use video_cards_radeon && targets+=',r600'
228 conf_flags+=( --enable-targets=${targets} )
230 if multilib_is_native_abi; then
231 use gold && conf_flags+=( --with-binutils-include="${EPREFIX}"/usr/include/ )
232 # extra commas don't hurt
233 use ocaml && bindings+=',ocaml'
236 [[ ${bindings} ]] || bindings='none'
237 conf_flags+=( --enable-bindings=${bindings} )
240 local CPPFLAGS=${CPPFLAGS}
241 append-cppflags "$(pkg-config --cflags libffi)"
244 # llvm prefers clang over gcc, so we may need to force that
248 econf "${conf_flags[@]}"
255 GENTOO_LIBDIR=$(get_libdir)
258 # for tests, we want it all! otherwise, we may use a little filtering...
259 # adding ONLY_TOOLS also disables unittest building...
260 if [[ ${EBUILD_PHASE_FUNC} != src_test ]]; then
261 local tools=( llvm-config )
262 use clang && tools+=( clang )
264 if multilib_is_native_abi; then
266 opt llvm-as llvm-dis llc llvm-ar llvm-nm llvm-link lli
267 llvm-extract llvm-mc llvm-bcanalyzer llvm-diff macho-dump
268 llvm-objdump llvm-readobj llvm-rtdyld llvm-dwarfdump llvm-cov
269 llvm-size llvm-stress llvm-mcmarkup llvm-profdata
270 llvm-symbolizer obj2yaml yaml2obj lto bugpoint
273 # the build system runs explicitly specified tools in parallel,
274 # so we need to split it into two runs
275 if [[ ${1} != -1 ]]; then
278 use gold && tools+=( gold )
280 # those require clang :)
281 # we need to explicitly specify all its tools
282 # since we're passing BUILD_CLANG_ONLY
283 use clang && tools+=(
284 clang/tools/{clang-check,clang-format,extra}
290 # filter tools + disable unittests implicitly
291 ONLY_TOOLS="${tools[*]}"
293 # this disables unittests & docs from clang
299 multilib_src_compile() {
302 emake "${MAKEARGS[@]}"
304 if multilib_is_native_abi; then
306 emake -C tools "${MAKEARGS[@]}"
309 emake -C "${S}"/docs -f Makefile.sphinx man
310 use clang && emake -C "${S}"/tools/clang/docs/tools \
311 BUILD_FOR_WEBSITE=1 DST_MAN_DIR="${T}"/ man
312 emake -C "${S}"/docs -f Makefile.sphinx html
317 pax-mark m Debug+Asserts+Checks/bin/llvm-rtdyld
318 pax-mark m Debug+Asserts+Checks/bin/lli
319 pax-mark m Debug+Asserts+Checks/bin/lli-child-target
321 pax-mark m Release/bin/llvm-rtdyld
322 pax-mark m Release/bin/lli
323 pax-mark m Release/bin/lli-child-target
327 multilib_src_test() {
331 # build the remaining tools & unittests
332 emake "${MAKEARGS[@]}"
334 pax-mark m unittests/ExecutionEngine/JIT/Release/JITTests
335 pax-mark m unittests/ExecutionEngine/MCJIT/Release/MCJITTests
336 pax-mark m unittests/Support/Release/SupportTests
339 local -x LIT_PRESERVES_TMP=1
340 emake "${MAKEARGS[@]}" check
341 use clang && emake "${MAKEARGS[@]}" -C tools/clang test
345 local MULTILIB_CHOST_TOOLS=(
349 local MULTILIB_WRAPPED_HEADERS=(
350 /usr/include/llvm/Config/config.h
351 /usr/include/llvm/Config/llvm-config.h
355 # note: magic applied below
356 MULTILIB_CHOST_TOOLS+=(
360 /usr/bin/clang++-${PV}
363 MULTILIB_WRAPPED_HEADERS+=(
364 /usr/include/clang/Config/config.h
368 multilib-minimal_src_install
370 # Remove unnecessary headers on FreeBSD, bug #417171
371 use kernel_FreeBSD && use clang && rm "${ED}"usr/lib/clang/${PV}/include/{std,float,iso,limits,tgmath,varargs}*.h
374 multilib_src_install() {
378 local root=${D}/_${ABI}
380 emake "${MAKEARGS[@]}" DESTDIR="${root}" install
381 multibuild_merge_root "${root}" "${D}"
383 if ! multilib_is_native_abi; then
384 # Backwards compat, will be happily removed someday.
385 dosym "${CHOST}"-llvm-config /usr/bin/llvm-config.${ABI}
389 doman "${S}"/docs/_build/man/*.1
390 use clang && doman "${T}"/clang.1
391 dohtml -r "${S}"/docs/_build/html/
394 rm "${WORKDIR}"/${PN}-3.5.0-manpages/clang.1 || die
396 doman "${WORKDIR}"/${PN}-3.5.0-manpages/*.1
399 # Symlink the gold plugin.
401 dodir /usr/${CHOST}/binutils-bin/lib/bfd-plugins
402 dosym ../../../../$(get_libdir)/LLVMgold.so \
403 /usr/${CHOST}/binutils-bin/lib/bfd-plugins/LLVMgold.so
407 # apply CHOST and PV to clang executables
408 # they're statically linked so we don't have to worry about the lib
410 local clang_tools=( clang clang++ )
413 # append ${PV} and symlink back
414 # TODO: use alternatives.eclass? does that make any sense?
415 # maybe with USE=-clang on :0 and USE=clang on older
416 for i in "${clang_tools[@]}"; do
417 mv "${ED%/}/usr/bin/${i}"{,-${PV}} || die
418 dosym "${i}"-${PV} /usr/bin/${i}
421 # now prepend ${CHOST} and let the multilib-build.eclass symlink it
422 if ! multilib_is_native_abi; then
423 # non-native? let's replace it with a simple wrapper
424 for i in "${clang_tools[@]}"; do
425 rm "${ED%/}/usr/bin/${i}-${PV}" || die
426 cat > "${T}"/wrapper.tmp <<-_EOF_
428 exec "${i}-${PV}" $(get_abi_CFLAGS) "\${@}"
430 newbin "${T}"/wrapper.tmp "${i}-${PV}"
435 # Fix install_names on Darwin. The build system is too complicated
436 # to just fix this, so we correct it post-install
437 local lib= f= odylib= ndylib= libpv=${PV}
438 if [[ ${CHOST} == *-darwin* ]] ; then
439 eval $(grep PACKAGE_VERSION= configure)
440 [[ -n ${PACKAGE_VERSION} ]] && libpv=${PACKAGE_VERSION}
441 libpvminor=${libpv%.[0-9]*}
442 for lib in lib{EnhancedDisassembly,LLVM-${libpv},LTO,profile_rt,clang}.dylib LLVMHello.dylib clang/${libpv}/lib/darwin/libclang_rt.asan_{osx,iossim}_dynamic.dylib; do
443 # libEnhancedDisassembly is Darwin10 only, so non-fatal
444 # + omit clang libs if not enabled
445 [[ -f ${ED}/usr/lib/${lib} ]] || continue
447 ebegin "fixing install_name of $lib"
449 -id "${EPREFIX}"/usr/lib/${lib} \
450 "${ED}"/usr/lib/${lib}
453 for f in "${ED}"/usr/bin/* "${ED}"/usr/lib/lib*.dylib "${ED}"/usr/lib/clang/${libpv}/lib/darwin/*.dylib ; do
454 # omit clang libs if not enabled
455 [[ -f "${f}" ]] || continue
457 scanmacho -BF'%n#f' "${f}" | tr ',' '\n' | \
458 while read odylib ; do
462 ndylib="${EPREFIX}"/usr/lib/libclang.dylib
464 */libLLVM-${libpv}.dylib)
465 ndylib="${EPREFIX}"/usr/lib/libLLVM-${libpv}.dylib
467 */libLLVM-${libpvminor}.dylib)
468 ndylib="${EPREFIX}"/usr/lib/libLLVM-${libpvminor}.dylib
471 ndylib="${EPREFIX}"/usr/lib/libLTO.dylib
474 if [[ -n ${ndylib} ]] ; then
475 ebegin "fixing install_name reference to ${odylib} of ${f##*/}"
477 -change "${odylib}" "${ndylib}" \
486 multilib_src_install_all() {
487 insinto /usr/share/vim/vimfiles/syntax
488 doins utils/vim/*.vim
491 cd tools/clang || die
493 if use static-analyzer ; then
494 dobin tools/scan-build/ccc-analyzer
495 dosym ccc-analyzer /usr/bin/c++-analyzer
496 dobin tools/scan-build/scan-build
498 insinto /usr/share/${PN}
499 doins tools/scan-build/scanview.css
500 doins tools/scan-build/sorttable.js
504 if use static-analyzer ; then
505 pushd tools/scan-view >/dev/null || die
507 python_doscript scan-view
509 touch __init__.py || die
510 python_moduleinto clang
511 python_domodule __init__.py Reporter.py Resources ScanView.py startfile.py
513 popd >/dev/null || die
517 pushd bindings/python/clang >/dev/null || die
519 python_moduleinto clang
520 python_domodule __init__.py cindex.py enumerations.py
522 popd >/dev/null || die
525 # AddressSanitizer symbolizer (currently separate)
526 python_doscript "${S}"/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
528 python_foreach_impl python_inst