Revert "dev-util/nvidia-cuda-toolkit: Drop old"
[gentoo.git] / dev-util / nvidia-cuda-toolkit / nvidia-cuda-toolkit-7.5.18-r2.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit check-reqs cuda unpacker versionator
8
9 MYD=$(get_version_component_range 1-2)
10
11 DESCRIPTION="NVIDIA CUDA Toolkit (compiler and friends)"
12 HOMEPAGE="http://developer.nvidia.com/cuda"
13 SRC_URI="http://developer.download.nvidia.com/compute/cuda/${MYD}/Prod/local_installers/cuda_${PV}_linux.run"
14
15 SLOT="0/${PV}"
16 LICENSE="NVIDIA-CUDA"
17 KEYWORDS="-* ~amd64 ~amd64-linux"
18 IUSE="debugger doc eclipse profiler"
19
20 DEPEND=""
21 RDEPEND="${DEPEND}
22         >=sys-devel/gcc-4.7[cxx]
23         <sys-devel/gcc-5[cxx]
24         >=x11-drivers/nvidia-drivers-352.39[uvm]
25         debugger? (
26                 sys-libs/libtermcap-compat
27                 sys-libs/ncurses[tinfo]
28                 )
29         eclipse? ( >=virtual/jre-1.6 )
30         profiler? ( >=virtual/jre-1.6 )"
31
32 S="${WORKDIR}"
33
34 QA_PREBUILT="opt/cuda/*"
35
36 CHECKREQS_DISK_BUILD="1500M"
37
38 pkg_setup() {
39         # We don't like to run cuda_pkg_setup as it depends on us
40         check-reqs_pkg_setup
41 }
42
43 src_unpack() {
44         unpacker
45         unpacker run_files/cuda-linux*.run
46 }
47
48 src_prepare() {
49         local cuda_supported_gcc
50
51         cuda_supported_gcc="4.7 4.8 4.9"
52
53         sed \
54                 -e "s:CUDA_SUPPORTED_GCC:${cuda_supported_gcc}:g" \
55                 "${FILESDIR}"/cuda-config.in > "${T}"/cuda-config || die
56 }
57
58 src_install() {
59         local i j
60         local remove="doc jre run_files install-linux.pl "
61         local cudadir=/opt/cuda
62         local ecudadir="${EPREFIX}"${cudadir}
63
64         # dodoc doc/*txt
65         if use doc; then
66                 dodoc doc/pdf/*
67                 dohtml -r doc/html/*
68         fi
69
70         mv doc/man/man3/{,cuda-}deprecated.3 || die
71         doman doc/man/man*/*
72
73         use debugger || remove+=" bin/cuda-gdb extras/Debugger"
74         ( use profiler || use eclipse ) || remove+=" libnsight"
75         remove+=" cuda-installer.pl"
76
77         if use profiler; then
78                 # hack found in install-linux.pl
79                 for j in nvvp nsight; do
80                         cat > bin/${j} <<- EOF
81                                 #!${EPREFIX}/bin/sh
82                                 LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:${ecudadir}/lib:${ecudadir}/lib64 \
83                                         UBUNTU_MENUPROXY=0 LIBOVERLAY_SCROLLBAR=0 \
84                                         ${ecudadir}/lib${j}/${j} -vm ${EPREFIX}/usr/bin/java
85                         EOF
86                         chmod a+x bin/${j}
87                 done
88         else
89                 use eclipse || remove+=" libnvvp"
90                 remove+=" extras/CUPTI"
91         fi
92
93         for i in ${remove}; do
94         ebegin "Cleaning ${i}..."
95                 if [[ -e ${i} ]]; then
96                         find ${i} -delete || die
97                         eend
98                 else
99                         eend $1
100                 fi
101         done
102
103         ln -sf lib lib32 || die
104
105         dodir ${cudadir}
106         mv * "${ED}"${cudadir} || die
107
108         cat > "${T}"/99cuda <<- EOF
109                 PATH=${ecudadir}/bin$(use profiler && echo ":${ecudadir}/libnvvp")
110                 ROOTPATH=${ecudadir}/bin
111                 LDPATH=${ecudadir}/lib64:${ecudadir}/lib:${ecudadir}/nvvm/lib64
112         EOF
113         doenvd "${T}"/99cuda
114
115         use profiler && \
116                 make_wrapper nvprof "${EPREFIX}"${cudadir}/bin/nvprof "." ${ecudadir}/lib64:${ecudadir}/lib
117
118         dobin "${T}"/cuda-config
119 }
120
121 pkg_postinst_check() {
122         local a b
123         a="$(version_sort $(cuda-config -s))"; a=( $a )
124         # greatest supported version
125         b=${a[${#a[@]}-1]}
126
127         # if gcc and if not gcc-version is at least greatesst supported
128         if [[ $(tc-getCC) == *gcc* ]] && \
129                 ! version_is_at_least $(gcc-version) ${b}; then
130                         echo
131                         ewarn "gcc >= ${b} will not work with CUDA"
132                         ewarn "Make sure you set an earlier version of gcc with gcc-config"
133                         ewarn "or append --compiler-bindir= pointing to a gcc bindir like"
134                         ewarn "--compiler-bindir=${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/gcc${b}"
135                         ewarn "to the nvcc compiler flags"
136                         echo
137         fi
138 }
139
140 pkg_postinst() {
141         if [[ ${MERGE_TYPE} != binary ]]; then
142                 pkg_postinst_check
143         fi
144 }