/[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.16
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 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.16 2012/11/28 13:03:30 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
113 [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument" 112 [[ $# -lt 1 ]] && die "_fortran_compile_test() needs at least one arguments"
114 113
115 [[ -f ${fcode} ]] || _write_testsuite 114 [[ -f ${fcode} ]] || _fortran_write_testsuite
116 115
117 ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null 116 ${fcomp} "${fcode}" -o "${fcode}.x" &>> "${T}"/_fortran_compile_test.log
118 ret=$? 117 ret=$?
119 118
120 rm -f "${fcode}.x" 119 rm -f "${fcode}.x"
121 return ${ret} 120 return ${ret}
122} 121}
123 122
124# @FUNCTION: _fortran-has-openmp 123# @FUNCTION: _fortran-has-openmp
124# @RETURN: compilers return value
125# @INTERNAL 125# @INTERNAL
126# @DESCRIPTION: 126# @DESCRIPTION:
127# See if the fortran supports OpenMP. 127# See if the fortran supports OpenMP.
128_fortran-has-openmp() { 128_fortran-has-openmp() {
129 local flag 129 local flag
136 call omp_get_num_threads 136 call omp_get_num_threads
137 end 137 end
138 EOF 138 EOF
139 139
140 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do 140 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
141 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null 141 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" &>> "${T}"/_fortran_compile_test.log
142 ret=$? 142 ret=$?
143 (( ${ret} )) || break 143 (( ${ret} )) || break
144 done 144 done
145 145
146 rm -f "${fcode}.x" 146 rm -f "${fcode}.x"
147 return ${ret} 147 return ${ret}
148} 148}
149 149
150# @FUNCTION: _die_msg 150# @FUNCTION: _fortran_die_msg
151# @INTERNAL 151# @INTERNAL
152# @DESCRIPTION: 152# @DESCRIPTION:
153# Detailed description how to handle fortran support 153# Detailed description how to handle fortran support
154_die_msg() { 154_fortran_die_msg() {
155 echo 155 echo
156 eerror "Please install currently selected gcc version with USE=fortran." 156 eerror "Please install currently selected gcc version with USE=fortran."
157 eerror "If you intend to use a different compiler then gfortran, please" 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" 158 eerror "set FC variable accordingly and take care that the neccessary"
159 eerror "fortran dialects are support." 159 eerror "fortran dialects are support."
160 echo 160 echo
161 die "Currently no working fortran compiler is available" 161 die "Currently no working fortran compiler is available"
162} 162}
163 163
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 164# @FUNCTION: _fortran_test_function
190# @INTERNAL 165# @INTERNAL
191# @DESCRIPTION: 166# @DESCRIPTION:
192# Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup 167# Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup
193_fortran_test_function() { 168_fortran_test_function() {
196 : ${F77:=$(tc-getFC)} 171 : ${F77:=$(tc-getFC)}
197 172
198 : ${FORTRAN_STANDARD:=77} 173 : ${FORTRAN_STANDARD:=77}
199 for dialect in ${FORTRAN_STANDARD}; do 174 for dialect in ${FORTRAN_STANDARD}; do
200 case ${dialect} in 175 case ${dialect} in
201 77) _compile_test $(tc-getF77) || _die_msg ;; 176 77) _fortran_compile_test $(tc-getF77) || _fortran_die_msg ;;
202 90|95) _compile_test $(tc-getFC) 90 || _die_msg ;; 177 90|95) _fortran_compile_test $(tc-getFC) 90 || _fortran_die_msg ;;
203 2003) _compile_test $(tc-getFC) 03 || _die_msg ;; 178 2003) _fortran_compile_test $(tc-getFC) 03 || _fortran_die_msg ;;
204 2008) die "Future" ;; 179 2008) die "Future" ;;
205 *) die "${dialect} is not a Fortran dialect." ;; 180 *) die "${dialect} is not a Fortran dialect." ;;
206 esac 181 esac
207 done 182 done
208 183
218 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP" 193 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
219 fi 194 fi
220 fi 195 fi
221} 196}
222 197
198# @FUNCTION: fortran-2_pkg_setup
199# @DESCRIPTION:
200# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
201fortran-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
223case ${EAPI:-0} in 223case ${EAPI:-0} in
224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;; 224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
225 *) die "EAPI=${EAPI} is not supported" ;; 225 *) die "EAPI=${EAPI} is not supported" ;;
226esac 226esac

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

  ViewVC Help
Powered by ViewVC 1.1.20