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

Contents of /eclass/cuda.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Fri Jan 11 08:31:49 2013 UTC (17 months, 4 weeks ago) by jlec
Branch: MAIN
Add new eclass

1 jlec 1.1 # Copyright 1999-2013 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3     # $Header: $
4    
5     inherit 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     # @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     has_version sys-devel/gcc:${ver} && \
75     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     # Be verbose if wanted
100     [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
101    
102     # Tell nvcc where to find a compatible compiler
103     NVCCFLAGS+=" $(cuda_gccdir -f)"
104    
105     # Tell nvcc which flags should be used for underlying C compiler
106     NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\""
107    
108     export NVCCFLAGS
109     }
110    
111     # @FUNCTION: cuda_pkg_setup
112     # @DESCRIPTION:
113     # Call cuda_src_prepare for EAPIs not supporting src_prepare
114     cuda_pkg_setup() {
115     cuda_src_prepare
116     }
117    
118     # @FUNCTION: cuda_src_prepare
119     # @DESCRIPTION:
120     # Sanitise and export NVCCFLAGS by default
121     cuda_src_prepare() {
122     cuda_sanitize
123     }
124    
125    
126     case "${EAPI:-0}" in
127     0|1)
128     EXPORT_FUNCTIONS pkg_setup ;;
129     2|3|4|5)
130     EXPORT_FUNCTIONS src_prepare ;;
131     *) die "EAPI=${EAPI} is not supported" ;;
132     esac

  ViewVC Help
Powered by ViewVC 1.1.20