/[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.18
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.18 2013/07/18 07:03:33 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
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 arguments"
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: compilers return value
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 neccessary"
159 eerror "fortran dialects are support." 162 eerror "fortran dialects are support."
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 testfunction 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
213 195
214 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then 196 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
215 if _fortran-has-openmp; then 197 if _fortran-has-openmp; then
216 einfo "${FC} has OPENMP support" 198 einfo "${FC} has OPENMP support"
217 else 199 else
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 " \
201 "set the FC variable to a compiler that supports OpenMP"
219 fi 202 fi
220 fi 203 fi
204}
205
206# @FUNCTION: fortran-2_pkg_setup
207# @DESCRIPTION:
208# Setup functionallity,
209# checks for a valid fortran compiler and optionally for its openmp support.
210fortran-2_pkg_setup() {
211 for _f_use in ${FORTRAN_NEEDED}; do
212 case ${_f_use} in
213 always)
214 _fortran_test_function && break
215 ;;
216 no)
217 einfo "Forcing fortran support off"
218 break
219 ;;
220 *)
221 if use ${_f_use}; then
222 _fortran_test_function && break
223 else
224 unset FC
225 unset F77
226 fi
227 ;;
228 esac
229 done
221} 230}
222 231
223case ${EAPI:-0} in 232case ${EAPI:-0} in
224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;; 233 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
225 *) die "EAPI=${EAPI} is not supported" ;; 234 *) die "EAPI=${EAPI} is not supported" ;;

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

  ViewVC Help
Powered by ViewVC 1.1.20