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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Tue Oct 16 18:31:48 2012 UTC (18 months ago) by jlec
Branch: MAIN
Changes since 1.11: +72 -16 lines
Add enhanced DEP support in fortran-2.eclass to easy the usage. Only inherit fortran-2 is need for general use. For a USE dependency on fortran the new FORTRAN_NEEDED=USE variable was introduced

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

  ViewVC Help
Powered by ViewVC 1.1.20