-# Copyright 1999-2015 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-# $Id$
# @ECLASS: fortran-2.eclass
# @MAINTAINER:
# @AUTHOR:
# Author Justin Lecher <jlec@gentoo.org>
# Test functions provided by Sebastien Fabbro and Kacper Kowalik
+# @SUPPORTED_EAPIS: 4 5 6 7
# @BLURB: Simplify fortran compiler management
# @DESCRIPTION:
# If you need a fortran compiler, then you should be inheriting this eclass.
#
# FORTRAN_NEED_OPENMP=1
+inherit toolchain-funcs
+case ${EAPI:-0} in
+ # not used in the eclass, but left for backward compatibility with legacy users
+ 4|5|6) inherit eutils ;;
+ 7) ;;
+ *) die "EAPI=${EAPI} is not supported" ;;
+esac
+
+EXPORT_FUNCTIONS pkg_setup
+
if [[ ! ${_FORTRAN_2_CLASS} ]]; then
# @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
# If unset, we always depend on virtual/fortran.
: ${FORTRAN_NEEDED:=always}
-inherit eutils toolchain-funcs
-
for _f_use in ${FORTRAN_NEEDED}; do
case ${_f_use} in
always)
;;
esac
done
+unset _f_use
# @FUNCTION: fortran_int64_abi_fflags
-# @DESCRIPTION: Return the Fortran compiler flag to enable 64 bit integers for
+# @DESCRIPTION:
+# Return the Fortran compiler flag to enable 64 bit integers for
# array indices
# @CODE
fortran_int64_abi_fflags() {
debug-print-function ${FUNCNAME} "${@}"
- _FC=$(tc-getFC)
+
+ local _FC=$(tc-getFC)
if [[ ${_FC} == *gfortran* ]]; then
echo "-fdefault-integer-8"
elif [[ ${_FC} == ifort ]]; then
# @DESCRIPTION:
# writes fortran test code
_fortran_write_testsuite() {
+ debug-print-function ${FUNCNAME} "${@}"
+
local filebase=${T}/test-fortran
# f77 code
- cat <<- EOF > "${filebase}.f"
+ cat <<- EOF > "${filebase}.f" || die
end
EOF
# f90/95 code
- cat <<- EOF > "${filebase}.f90"
+ cat <<- EOF > "${filebase}.f90" || die
end
EOF
# f2003 code
- cat <<- EOF > "${filebase}.f03"
+ cat <<- EOF > "${filebase}.f03" || die
procedure(), pointer :: p
end
EOF
# Takes fortran compiler as first argument and dialect as second.
# Checks whether the passed fortran compiler speaks the fortran dialect
_fortran_compile_test() {
+ debug-print-function ${FUNCNAME} "${@}"
+
local filebase=${T}/test-fortran
local fcomp=${1}
local fdia=${2}
# @DESCRIPTION:
# See if the fortran supports OpenMP.
_fortran-has-openmp() {
+ debug-print-function ${FUNCNAME} "${@}"
+
local flag
local filebase=${T}/test-fc-openmp
local fcode=${filebase}.f
local ret
local _fc=$(tc-getFC)
- cat <<- EOF > "${fcode}"
+ cat <<- EOF > "${fcode}" || die
call omp_get_num_threads
end
EOF
${_fc} ${flag} "${fcode}" -o "${fcode}.x" \
&>> "${T}"/_fortran_compile_test.log
ret=$?
- (( ${ret} )) || break
+ [[ ${ret} == 0 ]] && break
done
rm -f "${fcode}.x"
# @DESCRIPTION:
# Detailed description how to handle fortran support
_fortran_die_msg() {
- echo
+ debug-print-function ${FUNCNAME} "${@}"
+
+ eerror
eerror "Please install currently selected gcc version with USE=fortran."
eerror "If you intend to use a different compiler then gfortran, please"
eerror "set FC variable accordingly and take care that the necessary"
eerror "fortran dialects are supported."
- echo
- die "Currently no working fortran compiler is available"
+ eerror
+ die "Currently no working fortran compiler is available (see ${T}/_fortran_compile_test.log for information)"
}
# @FUNCTION: _fortran_test_function
# Internal test function for working fortran compiler.
# It is called in fortran-2_pkg_setup.
_fortran_test_function() {
+ debug-print-function ${FUNCNAME} "${@}"
+
local dialect
: ${F77:=$(tc-getFC)}
for _f_use in ${FORTRAN_NEEDED}; do
case ${_f_use} in
always)
- _fortran_test_function && break
+ _fortran_test_function && break 2
;;
no)
einfo "Forcing fortran support off"
;;
*)
if use ${_f_use}; then
- _fortran_test_function && break
+ _fortran_test_function && break 2
else
unset FC
unset F77
# Setup functionality,
# checks for a valid fortran compiler and optionally for its openmp support.
fortran-2_pkg_setup() {
- case ${EAPI:-0} in
- 0|1|2|3)
- eqawarn "Support for EAPI < 4 will be removed from the"
- eqawarn "fortran-2.eclass in until 2013-09-30."
- eqawarn "Please migrate your package to a higher EAPI"
- eqawarn "or file a bug at https://bugs.gentoo.org"
- _fortran-2_pkg_setup ;;
- 4|5)
- if [[ ${MERGE_TYPE} != binary ]]; then
- _fortran-2_pkg_setup
- fi
- ;;
- esac
-}
+ debug-print-function ${FUNCNAME} "${@}"
-case ${EAPI:-0} in
- 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
- *) die "EAPI=${EAPI} is not supported" ;;
-esac
+ if [[ ${MERGE_TYPE} != binary ]]; then
+ _fortran-2_pkg_setup
+ fi
+}
_FORTRAN_2_ECLASS=1
fi