/[gentoo-x86]/eclass/cuda.eclass
Gentoo

Contents of /eclass/cuda.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Nov 18 19:54:06 2014 UTC (5 weeks, 1 day ago) by jlec
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
Add missing quotes, thanks mgorny for heads up

1 jlec 1.4 # Copyright 1999-2014 Gentoo Foundation
2 jlec 1.1 # Distributed under the terms of the GNU General Public License v2
3 jlec 1.6 # $Header: /var/cvsroot/gentoo-x86/eclass/cuda.eclass,v 1.5 2014/11/18 19:44:02 jlec Exp $
4 jlec 1.1
5 jlec 1.3 inherit flag-o-matic toolchain-funcs versionator
6 jlec 1.1
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     # @ECLASS-VARIABLE: NVCCFLAGS
20     # @DESCRIPTION:
21     # nvcc compiler flags (see nvcc --help), which should be used like
22     # CFLAGS for c compiler
23     : ${NVCCFLAGS:=-O2}
24    
25     # @ECLASS-VARIABLE: CUDA_VERBOSE
26     # @DESCRIPTION:
27     # Being verbose during compilation to see underlying commands
28     : ${CUDA_VERBOSE:=true}
29    
30     # @FUNCTION: cuda_gccdir
31     # @USAGE: [-f]
32     # @RETURN: gcc bindir compatible with current cuda, optionally (-f) prefixed with "--compiler-bindir="
33     # @DESCRIPTION:
34     # Helper for determination of the latest gcc bindir supported by
35     # then current nvidia cuda toolkit.
36     #
37     # Example:
38     # @CODE
39     # cuda_gccdir -f
40     # -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
41     # @CODE
42     cuda_gccdir() {
43     local gcc_bindir ver args="" flag ret
44    
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"
48     return 2
49     fi
50    
51     while [ "$1" ]; do
52     case $1 in
53     -f)
54     flag="--compiler-bindir="
55     ;;
56     *)
57     ;;
58     esac
59     shift
60     done
61    
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"
66     else
67     args=$(version_sort ${args})
68     if [[ -z ${args} ]]; then
69     die "Could not determine supported gcc versions from cuda-config"
70     fi
71     fi
72    
73     for ver in ${args}; do
74 jlec 1.6 has_version "=sys-devel/gcc-${ver}*" && \
75 jlec 1.1 gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${ver}* | tail -n 1)"
76     done
77    
78     if [[ -n ${gcc_bindir} ]]; then
79     if [[ -n ${flag} ]]; then
80     ret="${flag}\\\"${gcc_bindir}\\\""
81     else
82     ret="${gcc_bindir}"
83     fi
84     echo ${ret}
85     return 0
86     else
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"
90     return 1
91     fi
92     }
93    
94     # @FUNCTION: cuda_sanitize
95     # @DESCRIPTION:
96     # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
97     # passing CXXFLAGS to underlying compiler without disturbing nvcc.
98     cuda_sanitize() {
99 jlec 1.3 local rawldflags=$(raw-ldflags)
100 jlec 1.1 # Be verbose if wanted
101     [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
102    
103     # Tell nvcc where to find a compatible compiler
104 jlec 1.4 NVCCFLAGS+=" $(cuda_gccdir -f)"
105 jlec 1.1
106     # Tell nvcc which flags should be used for underlying C compiler
107 jlec 1.3 NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\" --linker-options=\"${rawldflags// /,}\""
108 jlec 1.1
109 jlec 1.2 debug-print "Using ${NVCCFLAGS} for cuda"
110 jlec 1.1 export NVCCFLAGS
111     }
112    
113     # @FUNCTION: cuda_pkg_setup
114     # @DESCRIPTION:
115     # Call cuda_src_prepare for EAPIs not supporting src_prepare
116     cuda_pkg_setup() {
117     cuda_src_prepare
118     }
119    
120     # @FUNCTION: cuda_src_prepare
121     # @DESCRIPTION:
122     # Sanitise and export NVCCFLAGS by default
123     cuda_src_prepare() {
124     cuda_sanitize
125     }
126    
127    
128     case "${EAPI:-0}" in
129     0|1)
130     EXPORT_FUNCTIONS pkg_setup ;;
131     2|3|4|5)
132     EXPORT_FUNCTIONS src_prepare ;;
133     *) die "EAPI=${EAPI} is not supported" ;;
134     esac

  ViewVC Help
Powered by ViewVC 1.1.20