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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Wed Nov 28 13:03:30 2012 UTC (21 months ago) by jlec
Branch: MAIN
Changes since 1.15: +41 -39 lines
* Reduce potential clash of function names in global scope
* Use more manpage tags
* resort phase functions to the end
* require at least arguments for _fortran_compile_test()
* log compile tests

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.15 2012/11/28 12:11:51 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: _fortran_write_testsuite
76 # @INTERNAL
77 # @DESCRIPTION:
78 # writes fortran test code
79 _fortran_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: _fortran_compile_test
100 # @USAGE: <compiler> [dialect]
101 # @INTERNAL
102 # @DESCRIPTION:
103 # Takes fortran compiler as first argument and dialect as second.
104 # Checks whether the passed fortran compiler speaks the fortran dialect
105 _fortran_compile_test() {
106 local filebase=${T}/test-fortran
107 local fcomp=${1}
108 local fdia=${2}
109 local fcode=${filebase}.f${fdia}
110 local ret
111
112 [[ $# -lt 1 ]] && die "_fortran_compile_test() needs at least one arguments"
113
114 [[ -f ${fcode} ]] || _fortran_write_testsuite
115
116 ${fcomp} "${fcode}" -o "${fcode}.x" &>> "${T}"/_fortran_compile_test.log
117 ret=$?
118
119 rm -f "${fcode}.x"
120 return ${ret}
121 }
122
123 # @FUNCTION: _fortran-has-openmp
124 # @RETURN: compilers return value
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" &>> "${T}"/_fortran_compile_test.log
142 ret=$?
143 (( ${ret} )) || break
144 done
145
146 rm -f "${fcode}.x"
147 return ${ret}
148 }
149
150 # @FUNCTION: _fortran_die_msg
151 # @INTERNAL
152 # @DESCRIPTION:
153 # Detailed description how to handle fortran support
154 _fortran_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_test_function
165 # @INTERNAL
166 # @DESCRIPTION:
167 # Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup
168 _fortran_test_function() {
169 local dialect
170
171 : ${F77:=$(tc-getFC)}
172
173 : ${FORTRAN_STANDARD:=77}
174 for dialect in ${FORTRAN_STANDARD}; do
175 case ${dialect} in
176 77) _fortran_compile_test $(tc-getF77) || _fortran_die_msg ;;
177 90|95) _fortran_compile_test $(tc-getFC) 90 || _fortran_die_msg ;;
178 2003) _fortran_compile_test $(tc-getFC) 03 || _fortran_die_msg ;;
179 2008) die "Future" ;;
180 *) die "${dialect} is not a Fortran dialect." ;;
181 esac
182 done
183
184 tc-export F77 FC
185 einfo "Using following Fortran compiler:"
186 einfo " F77: ${F77}"
187 einfo " FC: ${FC}"
188
189 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
190 if _fortran-has-openmp; then
191 einfo "${FC} has OPENMP support"
192 else
193 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
194 fi
195 fi
196 }
197
198 # @FUNCTION: fortran-2_pkg_setup
199 # @DESCRIPTION:
200 # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
201 fortran-2_pkg_setup() {
202 for _f_use in ${FORTRAN_NEEDED}; do
203 case ${_f_use} in
204 always)
205 _fortran_test_function && break
206 ;;
207 no)
208 einfo "Forcing fortran support off"
209 break
210 ;;
211 *)
212 if use ${_f_use}; then
213 _fortran_test_function && break
214 else
215 unset FC
216 unset F77
217 fi
218 ;;
219 esac
220 done
221 }
222
223 case ${EAPI:-0} in
224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
225 *) die "EAPI=${EAPI} is not supported" ;;
226 esac

  ViewVC Help
Powered by ViewVC 1.1.20