Use https by default
[gentoo.git] / sys-devel / llvm / llvm-3.5.1.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 PYTHON_COMPAT=( python2_7 pypy )
8
9 inherit eutils flag-o-matic multibuild multilib \
10         multilib-minimal python-r1 toolchain-funcs pax-utils check-reqs prefix
11
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 )"
19
20 LICENSE="UoI-NCSA"
21 SLOT="0/3.5"
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"
26
27 COMMON_DEPEND="
28         sys-libs/zlib:0=
29         clang? (
30                 python? ( ${PYTHON_DEPS} )
31                 static-analyzer? (
32                         dev-lang/perl:*
33                         ${PYTHON_DEPS}
34                 )
35                 xml? ( dev-libs/libxml2:2= )
36         )
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}
44         app-arch/xz-utils
45         dev-lang/perl
46         >=sys-devel/make-3.81
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 )
51         )
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
57         ${PYTHON_DEPS}"
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 )"
64
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*') ) )"
69
70 S=${WORKDIR}/${P}.src
71
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
76
77 pkg_pretend() {
78         # in megs
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
87
88         local build_size=550
89         use clang && build_size=1200
90
91         if use debug; then
92                 ewarn "USE=debug is known to increase the size of package considerably"
93                 ewarn "and cause the tests to fail."
94                 ewarn
95
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."
100                 ewarn
101
102                 (( build_size *= 10 ))
103         fi
104
105         # Multiply by number of ABIs :).
106         local abis=( $(multilib_get_enabled_abis) )
107         (( build_size *= ${#abis[@]} ))
108
109         local CHECKREQS_DISK_BUILD=${build_size}M
110         check-reqs_pkg_pretend
111
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"
120                 fi
121                 eend ${?}
122         fi
123 }
124
125 pkg_setup() {
126         pkg_pretend
127 }
128
129 src_unpack() {
130         default
131
132         rm -f "${S}"/tools/clang "${S}"/projects/compiler-rt \
133                 || die "symlinks removal failed"
134
135         if use clang; then
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"
142         fi
143 }
144
145 src_prepare() {
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
151
152         if use clang; then
153                 # Automatically select active system GCC's libraries, bugs #406163 and #417913
154                 epatch "${FILESDIR}"/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
155
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
159         fi
160
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
164         fi
165
166         local sub_files=(
167                 Makefile.config.in
168                 Makefile.rules
169                 tools/llvm-config/llvm-config.cpp
170         )
171         use clang && sub_files+=(
172                 tools/clang/lib/Driver/Tools.cpp
173                 tools/clang/tools/scan-build/scan-build
174         )
175
176         # unfortunately ./configure won't listen to --mandir and the-like, so take
177         # care of this.
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"
186
187         if use clang; then
188                 # constantly fails for a long time, likely due to our patches
189                 rm tools/clang/test/Driver/cross-linux.c || die
190         fi
191
192         # User patches
193         epatch_user
194
195         python_setup
196 }
197
198 multilib_src_configure() {
199         # disable timestamps since they confuse ccache
200         local conf_flags=(
201                 --disable-timestamps
202                 --enable-keep-symbols
203                 --enable-shared
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)
211                 $(use_enable libffi)
212         )
213
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" )
217         else
218                 conf_flags+=( ac_cv_prog_XML2CONFIG="" )
219         fi
220
221         local targets bindings
222         if use multitarget; then
223                 targets='all'
224         else
225                 targets='host,cpp'
226                 use video_cards_radeon && targets+=',r600'
227         fi
228         conf_flags+=( --enable-targets=${targets} )
229
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'
234         fi
235
236         [[ ${bindings} ]] || bindings='none'
237         conf_flags+=( --enable-bindings=${bindings} )
238
239         if use libffi; then
240                 local CPPFLAGS=${CPPFLAGS}
241                 append-cppflags "$(pkg-config --cflags libffi)"
242         fi
243
244         # llvm prefers clang over gcc, so we may need to force that
245         tc-export CC CXX
246
247         ECONF_SOURCE=${S} \
248         econf "${conf_flags[@]}"
249 }
250
251 set_makeargs() {
252         MAKEARGS=(
253                 VERBOSE=1
254                 REQUIRES_RTTI=1
255                 GENTOO_LIBDIR=$(get_libdir)
256         )
257
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 )
263
264                 if multilib_is_native_abi; then
265                         tools+=(
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
271                         )
272
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
276                                 # those require lto
277                                 tools+=( llvm-lto )
278                                 use gold && tools+=( gold )
279
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}
285                                 )
286                         fi
287                 fi
288
289                 MAKEARGS+=(
290                         # filter tools + disable unittests implicitly
291                         ONLY_TOOLS="${tools[*]}"
292
293                         # this disables unittests & docs from clang
294                         BUILD_CLANG_ONLY=YES
295                 )
296         fi
297 }
298
299 multilib_src_compile() {
300         local MAKEARGS
301         set_makeargs -1
302         emake "${MAKEARGS[@]}"
303
304         if multilib_is_native_abi; then
305                 set_makeargs
306                 emake -C tools "${MAKEARGS[@]}"
307
308                 if use doc; then
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
313                 fi
314         fi
315
316         if use debug; then
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
320         else
321                 pax-mark m Release/bin/llvm-rtdyld
322                 pax-mark m Release/bin/lli
323                 pax-mark m Release/bin/lli-child-target
324         fi
325 }
326
327 multilib_src_test() {
328         local MAKEARGS
329         set_makeargs
330
331         # build the remaining tools & unittests
332         emake "${MAKEARGS[@]}"
333
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
337
338         # respect TMPDIR!
339         local -x LIT_PRESERVES_TMP=1
340         emake "${MAKEARGS[@]}" check
341         use clang && emake "${MAKEARGS[@]}" -C tools/clang test
342 }
343
344 src_install() {
345         local MULTILIB_CHOST_TOOLS=(
346                 /usr/bin/llvm-config
347         )
348
349         local MULTILIB_WRAPPED_HEADERS=(
350                 /usr/include/llvm/Config/config.h
351                 /usr/include/llvm/Config/llvm-config.h
352         )
353
354         if use clang; then
355                 # note: magic applied below
356                 MULTILIB_CHOST_TOOLS+=(
357                         /usr/bin/clang
358                         /usr/bin/clang++
359                         /usr/bin/clang-${PV}
360                         /usr/bin/clang++-${PV}
361                 )
362
363                 MULTILIB_WRAPPED_HEADERS+=(
364                         /usr/include/clang/Config/config.h
365                 )
366         fi
367
368         multilib-minimal_src_install
369
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
372 }
373
374 multilib_src_install() {
375         local MAKEARGS
376         set_makeargs
377
378         local root=${D}/_${ABI}
379
380         emake "${MAKEARGS[@]}" DESTDIR="${root}" install
381         multibuild_merge_root "${root}" "${D}"
382
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}
386         else
387                 # Install docs.
388                 if use doc; then
389                         doman "${S}"/docs/_build/man/*.1
390                         use clang && doman "${T}"/clang.1
391                         dohtml -r "${S}"/docs/_build/html/
392                 else
393                         if ! use clang; then
394                                 rm "${WORKDIR}"/${PN}-3.5.0-manpages/clang.1 || die
395                         fi
396                         doman "${WORKDIR}"/${PN}-3.5.0-manpages/*.1
397                 fi
398
399                 # Symlink the gold plugin.
400                 if use gold; then
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
404                 fi
405         fi
406
407         # apply CHOST and PV to clang executables
408         # they're statically linked so we don't have to worry about the lib
409         if use clang; then
410                 local clang_tools=( clang clang++ )
411                 local i
412
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}
419                 done
420
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_
427                                         #!${EPREFIX}/bin/sh
428                                         exec "${i}-${PV}" $(get_abi_CFLAGS) "\${@}"
429                                 _EOF_
430                                 newbin "${T}"/wrapper.tmp "${i}-${PV}"
431                         done
432                 fi
433         fi
434
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
446
447                         ebegin "fixing install_name of $lib"
448                         install_name_tool \
449                                 -id "${EPREFIX}"/usr/lib/${lib} \
450                                 "${ED}"/usr/lib/${lib}
451                         eend $?
452                 done
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
456
457                         scanmacho -BF'%n#f' "${f}" | tr ',' '\n' | \
458                         while read odylib ; do
459                                 ndylib=
460                                 case ${odylib} in
461                                         */libclang.dylib)
462                                                 ndylib="${EPREFIX}"/usr/lib/libclang.dylib
463                                                 ;;
464                                         */libLLVM-${libpv}.dylib)
465                                                 ndylib="${EPREFIX}"/usr/lib/libLLVM-${libpv}.dylib
466                                                 ;;
467                                         */libLLVM-${libpvminor}.dylib)
468                                                 ndylib="${EPREFIX}"/usr/lib/libLLVM-${libpvminor}.dylib
469                                                 ;;
470                                         */libLTO.dylib)
471                                                 ndylib="${EPREFIX}"/usr/lib/libLTO.dylib
472                                                 ;;
473                                 esac
474                                 if [[ -n ${ndylib} ]] ; then
475                                         ebegin "fixing install_name reference to ${odylib} of ${f##*/}"
476                                         install_name_tool \
477                                                 -change "${odylib}" "${ndylib}" \
478                                                 "${f}"
479                                         eend $?
480                                 fi
481                         done
482                 done
483         fi
484 }
485
486 multilib_src_install_all() {
487         insinto /usr/share/vim/vimfiles/syntax
488         doins utils/vim/*.vim
489
490         if use clang; then
491                 cd tools/clang || die
492
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
497
498                         insinto /usr/share/${PN}
499                         doins tools/scan-build/scanview.css
500                         doins tools/scan-build/sorttable.js
501                 fi
502
503                 python_inst() {
504                         if use static-analyzer ; then
505                                 pushd tools/scan-view >/dev/null || die
506
507                                 python_doscript scan-view
508
509                                 touch __init__.py || die
510                                 python_moduleinto clang
511                                 python_domodule __init__.py Reporter.py Resources ScanView.py startfile.py
512
513                                 popd >/dev/null || die
514                         fi
515
516                         if use python ; then
517                                 pushd bindings/python/clang >/dev/null || die
518
519                                 python_moduleinto clang
520                                 python_domodule __init__.py cindex.py enumerations.py
521
522                                 popd >/dev/null || die
523                         fi
524
525                         # AddressSanitizer symbolizer (currently separate)
526                         python_doscript "${S}"/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
527                 }
528                 python_foreach_impl python_inst
529         fi
530 }