public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/sci:cuda commit in: eclass/
@ 2012-11-16 15:50 Justin Lecher
  0 siblings, 0 replies; only message in thread
From: Justin Lecher @ 2012-11-16 15:50 UTC (permalink / raw
  To: gentoo-commits

commit:     c68b60e656ddf468dc9d51704cd0ada7a3dab7c2
Author:     Justin Lecher <jlec <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 16 15:48:47 2012 +0000
Commit:     Justin Lecher <jlec <AT> gentoo <DOT> org>
CommitDate: Fri Nov 16 15:48:47 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/sci.git;a=commit;h=c68b60e6

Add pkg_setup and gcc bindir detection

---
 eclass/cuda.eclass |   91 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/eclass/cuda.eclass b/eclass/cuda.eclass
index 5a72d2f..3672d9e 100644
--- a/eclass/cuda.eclass
+++ b/eclass/cuda.eclass
@@ -9,16 +9,94 @@ inherit toolchain-funcs versionator
 # Justin Lecher <jlec@gentoo.org>
 # @BLURB: Common functions for cuda packages
 
-#  @ECLASS-VARIABLE: 
+# @ECLASS-VARIABLE: NVCCFLAGS
+# DESCRIPTION:
+# nvcc compiler flags (see nvcc --help)
+: ${NVCCFLAGS:=-O2}
 
+# @ECLASS-VARIABLE: CUDA_VERBOSE
+# DESCRIPTION:
+# Being verbose during compilation to see underlying commands
+: ${CUDA_VERBOSE:=true}
 
-# @ECLASS-FUNCTION: CUDA_SUPPORTED_GCC
+if [[ "${CUDA_VERBOSE}" == true ]]; then
+	NVCCFLAGS+=" -v"
+fi
+
+# @ECLASS-FUNCTION: cuda_gccdir
 # @DESCRIPTION:
-# Listing of gcc version slots supported by nvidia cuda tool.
-# Generally only needed py
+# Helper for determination of the latest bindir supported by nvidia cuda toolkit.
+#
+# Calling plain it returns simply the path, but you probably want to add \"-f\""
+# to get the full flag to add to nvcc call.
+#
+# cuda_gccdir-f
+# -> --compiler-bindir="/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
+cuda_gccdir() {
+	local _gcc_bindir _ver _args="" _flag _ret
+
+	# Currently we only support the gnu compiler suite
+	if [[ $(tc-getCXX) != *g++* ]]; then
+		return 2
+	fi
+
+	while [ "$1" ]; do
+		case $1 in
+			-f)
+				_flag="--compiler-bindir="
+				;;
+			*)
+				;;
+		esac
+		shift
+	done
+
+	if [[ ! $(type -P cuda-config) ]]; then
+		eerror "Could not execute cuda-config"
+		eerror "Make sure >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 is installed"
+		die "cuda-config not found"
+	else
+		_args="$(version_sort $(cuda-config -s))"
+		if [[ ! -n ${_args} ]]; then
+			die "Could not determine supported gcc versions from cuda-config"
+		fi
+	fi
+
+	for _ver in ${_args}; do
+      has_version sys-devel/gcc:${_ver} && \
+         _gcc_bindir="$(ls -d ${EPREFIX}/usr/*pc-linux-gnu/gcc-bin/${_ver}* | tail -n 1)"
+   done
+
+   if [[ -n ${_gcc_bindir} ]]; then
+		if [[ -n ${_flag} ]]; then
+			_ret="${_flag}\\\"${_gcc_bindir}\\\""
+		else
+	      _ret="${_gcc_bindir}"
+		fi
+		echo ${_ret}
+		return 0
+	else
+      eerror "Only gcc version(s) ${_args} are supported,"
+		eerror "of which none is installed"
+      die "Only gcc version(s) ${_args} are supported"
+      return 1
+   fi
+}
+
+cuda_pkg_setup() {
+	# Tell nvcc where to find a compatible compiler
+	NVCCFLAGS+=" $(cuda_gccdir -f)"
+
+	# Tell nvcc which flags should be used for underlying C compiler
+	NVCCFLAGS+=" --compiler-options=\"${CXXFLAGS}\""
+
+	export NVCCFLAGS
+}
 
 cuda_pkg_postinst() {
-   if [[ $(tc-getCC) == *gcc* ]] && version_is_at_least 4.7 "$(gcc-version)"; then
+	local a
+	a="$(version_sort $(cuda-config -s))"; a=($a)
+   if [[ $(tc-getCC) == *gcc* ]] && version_is_at_least "$(gcc-version)" ${a[1]}; then
       ewarn "gcc >= 4.6 will not work with CUDA"
       ewarn "Make sure you set an earlier version of gcc with gcc-config"
 		ewarn "or append --compiler-bindir= to the nvcc compiler flags"
@@ -27,9 +105,8 @@ cuda_pkg_postinst() {
    fi
 }
 
-EXPORT_FUNCTIONS pkg_postinst
+EXPORT_FUNCTIONS pkg_setup pkg_postinst
 case "${EAPI:-0}" in
    0|1|2|3|4|5) ;;
    *) die "EAPI=${EAPI} is not supported" ;;
 esac
-


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2012-11-16 15:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-16 15:50 [gentoo-commits] proj/sci:cuda commit in: eclass/ Justin Lecher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox