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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download)
Wed Nov 28 12:11:51 2012 UTC (20 months ago) by jlec
Branch: MAIN
Changes since 1.14: +2 -4 lines
Use man page tags

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.14 2012/10/18 21:08:57 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.
15 # In case you only need optional support, please export FORTRAN_NEEDED before
16 # inheriting the eclass.
17 #
18 # The eclass tests for working fortran compilers
19 # and exports the variables FC and F77.
20 # Optionally, it checks for extended capabilities based on
21 # the variable options selected in the ebuild
22 # The only phase function exported is fortran-2_pkg_setup.
23 # @EXAMPLE:
24 # FORTRAN_NEEDED="lapack fortran"
25 #
26 # inherit fortran-2
27 #
28 # FORTRAN_NEED_OPENMP=1
29
30 # @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
31 # @DESCRIPTION:
32 # Set to "1" in order to automatically have the eclass abort if the fortran
33 # compiler lacks openmp support.
34 : ${FORTRAN_NEED_OPENMP:=0}
35
36 # @ECLASS-VARIABLE: FORTRAN_STANDARD
37 # @DESCRIPTION:
38 # Set this, if a special dialect needs to be supported.
39 # Generally not needed as default is sufficient.
40 #
41 # Valid settings are any combination of: 77 90 95 2003
42 : ${FORTRAN_STANDARD:=77}
43
44 # @ECLASS-VARIABLE: FORTRAN_NEEDED
45 # @DESCRIPTION:
46 # If your package has an optional fortran support, set this variable
47 # to the space seperated list of USE triggering the fortran
48 # dependence.
49 #
50 # e.g. FORTRAN_NEEDED=lapack would result in
51 #
52 # DEPEND="lapack? ( virtual/fortran )"
53 #
54 # If unset, we always depend on virtual/fortran.
55 : ${FORTRAN_NEEDED:=always}
56
57 inherit eutils toolchain-funcs
58
59 for _f_use in ${FORTRAN_NEEDED}; do
60 case ${_f_use} in
61 always)
62 DEPEND+=" virtual/fortran"
63 break
64 ;;
65 no)
66 break
67 ;;
68 *)
69 DEPEND+=" ${_f_use}? ( virtual/fortran )"
70 ;;
71 esac
72 done
73 RDEPEND="${DEPEND}"
74
75 # @FUNCTION: _write_testsuite
76 # @INTERNAL
77 # @DESCRIPTION:
78 # writes fortran test code
79 _write_testsuite() {
80 local filebase=${T}/test-fortran
81
82 # f77 code
83 cat <<- EOF > "${filebase}.f"
84 end
85 EOF
86
87 # f90/95 code
88 cat <<- EOF > "${filebase}.f90"
89 end
90 EOF
91
92 # f2003 code
93 cat <<- EOF > "${filebase}.f03"
94 procedure(), pointer :: p
95 end
96 EOF
97 }
98
99 # @FUNCTION: _compile_test
100 # @INTERNAL
101 # @DESCRIPTION:
102 # Takes fortran compiler as first argument and dialect as second.
103 # Checks whether the passed fortran compiler speaks the fortran dialect
104 _compile_test() {
105 local filebase=${T}/test-fortran
106 local fcomp=${1}
107 local fdia=${2}
108 local fcode=${filebase}.f${fdia}
109 local ret
110
111 [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
112
113 [[ -f ${fcode} ]] || _write_testsuite
114
115 ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
116 ret=$?
117
118 rm -f "${fcode}.x"
119 return ${ret}
120 }
121
122 # @FUNCTION: _fortran-has-openmp
123 # @INTERNAL
124 # @DESCRIPTION:
125 # See if the fortran supports OpenMP.
126 _fortran-has-openmp() {
127 local flag
128 local filebase=${T}/test-fc-openmp
129 local fcode=${filebase}.f
130 local ret
131 local _fc=$(tc-getFC)
132
133 cat <<- EOF > "${fcode}"
134 call omp_get_num_threads
135 end
136 EOF
137
138 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
139 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
140 ret=$?
141 (( ${ret} )) || break
142 done
143
144 rm -f "${fcode}.x"
145 return ${ret}
146 }
147
148 # @FUNCTION: _die_msg
149 # @INTERNAL
150 # @DESCRIPTION:
151 # Detailed description how to handle fortran support
152 _die_msg() {
153 echo
154 eerror "Please install currently selected gcc version with USE=fortran."
155 eerror "If you intend to use a different compiler then gfortran, please"
156 eerror "set FC variable accordingly and take care that the neccessary"
157 eerror "fortran dialects are support."
158 echo
159 die "Currently no working fortran compiler is available"
160 }
161
162 # @FUNCTION: fortran-2_pkg_setup
163 # @DESCRIPTION:
164 # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
165 fortran-2_pkg_setup() {
166 for _f_use in ${FORTRAN_NEEDED}; do
167 case ${_f_use} in
168 always)
169 _fortran_test_function && break
170 ;;
171 no)
172 einfo "Forcing fortran support off"
173 break
174 ;;
175 *)
176 if use ${_f_use}; then
177 _fortran_test_function && break
178 else
179 unset FC
180 unset F77
181 fi
182 ;;
183 esac
184 done
185 }
186
187 # @FUNCTION: _fortran_test_function
188 # @INTERNAL
189 # @DESCRIPTION:
190 # Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup
191 _fortran_test_function() {
192 local dialect
193
194 : ${F77:=$(tc-getFC)}
195
196 : ${FORTRAN_STANDARD:=77}
197 for dialect in ${FORTRAN_STANDARD}; do
198 case ${dialect} in
199 77) _compile_test $(tc-getF77) || _die_msg ;;
200 90|95) _compile_test $(tc-getFC) 90 || _die_msg ;;
201 2003) _compile_test $(tc-getFC) 03 || _die_msg ;;
202 2008) die "Future" ;;
203 *) die "${dialect} is not a Fortran dialect." ;;
204 esac
205 done
206
207 tc-export F77 FC
208 einfo "Using following Fortran compiler:"
209 einfo " F77: ${F77}"
210 einfo " FC: ${FC}"
211
212 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
213 if _fortran-has-openmp; then
214 einfo "${FC} has OPENMP support"
215 else
216 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
217 fi
218 fi
219 }
220
221 case ${EAPI:-0} in
222 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
223 *) die "EAPI=${EAPI} is not supported" ;;
224 esac

  ViewVC Help
Powered by ViewVC 1.1.20