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

Diff of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.14 Revision 1.20
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 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 $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.20 2013/07/29 20:13:57 jlec Exp $
4 4
5# @ECLASS: fortran-2.eclass 5# @ECLASS: fortran-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# jlec@gentoo.org 7# jlec@gentoo.org
8# sci@gentoo.org 8# sci@gentoo.org
18# The eclass tests for working fortran compilers 18# The eclass tests for working fortran compilers
19# and exports the variables FC and F77. 19# and exports the variables FC and F77.
20# Optionally, it checks for extended capabilities based on 20# Optionally, it checks for extended capabilities based on
21# the variable options selected in the ebuild 21# the variable options selected in the ebuild
22# The only phase function exported is fortran-2_pkg_setup. 22# The only phase function exported is fortran-2_pkg_setup.
23# 23# @EXAMPLE:
24# Example:
25#
26# FORTRAN_NEEDED="lapack fortran" 24# FORTRAN_NEEDED="lapack fortran"
27# 25#
28# inherit fortran-2 26# inherit fortran-2
29# 27#
30# FORTRAN_NEED_OPENMP=1 28# FORTRAN_NEED_OPENMP=1
44: ${FORTRAN_STANDARD:=77} 42: ${FORTRAN_STANDARD:=77}
45 43
46# @ECLASS-VARIABLE: FORTRAN_NEEDED 44# @ECLASS-VARIABLE: FORTRAN_NEEDED
47# @DESCRIPTION: 45# @DESCRIPTION:
48# If your package has an optional fortran support, set this variable 46# If your package has an optional fortran support, set this variable
49# to the space seperated list of USE triggering the fortran 47# to the space separated list of USE triggering the fortran
50# dependence. 48# dependency.
51# 49#
52# e.g. FORTRAN_NEEDED=lapack would result in 50# e.g. FORTRAN_NEEDED=lapack would result in
53# 51#
54# DEPEND="lapack? ( virtual/fortran )" 52# DEPEND="lapack? ( virtual/fortran )"
55# 53#
72 ;; 70 ;;
73 esac 71 esac
74done 72done
75RDEPEND="${DEPEND}" 73RDEPEND="${DEPEND}"
76 74
77# @FUNCTION: _write_testsuite 75# @FUNCTION: _fortran_write_testsuite
78# @INTERNAL 76# @INTERNAL
79# @DESCRIPTION: 77# @DESCRIPTION:
80# writes fortran test code 78# writes fortran test code
81_write_testsuite() { 79_fortran_write_testsuite() {
82 local filebase=${T}/test-fortran 80 local filebase=${T}/test-fortran
83 81
84 # f77 code 82 # f77 code
85 cat <<- EOF > "${filebase}.f" 83 cat <<- EOF > "${filebase}.f"
86 end 84 end
96 procedure(), pointer :: p 94 procedure(), pointer :: p
97 end 95 end
98 EOF 96 EOF
99} 97}
100 98
101# @FUNCTION: _compile_test 99# @FUNCTION: _fortran_compile_test
100# @USAGE: <compiler> [dialect]
102# @INTERNAL 101# @INTERNAL
103# @DESCRIPTION: 102# @DESCRIPTION:
104# Takes fortran compiler as first argument and dialect as second. 103# Takes fortran compiler as first argument and dialect as second.
105# Checks whether the passed fortran compiler speaks the fortran dialect 104# Checks whether the passed fortran compiler speaks the fortran dialect
106_compile_test() { 105_fortran_compile_test() {
107 local filebase=${T}/test-fortran 106 local filebase=${T}/test-fortran
108 local fcomp=${1} 107 local fcomp=${1}
109 local fdia=${2} 108 local fdia=${2}
110 local fcode=${filebase}.f${fdia} 109 local fcode=${filebase}.f${fdia}
111 local ret 110 local ret
112 111
112 [[ $# -lt 1 ]] && \
113 [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument" 113 die "_fortran_compile_test() needs at least one argument"
114 114
115 [[ -f ${fcode} ]] || _write_testsuite 115 [[ -f ${fcode} ]] || _fortran_write_testsuite
116 116
117 ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null 117 ${fcomp} "${fcode}" -o "${fcode}.x" \
118 >> "${T}"/_fortran_compile_test.log 2>&1
118 ret=$? 119 ret=$?
119 120
120 rm -f "${fcode}.x" 121 rm -f "${fcode}.x"
121 return ${ret} 122 return ${ret}
122} 123}
123 124
124# @FUNCTION: _fortran-has-openmp 125# @FUNCTION: _fortran-has-openmp
126# @RETURN: return code of the compiler
125# @INTERNAL 127# @INTERNAL
126# @DESCRIPTION: 128# @DESCRIPTION:
127# See if the fortran supports OpenMP. 129# See if the fortran supports OpenMP.
128_fortran-has-openmp() { 130_fortran-has-openmp() {
129 local flag 131 local flag
136 call omp_get_num_threads 138 call omp_get_num_threads
137 end 139 end
138 EOF 140 EOF
139 141
140 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do 142 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
141 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null 143 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" \
144 &>> "${T}"/_fortran_compile_test.log
142 ret=$? 145 ret=$?
143 (( ${ret} )) || break 146 (( ${ret} )) || break
144 done 147 done
145 148
146 rm -f "${fcode}.x" 149 rm -f "${fcode}.x"
147 return ${ret} 150 return ${ret}
148} 151}
149 152
150# @FUNCTION: _die_msg 153# @FUNCTION: _fortran_die_msg
151# @INTERNAL 154# @INTERNAL
152# @DESCRIPTION: 155# @DESCRIPTION:
153# Detailed description how to handle fortran support 156# Detailed description how to handle fortran support
154_die_msg() { 157_fortran_die_msg() {
155 echo 158 echo
156 eerror "Please install currently selected gcc version with USE=fortran." 159 eerror "Please install currently selected gcc version with USE=fortran."
157 eerror "If you intend to use a different compiler then gfortran, please" 160 eerror "If you intend to use a different compiler then gfortran, please"
158 eerror "set FC variable accordingly and take care that the neccessary" 161 eerror "set FC variable accordingly and take care that the necessary"
159 eerror "fortran dialects are support." 162 eerror "fortran dialects are supported."
160 echo 163 echo
161 die "Currently no working fortran compiler is available" 164 die "Currently no working fortran compiler is available"
162} 165}
163 166
164# @FUNCTION: fortran-2_pkg_setup
165# @DESCRIPTION:
166# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
167fortran-2_pkg_setup() {
168for _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 if use ${_f_use}; then
179 _fortran_test_function && break
180 else
181 unset FC
182 unset F77
183 fi
184 ;;
185 esac
186done
187}
188
189# @FUNCTION: _fortran_test_function 167# @FUNCTION: _fortran_test_function
190# @INTERNAL 168# @INTERNAL
191# @DESCRIPTION: 169# @DESCRIPTION:
192# Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup 170# Internal test function for working fortran compiler.
171# It is called in fortran-2_pkg_setup.
193_fortran_test_function() { 172_fortran_test_function() {
194 local dialect 173 local dialect
195 174
196 : ${F77:=$(tc-getFC)} 175 : ${F77:=$(tc-getFC)}
197 176
198 : ${FORTRAN_STANDARD:=77} 177 : ${FORTRAN_STANDARD:=77}
199 for dialect in ${FORTRAN_STANDARD}; do 178 for dialect in ${FORTRAN_STANDARD}; do
200 case ${dialect} in 179 case ${dialect} in
201 77) _compile_test $(tc-getF77) || _die_msg ;; 180 77) _fortran_compile_test $(tc-getF77) || \
181 _fortran_die_msg ;;
202 90|95) _compile_test $(tc-getFC) 90 || _die_msg ;; 182 90|95) _fortran_compile_test $(tc-getFC) 90 || \
183 _fortran_die_msg ;;
203 2003) _compile_test $(tc-getFC) 03 || _die_msg ;; 184 2003) _fortran_compile_test $(tc-getFC) 03 || \
185 _fortran_die_msg ;;
204 2008) die "Future" ;; 186 2008) die "Future" ;;
205 *) die "${dialect} is not a Fortran dialect." ;; 187 *) die "${dialect} is not a Fortran dialect." ;;
206 esac 188 esac
207 done 189 done
208 190
218 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP" 200 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
219 fi 201 fi
220 fi 202 fi
221} 203}
222 204
205# @FUNCTION: _fortran-2_pkg_setup
206# @INTERNAL
207# @DESCRIPTION:
208# _The_ fortran-2_pkg_setup() code
209_fortran-2_pkg_setup() {
210 for _f_use in ${FORTRAN_NEEDED}; do
211 case ${_f_use} in
212 always)
213 _fortran_test_function && break
214 ;;
215 no)
216 einfo "Forcing fortran support off"
217 break
218 ;;
219 *)
220 if use ${_f_use}; then
221 _fortran_test_function && break
222 else
223 unset FC
224 unset F77
225 fi
226 ;;
227 esac
228 done
229}
230
231
232# @FUNCTION: fortran-2_pkg_setup
233# @DESCRIPTION:
234# Setup functionality,
235# checks for a valid fortran compiler and optionally for its openmp support.
236fortran-2_pkg_setup() {
237 case ${EAPI:-0} in
238 0|1|2|3)
239 eqawarn "Support for EAPI < 4 will be removed from the"
240 eqawarn "fortran-2.eclass in until 2013-09-30."
241 eqawarn "Please migrate your package to a higher EAPI"
242 eqawarn "or file a bug at https://bugs.gentoo.org"
243 _fortran-2_pkg_setup ;;
244 4|5)
245 if [[ ${MERGE_TYPE} != binary ]]; then
246 _fortran-2_pkg_setup
247 fi
248 ;;
249 esac
250}
251
223case ${EAPI:-0} in 252case ${EAPI:-0} in
224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;; 253 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
225 *) die "EAPI=${EAPI} is not supported" ;; 254 *) die "EAPI=${EAPI} is not supported" ;;
226esac 255esac
256

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20