| 1 |
# Copyright 1999-2012 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.9 2012/10/07 13:15:52 jlec Exp $
|
| 4 |
|
| 5 |
# @ECLASS: fortran-2.eclass
|
| 6 |
# @MAINTAINER:
|
| 7 |
# jlec@gentoo.org
|
| 8 |
# sci@gentoo.org
|
| 9 |
# @AUTHOR:
|
| 10 |
# Author Justin Lecher <jlec@gentoo.org>
|
| 11 |
# Test functions provided by Sebastien Fabbro and Kacper Kowalik
|
| 12 |
# @BLURB: Simplify fortran compiler management
|
| 13 |
# @DESCRIPTION:
|
| 14 |
# If you need a fortran compiler, then you should be inheriting this eclass and
|
| 15 |
# adding virtual/fortran to your dependencies.
|
| 16 |
# The eclass tests for working fortran compilers
|
| 17 |
# and exports the variables FC and F77.
|
| 18 |
# Optionally, it checks for extended capabilities based on
|
| 19 |
# the variable options selected in the ebuild
|
| 20 |
# The only phase function exported is fortran-2_pkg_setup.
|
| 21 |
|
| 22 |
# @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
|
| 23 |
# @DESCRIPTION:
|
| 24 |
# Set to "1" in order to automatically have the eclass abort if the fortran
|
| 25 |
# compiler lacks openmp support.
|
| 26 |
: ${FORTRAN_NEED_OPENMP:=0}
|
| 27 |
|
| 28 |
# @ECLASS-VARIABLE: FORTRAN_STANDARD
|
| 29 |
# @DESCRIPTION:
|
| 30 |
# Set this, if a special dialect needs to be supported.
|
| 31 |
# Generally not needed as default is sufficient.
|
| 32 |
#
|
| 33 |
# Valid settings are any combination of: 77 90 95 2003
|
| 34 |
: ${FORTRAN_STANDARD:=77}
|
| 35 |
|
| 36 |
inherit eutils toolchain-funcs
|
| 37 |
|
| 38 |
# @FUNCTION: _write_testsuite
|
| 39 |
# @INTERNAL
|
| 40 |
# @DESCRIPTION:
|
| 41 |
# writes fortran test code
|
| 42 |
_write_testsuite() {
|
| 43 |
local filebase=${T}/test-fortran
|
| 44 |
|
| 45 |
# f77 code
|
| 46 |
cat <<- EOF > "${filebase}.f"
|
| 47 |
end
|
| 48 |
EOF
|
| 49 |
|
| 50 |
# f90/95 code
|
| 51 |
cat <<- EOF > "${filebase}.f90"
|
| 52 |
end
|
| 53 |
EOF
|
| 54 |
|
| 55 |
# f2003 code
|
| 56 |
cat <<- EOF > "${filebase}.f03"
|
| 57 |
procedure(), pointer :: p
|
| 58 |
end
|
| 59 |
EOF
|
| 60 |
}
|
| 61 |
|
| 62 |
# @FUNCTION: _compile_test
|
| 63 |
# @INTERNAL
|
| 64 |
# @DESCRIPTION:
|
| 65 |
# Takes fortran compiler as first argument and dialect as second.
|
| 66 |
# Checks whether the passed fortran compiler speaks the fortran dialect
|
| 67 |
_compile_test() {
|
| 68 |
local filebase=${T}/test-fortran
|
| 69 |
local fcomp=${1}
|
| 70 |
local fdia=${2}
|
| 71 |
local fcode=${filebase}.f${fdia}
|
| 72 |
local ret
|
| 73 |
|
| 74 |
[[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
|
| 75 |
|
| 76 |
[[ -f ${fcode} ]] || _write_testsuite
|
| 77 |
|
| 78 |
${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
|
| 79 |
ret=$?
|
| 80 |
|
| 81 |
rm -f "${fcode}.x"
|
| 82 |
return ${ret}
|
| 83 |
}
|
| 84 |
|
| 85 |
# @FUNCTION: _fortran-has-openmp
|
| 86 |
# @INTERNAL
|
| 87 |
# @DESCRIPTION:
|
| 88 |
# See if the fortran supports OpenMP.
|
| 89 |
_fortran-has-openmp() {
|
| 90 |
local flag
|
| 91 |
local filebase=${T}/test-fc-openmp
|
| 92 |
local fcode=${filebase}.f
|
| 93 |
local ret
|
| 94 |
local _fc=$(tc-getFC)
|
| 95 |
|
| 96 |
cat <<- EOF > "${fcode}"
|
| 97 |
call omp_get_num_threads
|
| 98 |
end
|
| 99 |
EOF
|
| 100 |
|
| 101 |
for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
|
| 102 |
${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
|
| 103 |
ret=$?
|
| 104 |
(( ${ret} )) || break
|
| 105 |
done
|
| 106 |
|
| 107 |
rm -f "${fcode}.x"
|
| 108 |
return ${ret}
|
| 109 |
}
|
| 110 |
|
| 111 |
# @FUNCTION: _die_msg
|
| 112 |
# @INTERNAL
|
| 113 |
# @DESCRIPTION:
|
| 114 |
# Detailed description how to handle fortran support
|
| 115 |
_die_msg() {
|
| 116 |
echo
|
| 117 |
eerror "Please install currently selected gcc version with USE=fortran."
|
| 118 |
eerror "If you intend to use a different compiler then gfortran, please"
|
| 119 |
eerror "set FC variable accordingly and take care that the neccessary"
|
| 120 |
eerror "fortran dialects are support."
|
| 121 |
echo
|
| 122 |
die "Currently no working fortran compiler is available"
|
| 123 |
}
|
| 124 |
|
| 125 |
# @FUNCTION: fortran-2_pkg_setup
|
| 126 |
# @DESCRIPTION:
|
| 127 |
# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
|
| 128 |
fortran-2_pkg_setup() {
|
| 129 |
local dialect
|
| 130 |
|
| 131 |
: ${F77:=$(tc-getFC)}
|
| 132 |
|
| 133 |
: ${FORTRAN_STANDARD:=77}
|
| 134 |
for dialect in ${FORTRAN_STANDARD}; do
|
| 135 |
case ${dialect} in
|
| 136 |
77) _compile_test $(tc-getF77) || _die_msg ;;
|
| 137 |
90|95) _compile_test $(tc-getFC) 90 || _die_msg ;;
|
| 138 |
2003) _compile_test $(tc-getFC) 03 || _die_msg ;;
|
| 139 |
2008) die "Future" ;;
|
| 140 |
*) die "${dialect} is not a Fortran dialect." ;;
|
| 141 |
esac
|
| 142 |
done
|
| 143 |
|
| 144 |
if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
|
| 145 |
_fortran-has-openmp || \
|
| 146 |
die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
|
| 147 |
fi
|
| 148 |
tc-export F77 FC
|
| 149 |
einfo "Using following Fortran compiler"
|
| 150 |
einfo " F77: ${F77}"
|
| 151 |
einfo " FC: ${FC}"
|
| 152 |
}
|
| 153 |
|
| 154 |
case ${EAPI:-0} in
|
| 155 |
0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
|
| 156 |
*) die "EAPI=${EAPI} is not supported" ;;
|
| 157 |
esac
|
| 158 |
|
| 159 |
if in_iuse fortran; then
|
| 160 |
DEPEND="fortran? ( virtual/fortran )"
|
| 161 |
else
|
| 162 |
DEPEND="virtual/fortran"
|
| 163 |
fi
|
| 164 |
|
| 165 |
RDEPEND="${DEPEND}"
|