1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 inherit flag-o-matic toolchain-funcs versionator
8 # Justin Lecher <jlec@gentoo.org>
9 # @BLURB: Common functions for cuda packages
11 # This eclass contains functions to be used with cuda package. Currently it is
12 # setting and/or sanitizing NVCCFLAGS, the compiler flags for nvcc. This is
13 # automatically done and exported in src_prepare() or manually by calling
18 if [[ -z ${_CUDA_ECLASS} ]]; then
20 # @ECLASS-VARIABLE: NVCCFLAGS
22 # nvcc compiler flags (see nvcc --help), which should be used like
23 # CFLAGS for c compiler
26 # @ECLASS-VARIABLE: CUDA_VERBOSE
28 # Being verbose during compilation to see underlying commands
29 : ${CUDA_VERBOSE:=true}
31 # @FUNCTION: cuda_gccdir
33 # @RETURN: gcc bindir compatible with current cuda, optionally (-f) prefixed with "--compiler-bindir "
35 # Helper for determination of the latest gcc bindir supported by
36 # then current nvidia cuda toolkit.
41 # -> --compiler-bindir "/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
44 debug-print-function ${FUNCNAME} "$@"
46 local gcc_bindir ver args="" flag ret
48 # Currently we only support the gnu compiler suite
50 ewarn "Currently we only support the gnu compiler suite"
57 flag="--compiler-bindir "
65 if ! args=$(cuda-config -s); then
66 eerror "Could not execute cuda-config"
67 eerror "Make sure >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 is installed"
68 die "cuda-config not found"
70 args=$(version_sort ${args})
71 if [[ -z ${args} ]]; then
72 die "Could not determine supported gcc versions from cuda-config"
76 for ver in ${args}; do
77 has_version "=sys-devel/gcc-${ver}*" && \
78 gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${ver}* | tail -n 1)"
81 if [[ -n ${gcc_bindir} ]]; then
82 if [[ -n ${flag} ]]; then
83 ret="${flag}\"${gcc_bindir}\""
90 eerror "Only gcc version(s) ${args} are supported,"
91 eerror "of which none is installed"
92 die "Only gcc version(s) ${args} are supported"
97 # @FUNCTION: cuda_sanitize
99 # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
100 # passing CXXFLAGS to underlying compiler without disturbing nvcc.
102 debug-print-function ${FUNCNAME} "$@"
104 local rawldflags=$(raw-ldflags)
105 # Be verbose if wanted
106 [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
108 # Tell nvcc where to find a compatible compiler
109 NVCCFLAGS+=" $(cuda_gccdir -f)"
111 # Tell nvcc which flags should be used for underlying C compiler
112 NVCCFLAGS+=" --compiler-options \"${CXXFLAGS}\" --linker-options \"${rawldflags// /,}\""
114 debug-print "Using ${NVCCFLAGS} for cuda"
118 # @FUNCTION: cuda_pkg_setup
120 # Call cuda_src_prepare for EAPIs not supporting src_prepare
122 debug-print-function ${FUNCNAME} "$@"
127 # @FUNCTION: cuda_src_prepare
129 # Sanitise and export NVCCFLAGS by default
131 debug-print-function ${FUNCNAME} "$@"
138 EXPORT_FUNCTIONS pkg_setup ;;
140 EXPORT_FUNCTIONS src_prepare ;;
141 *) die "EAPI=${EAPI} is not supported" ;;