1 # Copyright 1999-2015 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 # @ECLASS-VARIABLE: NVCCFLAGS
21 # nvcc compiler flags (see nvcc --help), which should be used like
22 # CFLAGS for c compiler
25 # @ECLASS-VARIABLE: CUDA_VERBOSE
27 # Being verbose during compilation to see underlying commands
28 : ${CUDA_VERBOSE:=true}
30 # @FUNCTION: cuda_gccdir
32 # @RETURN: gcc bindir compatible with current cuda, optionally (-f) prefixed with "--compiler-bindir="
34 # Helper for determination of the latest gcc bindir supported by
35 # then current nvidia cuda toolkit.
40 # -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
43 local gcc_bindir ver args="" flag ret
45 # Currently we only support the gnu compiler suite
46 if [[ $(tc-getCXX) != *g++* ]]; then
47 ewarn "Currently we only support the gnu compiler suite"
54 flag="--compiler-bindir="
62 if ! args=$(cuda-config -s); then
63 eerror "Could not execute cuda-config"
64 eerror "Make sure >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 is installed"
65 die "cuda-config not found"
67 args=$(version_sort ${args})
68 if [[ -z ${args} ]]; then
69 die "Could not determine supported gcc versions from cuda-config"
73 for ver in ${args}; do
74 has_version "=sys-devel/gcc-${ver}*" && \
75 gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${ver}* | tail -n 1)"
78 if [[ -n ${gcc_bindir} ]]; then
79 if [[ -n ${flag} ]]; then
80 ret="${flag}\"${gcc_bindir}\""
87 eerror "Only gcc version(s) ${args} are supported,"
88 eerror "of which none is installed"
89 die "Only gcc version(s) ${args} are supported"
94 # @FUNCTION: cuda_sanitize
96 # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
97 # passing CXXFLAGS to underlying compiler without disturbing nvcc.
99 local rawldflags=$(raw-ldflags)
100 # Be verbose if wanted
101 [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
103 # Tell nvcc where to find a compatible compiler
104 NVCCFLAGS+=" $(cuda_gccdir -f)"
106 # Tell nvcc which flags should be used for underlying C compiler
107 NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\" --linker-options=\"${rawldflags// /,}\""
109 debug-print "Using ${NVCCFLAGS} for cuda"
113 # @FUNCTION: cuda_pkg_setup
115 # Call cuda_src_prepare for EAPIs not supporting src_prepare
120 # @FUNCTION: cuda_src_prepare
122 # Sanitise and export NVCCFLAGS by default
130 EXPORT_FUNCTIONS pkg_setup ;;
132 EXPORT_FUNCTIONS src_prepare ;;
133 *) die "EAPI=${EAPI} is not supported" ;;