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

Contents of /eclass/cuda.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sun Aug 11 16:20:23 2013 UTC (13 months, 1 week ago) by jlec
Branch: MAIN
Changes since 1.2: +7 -4 lines
Add compatibility to latest cuda compiler; respect LDFLAGS

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/cuda.eclass,v 1.2 2013/06/22 12:37:28 jlec Exp $
4
5 inherit flag-o-matic 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 local rawldflags=$(raw-ldflags)
100 # Be verbose if wanted
101 [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
102
103 # Tell nvcc where to find a compatible compiler
104 if has_version \<=dev-util/nvidia-cuda-toolkit-5.5; then
105 NVCCFLAGS+=" $(cuda_gccdir -f)"
106 fi
107
108 # Tell nvcc which flags should be used for underlying C compiler
109 NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\" --linker-options=\"${rawldflags// /,}\""
110
111 debug-print "Using ${NVCCFLAGS} for cuda"
112 export NVCCFLAGS
113 }
114
115 # @FUNCTION: cuda_pkg_setup
116 # @DESCRIPTION:
117 # Call cuda_src_prepare for EAPIs not supporting src_prepare
118 cuda_pkg_setup() {
119 cuda_src_prepare
120 }
121
122 # @FUNCTION: cuda_src_prepare
123 # @DESCRIPTION:
124 # Sanitise and export NVCCFLAGS by default
125 cuda_src_prepare() {
126 cuda_sanitize
127 }
128
129
130 case "${EAPI:-0}" in
131 0|1)
132 EXPORT_FUNCTIONS pkg_setup ;;
133 2|3|4|5)
134 EXPORT_FUNCTIONS src_prepare ;;
135 *) die "EAPI=${EAPI} is not supported" ;;
136 esac

  ViewVC Help
Powered by ViewVC 1.1.20