EAPI=6 support; removed support befor media-video/vdr-2
[gentoo.git] / eclass / cuda.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 inherit flag-o-matic toolchain-funcs versionator
6
7 # @ECLASS: cuda.eclass
8 # @MAINTAINER:
9 # Justin Lecher <jlec@gentoo.org>
10 # @BLURB: Common functions for cuda packages
11 # @DESCRIPTION:
12 # This eclass contains functions to be used with cuda package. Currently it is
13 # setting and/or sanitizing NVCCFLAGS, the compiler flags for nvcc. This is
14 # automatically done and exported in src_prepare() or manually by calling
15 # cuda_sanatize.
16 # @EXAMPLE:
17 # inherit cuda
18
19 if [[ -z ${_CUDA_ECLASS} ]]; then
20
21 # @ECLASS-VARIABLE: NVCCFLAGS
22 # @DESCRIPTION:
23 # nvcc compiler flags (see nvcc --help), which should be used like
24 # CFLAGS for c compiler
25 : ${NVCCFLAGS:=-O2}
26
27 # @ECLASS-VARIABLE: CUDA_VERBOSE
28 # @DESCRIPTION:
29 # Being verbose during compilation to see underlying commands
30 : ${CUDA_VERBOSE:=true}
31
32 # @FUNCTION: cuda_gccdir
33 # @USAGE: [-f]
34 # @RETURN: gcc bindir compatible with current cuda, optionally (-f) prefixed with "--compiler-bindir="
35 # @DESCRIPTION:
36 # Helper for determination of the latest gcc bindir supported by
37 # then current nvidia cuda toolkit.
38 #
39 # Example:
40 # @CODE
41 # cuda_gccdir -f
42 # -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
43 # @CODE
44 cuda_gccdir() {
45         debug-print-function ${FUNCNAME} "$@"
46
47         local gcc_bindir ver args="" flag ret
48
49         # Currently we only support the gnu compiler suite
50         if [[ $(tc-getCXX) != *g++* ]]; then
51                 ewarn "Currently we only support the gnu compiler suite"
52                 return 2
53         fi
54
55         while [ "$1" ]; do
56                 case $1 in
57                         -f)
58                                 flag="--compiler-bindir="
59                                 ;;
60                         *)
61                                 ;;
62                 esac
63                 shift
64         done
65
66         if ! args=$(cuda-config -s); then
67                 eerror "Could not execute cuda-config"
68                 eerror "Make sure >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 is installed"
69                 die "cuda-config not found"
70         else
71                 args=$(version_sort ${args})
72                 if [[ -z ${args} ]]; then
73                         die "Could not determine supported gcc versions from cuda-config"
74                 fi
75         fi
76
77         for ver in ${args}; do
78                 has_version "=sys-devel/gcc-${ver}*" && \
79                  gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${ver}* | tail -n 1)"
80         done
81
82         if [[ -n ${gcc_bindir} ]]; then
83                 if [[ -n ${flag} ]]; then
84                         ret="${flag}\"${gcc_bindir}\""
85                 else
86                         ret="${gcc_bindir}"
87                 fi
88                 echo ${ret}
89                 return 0
90         else
91                 eerror "Only gcc version(s) ${args} are supported,"
92                 eerror "of which none is installed"
93                 die "Only gcc version(s) ${args} are supported"
94                 return 1
95         fi
96 }
97
98 # @FUNCTION: cuda_sanitize
99 # @DESCRIPTION:
100 # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
101 # passing CXXFLAGS to underlying compiler without disturbing nvcc.
102 cuda_sanitize() {
103         debug-print-function ${FUNCNAME} "$@"
104
105         local rawldflags=$(raw-ldflags)
106         # Be verbose if wanted
107         [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
108
109         # Tell nvcc where to find a compatible compiler
110         NVCCFLAGS+=" $(cuda_gccdir -f)"
111
112         # Tell nvcc which flags should be used for underlying C compiler
113         NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\" --linker-options=\"${rawldflags// /,}\""
114
115         debug-print "Using ${NVCCFLAGS} for cuda"
116         export NVCCFLAGS
117 }
118
119 # @FUNCTION: cuda_pkg_setup
120 # @DESCRIPTION:
121 # Call cuda_src_prepare for EAPIs not supporting src_prepare
122 cuda_pkg_setup() {
123         debug-print-function ${FUNCNAME} "$@"
124
125         cuda_src_prepare
126 }
127
128 # @FUNCTION: cuda_src_prepare
129 # @DESCRIPTION:
130 # Sanitise and export NVCCFLAGS by default
131 cuda_src_prepare() {
132         debug-print-function ${FUNCNAME} "$@"
133
134         cuda_sanitize
135 }
136
137 case "${EAPI:-0}" in
138         0|1)
139                 EXPORT_FUNCTIONS pkg_setup ;;
140         2|3|4|5|6)
141                 EXPORT_FUNCTIONS src_prepare ;;
142         *) die "EAPI=${EAPI} is not supported" ;;
143 esac
144
145 _CUDA_ECLASS=1
146 fi