1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 inherit flag-o-matic toolchain-funcs versionator
9 # Justin Lecher <jlec@gentoo.org>
10 # @BLURB: Common functions for cuda packages
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
19 if [[ -z ${_CUDA_ECLASS} ]]; then
21 # @ECLASS-VARIABLE: NVCCFLAGS
23 # nvcc compiler flags (see nvcc --help), which should be used like
24 # CFLAGS for c compiler
27 # @ECLASS-VARIABLE: CUDA_VERBOSE
29 # Being verbose during compilation to see underlying commands
30 : ${CUDA_VERBOSE:=true}
32 # @FUNCTION: cuda_gccdir
34 # @RETURN: gcc bindir compatible with current cuda, optionally (-f) prefixed with "--compiler-bindir="
36 # Helper for determination of the latest gcc bindir supported by
37 # then current nvidia cuda toolkit.
42 # -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
45 debug-print-function ${FUNCNAME} "$@"
47 local gcc_bindir ver args="" flag ret
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"
58 flag="--compiler-bindir="
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"
71 args=$(version_sort ${args})
72 if [[ -z ${args} ]]; then
73 die "Could not determine supported gcc versions from cuda-config"
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)"
82 if [[ -n ${gcc_bindir} ]]; then
83 if [[ -n ${flag} ]]; then
84 ret="${flag}\"${gcc_bindir}\""
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"
98 # @FUNCTION: cuda_sanitize
100 # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
101 # passing CXXFLAGS to underlying compiler without disturbing nvcc.
103 debug-print-function ${FUNCNAME} "$@"
105 local rawldflags=$(raw-ldflags)
106 # Be verbose if wanted
107 [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
109 # Tell nvcc where to find a compatible compiler
110 NVCCFLAGS+=" $(cuda_gccdir -f)"
112 # Tell nvcc which flags should be used for underlying C compiler
113 NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\" --linker-options=\"${rawldflags// /,}\""
115 debug-print "Using ${NVCCFLAGS} for cuda"
119 # @FUNCTION: cuda_pkg_setup
121 # Call cuda_src_prepare for EAPIs not supporting src_prepare
123 debug-print-function ${FUNCNAME} "$@"
128 # @FUNCTION: cuda_src_prepare
130 # Sanitise and export NVCCFLAGS by default
132 debug-print-function ${FUNCNAME} "$@"
139 EXPORT_FUNCTIONS pkg_setup ;;
141 EXPORT_FUNCTIONS src_prepare ;;
142 *) die "EAPI=${EAPI} is not supported" ;;