Gentoo Archives: gentoo-dev

From: justin <jlec@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] New eclass cuda.eclass
Date: Wed, 28 Nov 2012 11:00:00
Message-Id: 50B5EE7C.8080301@gentoo.org
In Reply to: [gentoo-dev] New eclass cuda.eclass by Justin
1 Please review my inclusion of your suggestions. Additionally I move to
2 src_prepare to be more binpackage compatible as things are only of
3 interest at compile time.
4
5
6 commit 366a690925f5cc5e4bdd2ea984d9ccca65d8f996
7 Author: Justin Lecher <jlec@g.o>
8 Date: Wed Nov 28 11:54:16 2012 +0100
9
10 Be bin package friendly
11
12 Move standard call of cuda_sanitize to src_prepapere as it isn't need
13 for bin packages.
14
15 Signed-off-by: Justin Lecher <jlec@g.o>
16
17 diff --git a/eclass/cuda.eclass b/eclass/cuda.eclass
18 index 08cfb72..beac082 100644
19 --- a/eclass/cuda.eclass
20 +++ b/eclass/cuda.eclass
21 @@ -110,13 +110,23 @@ cuda_sanitize() {
22
23 # @FUNCTION: cuda_pkg_setup
24 # @DESCRIPTION:
25 -# Sanitise and export NVCCFLAGS by default
26 +# Call cuda_src_prepare for EAPIs not supporting src_prepare
27 cuda_pkg_setup() {
28 + cuda_src_prepare
29 +}
30 +
31 +# @FUNCTION: cuda_src_prepare
32 +# @DESCRIPTION:
33 +# Sanitise and export NVCCFLAGS by default
34 +cuda_src_prepare() {
35 cuda_sanitize
36 }
37
38 -EXPORT_FUNCTIONS pkg_setup
39 +
40 case "${EAPI:-0}" in
41 - 0|1|2|3|4|5) ;;
42 + 0|1)
43 + EXPORT_FUNCTIONS pkg_setup ;;
44 + 2|3|4|5)
45 + EXPORT_FUNCTIONS src_prepare ;;
46 *) die "EAPI=${EAPI} is not supported" ;;
47 esac
48
49 commit 07b5a629a7f6e9f163e0dfe9c1927010f527508f
50 Author: Justin Lecher <jlec@g.o>
51 Date: Wed Nov 28 11:24:51 2012 +0100
52
53 Fix typo in Copyright year
54
55 Signed-off-by: Justin Lecher <jlec@g.o>
56
57 diff --git a/eclass/cuda.eclass b/eclass/cuda.eclass
58 index 0b2e084..08cfb72 100644
59 --- a/eclass/cuda.eclass
60 +++ b/eclass/cuda.eclass
61 @@ -1,4 +1,4 @@
62 -# Copyright 1999-20012 Gentoo Foundation
63 +# Copyright 1999-2012 Gentoo Foundation
64 # Distributed under the terms of the GNU General Public License v2
65 # $Header: $
66
67
68 commit 7319422dd7c7427cc741e9bdab2f1211b5af1be4
69 Author: Justin Lecher <jlec@g.o>
70 Date: Wed Nov 28 11:24:16 2012 +0100
71
72 Implemented comments from g-dev review
73
74 * Fix whitespacing
75 * Fix man pages tags
76 * Try to do things in functions instead of global scope
77 * remove _ from local variables
78 * inline check for presents and functionality of cuda-config
79
80 Signed-off-by: Justin Lecher <jlec@g.o>
81
82 diff --git a/eclass/cuda.eclass b/eclass/cuda.eclass
83 index f8ebd81..0b2e084 100644
84 --- a/eclass/cuda.eclass
85 +++ b/eclass/cuda.eclass
86 @@ -13,49 +13,45 @@ inherit toolchain-funcs versionator
87 # setting and/or sanitizing NVCCFLAGS, the compiler flags for nvcc. This is
88 # automatically done and exported in src_prepare() or manually by calling
89 # cuda_sanatize.
90 -#
91 -# Common usage:
92 -#
93 +# @EXAMPLE:
94 # inherit cuda
95
96 # @ECLASS-VARIABLE: NVCCFLAGS
97 -# DESCRIPTION:
98 +# @DESCRIPTION:
99 # nvcc compiler flags (see nvcc --help), which should be used like
100 # CFLAGS for c compiler
101 : ${NVCCFLAGS:=-O2}
102
103 # @ECLASS-VARIABLE: CUDA_VERBOSE
104 -# DESCRIPTION:
105 +# @DESCRIPTION:
106 # Being verbose during compilation to see underlying commands
107 : ${CUDA_VERBOSE:=true}
108
109 -[[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
110 -
111 -# @ECLASS-FUNCTION: cuda_gccdir
112 +# @FUNCTION: cuda_gccdir
113 +# @USAGE: [-f]
114 +# @RETURN: gcc bindir compatible with current cuda, optionally (-f)
115 prefixed with "--compiler-bindir="
116 # @DESCRIPTION:
117 # Helper for determination of the latest gcc bindir supported by
118 # then current nvidia cuda toolkit.
119 #
120 -# Calling plain it returns simply the path, but you probably want to
121 add \"-f\""
122 -# to get the full flag to add to nvcc call.
123 -#
124 # Example:
125 -#
126 +# @CODE
127 # cuda_gccdir -f
128 # -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
129 +# @CODE
130 cuda_gccdir() {
131 - local _gcc_bindir _ver _args="" _flag _ret
132 + local gcc_bindir ver args="" flag ret
133
134 # Currently we only support the gnu compiler suite
135 if [[ $(tc-getCXX) != *g++* ]]; then
136 - ewarn "Currently we only support the gnu compiler suite"
137 + ewarn "Currently we only support the gnu compiler suite"
138 return 2
139 fi
140
141 while [ "$1" ]; do
142 case $1 in
143 -f)
144 - _flag="--compiler-bindir="
145 + flag="--compiler-bindir="
146 ;;
147 *)
148 ;;
149 @@ -63,43 +59,46 @@ cuda_gccdir() {
150 shift
151 done
152
153 - if [[ ! $(type -P cuda-config) ]]; then
154 + if ! args=$(cuda-config -s); then
155 eerror "Could not execute cuda-config"
156 eerror "Make sure >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 is installed"
157 die "cuda-config not found"
158 else
159 - _args="$(version_sort $(cuda-config -s))"
160 - if [[ ! -n ${_args} ]]; then
161 + args=$(version_sort ${args})
162 + if [[ -z ${args} ]]; then
163 die "Could not determine supported gcc versions from cuda-config"
164 fi
165 fi
166
167 - for _ver in ${_args}; do
168 - has_version sys-devel/gcc:${_ver} && \
169 - _gcc_bindir="$(ls -d
170 ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${_ver}* | tail -n 1)"
171 - done
172 + for ver in ${args}; do
173 + has_version sys-devel/gcc:${ver} && \
174 + gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${ver}* |
175 tail -n 1)"
176 + done
177
178 - if [[ -n ${_gcc_bindir} ]]; then
179 - if [[ -n ${_flag} ]]; then
180 - _ret="${_flag}\\\"${_gcc_bindir}\\\""
181 + if [[ -n ${gcc_bindir} ]]; then
182 + if [[ -n ${flag} ]]; then
183 + ret="${flag}\\\"${gcc_bindir}\\\""
184 else
185 - _ret="${_gcc_bindir}"
186 + ret="${gcc_bindir}"
187 fi
188 - echo ${_ret}
189 + echo ${ret}
190 return 0
191 else
192 - eerror "Only gcc version(s) ${_args} are supported,"
193 + eerror "Only gcc version(s) ${args} are supported,"
194 eerror "of which none is installed"
195 - die "Only gcc version(s) ${_args} are supported"
196 + die "Only gcc version(s) ${args} are supported"
197 return 1
198 - fi
199 + fi
200 }
201
202 -# @ECLASS-FUNCTION: cuda_sanitize
203 +# @FUNCTION: cuda_sanitize
204 # @DESCRIPTION:
205 # Correct NVCCFLAGS by adding the necessary reference to gcc bindir and
206 # passing CXXFLAGS to underlying compiler without disturbing nvcc.
207 cuda_sanitize() {
208 + # Be verbose if wanted
209 + [[ "${CUDA_VERBOSE}" == true ]] && NVCCFLAGS+=" -v"
210 +
211 # Tell nvcc where to find a compatible compiler
212 NVCCFLAGS+=" $(cuda_gccdir -f)"
213
214 @@ -109,15 +108,15 @@ cuda_sanitize() {
215 export NVCCFLAGS
216 }
217
218 -# @ECLASS-FUNCTION: cuda_pkg_setup
219 +# @FUNCTION: cuda_pkg_setup
220 # @DESCRIPTION:
221 -# Sanitise and export NVCCFLAGS by default in pkg_setup
222 +# Sanitise and export NVCCFLAGS by default
223 cuda_pkg_setup() {
224 cuda_sanitize
225 }
226
227 EXPORT_FUNCTIONS pkg_setup
228 case "${EAPI:-0}" in
229 - 0|1|2|3|4|5) ;;
230 - *) die "EAPI=${EAPI} is not supported" ;;
231 + 0|1|2|3|4|5) ;;
232 + *) die "EAPI=${EAPI} is not supported" ;;
233 esac

Attachments

File name MIME type
cuda.eclass text/plain
signature.asc application/pgp-signature