/[gentoo-x86]/eclass/fortran-2.eclass
Gentoo

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Sun Oct 7 13:10:27 2012 UTC (21 months, 3 weeks ago) by jlec
Branch: MAIN
Changes since 1.7: +5 -3 lines
Depend on virtual/fortran eclass wise, #435250

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

  ViewVC Help
Powered by ViewVC 1.1.20