1 |
Hi all! |
2 |
|
3 |
Here follows the updated version with improvements proposed by |
4 |
mgorny and dilfridge. |
5 |
|
6 |
diff --git a/eclass/fortran-2.eclass b/eclass/fortran-2.eclass |
7 |
index 820cbbcb49bd..a0243714b674 100644 |
8 |
--- a/eclass/fortran-2.eclass |
9 |
+++ b/eclass/fortran-2.eclass |
10 |
@@ -1,285 +1,289 @@ |
11 |
-# Copyright 1999-2017 Gentoo Foundation |
12 |
+# Copyright 1999-2018 Gentoo Authors |
13 |
# Distributed under the terms of the GNU General Public License v2 |
14 |
|
15 |
# @ECLASS: fortran-2.eclass |
16 |
# @MAINTAINER: |
17 |
# jlec@g.o |
18 |
# sci@g.o |
19 |
# @AUTHOR: |
20 |
# Author Justin Lecher <jlec@g.o> |
21 |
# Test functions provided by Sebastien Fabbro and Kacper Kowalik |
22 |
-# @SUPPORTED_EAPIS: 4 5 6 |
23 |
+# @SUPPORTED_EAPIS: 4 5 6 7 |
24 |
# @BLURB: Simplify fortran compiler management |
25 |
# @DESCRIPTION: |
26 |
# If you need a fortran compiler, then you should be inheriting this eclass. |
27 |
# In case you only need optional support, please export FORTRAN_NEEDED before |
28 |
# inheriting the eclass. |
29 |
# |
30 |
# The eclass tests for working fortran compilers |
31 |
# and exports the variables FC and F77. |
32 |
# Optionally, it checks for extended capabilities based on |
33 |
# the variable options selected in the ebuild |
34 |
# The only phase function exported is fortran-2_pkg_setup. |
35 |
# @EXAMPLE: |
36 |
# FORTRAN_NEEDED="lapack fortran" |
37 |
# |
38 |
# inherit fortran-2 |
39 |
# |
40 |
# FORTRAN_NEED_OPENMP=1 |
41 |
|
42 |
-inherit eutils toolchain-funcs |
43 |
+inherit toolchain-funcs |
44 |
+case ${EAPI:-0} in |
45 |
+ # not used in the eclass, but left for backward compatibility with legacy users |
46 |
+ 4|5|6) inherit eutils ;; |
47 |
+ 7) ;; |
48 |
+ *) die "EAPI=${EAPI} is not supported" ;; |
49 |
+esac |
50 |
|
51 |
case ${EAPI:-0} in |
52 |
- 4|5|6) EXPORT_FUNCTIONS pkg_setup ;; |
53 |
+ 4|5|6|7) EXPORT_FUNCTIONS pkg_setup ;; |
54 |
*) die "EAPI=${EAPI} is not supported" ;; |
55 |
esac |
56 |
|
57 |
if [[ ! ${_FORTRAN_2_CLASS} ]]; then |
58 |
|
59 |
# @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP |
60 |
# @DESCRIPTION: |
61 |
# Set to "1" in order to automatically have the eclass abort if the fortran |
62 |
# compiler lacks openmp support. |
63 |
: ${FORTRAN_NEED_OPENMP:=0} |
64 |
|
65 |
# @ECLASS-VARIABLE: FORTRAN_STANDARD |
66 |
# @DESCRIPTION: |
67 |
# Set this, if a special dialect needs to be supported. |
68 |
# Generally not needed as default is sufficient. |
69 |
# |
70 |
# Valid settings are any combination of: 77 90 95 2003 |
71 |
: ${FORTRAN_STANDARD:=77} |
72 |
|
73 |
# @ECLASS-VARIABLE: FORTRAN_NEEDED |
74 |
# @DESCRIPTION: |
75 |
# If your package has an optional fortran support, set this variable |
76 |
# to the space separated list of USE triggering the fortran |
77 |
# dependency. |
78 |
# |
79 |
# e.g. FORTRAN_NEEDED=lapack would result in |
80 |
# |
81 |
# DEPEND="lapack? ( virtual/fortran )" |
82 |
# |
83 |
# If unset, we always depend on virtual/fortran. |
84 |
: ${FORTRAN_NEEDED:=always} |
85 |
|
86 |
for _f_use in ${FORTRAN_NEEDED}; do |
87 |
case ${_f_use} in |
88 |
always) |
89 |
DEPEND+=" virtual/fortran" |
90 |
RDEPEND+=" virtual/fortran" |
91 |
break |
92 |
;; |
93 |
no) |
94 |
break |
95 |
;; |
96 |
test) |
97 |
DEPEND+=" ${_f_use}? ( virtual/fortran )" |
98 |
;; |
99 |
*) |
100 |
DEPEND+=" ${_f_use}? ( virtual/fortran )" |
101 |
RDEPEND+=" ${_f_use}? ( virtual/fortran )" |
102 |
;; |
103 |
esac |
104 |
done |
105 |
unset _f_use |
106 |
|
107 |
# @FUNCTION: fortran_int64_abi_fflags |
108 |
# @DESCRIPTION: |
109 |
# Return the Fortran compiler flag to enable 64 bit integers for |
110 |
# array indices |
111 |
# @CODE |
112 |
fortran_int64_abi_fflags() { |
113 |
debug-print-function ${FUNCNAME} "${@}" |
114 |
|
115 |
- _FC=$(tc-getFC) |
116 |
+ local _FC=$(tc-getFC) |
117 |
if [[ ${_FC} == *gfortran* ]]; then |
118 |
echo "-fdefault-integer-8" |
119 |
elif [[ ${_FC} == ifort ]]; then |
120 |
echo "-integer-size 64" |
121 |
else |
122 |
die "Compiler flag for 64bit interger for ${_FC} unknown" |
123 |
fi |
124 |
} |
125 |
|
126 |
# @FUNCTION: _fortran_write_testsuite |
127 |
# @INTERNAL |
128 |
# @DESCRIPTION: |
129 |
# writes fortran test code |
130 |
_fortran_write_testsuite() { |
131 |
debug-print-function ${FUNCNAME} "${@}" |
132 |
|
133 |
local filebase=${T}/test-fortran |
134 |
|
135 |
# f77 code |
136 |
- cat <<- EOF > "${filebase}.f" |
137 |
+ cat <<- EOF > "${filebase}.f" || die |
138 |
end |
139 |
EOF |
140 |
|
141 |
# f90/95 code |
142 |
- cat <<- EOF > "${filebase}.f90" |
143 |
+ cat <<- EOF > "${filebase}.f90" || die |
144 |
end |
145 |
EOF |
146 |
|
147 |
# f2003 code |
148 |
- cat <<- EOF > "${filebase}.f03" |
149 |
+ cat <<- EOF > "${filebase}.f03" || die |
150 |
procedure(), pointer :: p |
151 |
end |
152 |
EOF |
153 |
} |
154 |
|
155 |
# @FUNCTION: _fortran_compile_test |
156 |
# @USAGE: <compiler> [dialect] |
157 |
# @INTERNAL |
158 |
# @DESCRIPTION: |
159 |
# Takes fortran compiler as first argument and dialect as second. |
160 |
# Checks whether the passed fortran compiler speaks the fortran dialect |
161 |
_fortran_compile_test() { |
162 |
debug-print-function ${FUNCNAME} "${@}" |
163 |
|
164 |
local filebase=${T}/test-fortran |
165 |
local fcomp=${1} |
166 |
local fdia=${2} |
167 |
local fcode=${filebase}.f${fdia} |
168 |
local ret |
169 |
|
170 |
[[ $# -lt 1 ]] && \ |
171 |
die "_fortran_compile_test() needs at least one argument" |
172 |
|
173 |
[[ -f ${fcode} ]] || _fortran_write_testsuite |
174 |
|
175 |
${fcomp} "${fcode}" -o "${fcode}.x" \ |
176 |
>> "${T}"/_fortran_compile_test.log 2>&1 |
177 |
ret=$? |
178 |
|
179 |
rm -f "${fcode}.x" |
180 |
return ${ret} |
181 |
} |
182 |
|
183 |
# @FUNCTION: _fortran-has-openmp |
184 |
# @RETURN: return code of the compiler |
185 |
# @INTERNAL |
186 |
# @DESCRIPTION: |
187 |
# See if the fortran supports OpenMP. |
188 |
_fortran-has-openmp() { |
189 |
debug-print-function ${FUNCNAME} "${@}" |
190 |
|
191 |
local flag |
192 |
local filebase=${T}/test-fc-openmp |
193 |
local fcode=${filebase}.f |
194 |
- local ret |
195 |
local _fc=$(tc-getFC) |
196 |
|
197 |
- cat <<- EOF > "${fcode}" |
198 |
+ cat <<- EOF > "${fcode}" || die |
199 |
call omp_get_num_threads |
200 |
end |
201 |
EOF |
202 |
|
203 |
for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do |
204 |
${_fc} ${flag} "${fcode}" -o "${fcode}.x" \ |
205 |
&>> "${T}"/_fortran_compile_test.log |
206 |
- ret=$? |
207 |
- (( ${ret} )) || break |
208 |
+ [[ $? == 0 ]] && break |
209 |
done |
210 |
|
211 |
rm -f "${fcode}.x" |
212 |
return ${ret} |
213 |
} |
214 |
|
215 |
# @FUNCTION: _fortran_die_msg |
216 |
# @INTERNAL |
217 |
# @DESCRIPTION: |
218 |
# Detailed description how to handle fortran support |
219 |
_fortran_die_msg() { |
220 |
debug-print-function ${FUNCNAME} "${@}" |
221 |
|
222 |
- echo |
223 |
+ eerror |
224 |
eerror "Please install currently selected gcc version with USE=fortran." |
225 |
eerror "If you intend to use a different compiler then gfortran, please" |
226 |
eerror "set FC variable accordingly and take care that the necessary" |
227 |
eerror "fortran dialects are supported." |
228 |
- echo |
229 |
+ eerror |
230 |
die "Currently no working fortran compiler is available (see ${T}/_fortran_compile_test.log for information)" |
231 |
} |
232 |
|
233 |
# @FUNCTION: _fortran_test_function |
234 |
# @INTERNAL |
235 |
# @DESCRIPTION: |
236 |
# Internal test function for working fortran compiler. |
237 |
# It is called in fortran-2_pkg_setup. |
238 |
_fortran_test_function() { |
239 |
debug-print-function ${FUNCNAME} "${@}" |
240 |
|
241 |
local dialect |
242 |
|
243 |
: ${F77:=$(tc-getFC)} |
244 |
|
245 |
: ${FORTRAN_STANDARD:=77} |
246 |
for dialect in ${FORTRAN_STANDARD}; do |
247 |
case ${dialect} in |
248 |
77) _fortran_compile_test $(tc-getF77) || \ |
249 |
_fortran_die_msg ;; |
250 |
90|95) _fortran_compile_test $(tc-getFC) 90 || \ |
251 |
_fortran_die_msg ;; |
252 |
2003) _fortran_compile_test $(tc-getFC) 03 || \ |
253 |
_fortran_die_msg ;; |
254 |
2008) die "Future" ;; |
255 |
*) die "${dialect} is not a Fortran dialect." ;; |
256 |
esac |
257 |
done |
258 |
|
259 |
tc-export F77 FC |
260 |
einfo "Using following Fortran compiler:" |
261 |
einfo " F77: ${F77}" |
262 |
einfo " FC: ${FC}" |
263 |
|
264 |
if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then |
265 |
if _fortran-has-openmp; then |
266 |
einfo "${FC} has OPENMP support" |
267 |
else |
268 |
die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP" |
269 |
fi |
270 |
fi |
271 |
} |
272 |
|
273 |
# @FUNCTION: _fortran-2_pkg_setup |
274 |
# @INTERNAL |
275 |
# @DESCRIPTION: |
276 |
# _The_ fortran-2_pkg_setup() code |
277 |
_fortran-2_pkg_setup() { |
278 |
for _f_use in ${FORTRAN_NEEDED}; do |
279 |
case ${_f_use} in |
280 |
always) |
281 |
- _fortran_test_function && break |
282 |
+ _fortran_test_function && break 2 |
283 |
;; |
284 |
no) |
285 |
einfo "Forcing fortran support off" |
286 |
break |
287 |
;; |
288 |
*) |
289 |
if use ${_f_use}; then |
290 |
- _fortran_test_function && break |
291 |
+ _fortran_test_function && break 2 |
292 |
else |
293 |
unset FC |
294 |
unset F77 |
295 |
fi |
296 |
;; |
297 |
esac |
298 |
done |
299 |
} |
300 |
|
301 |
|
302 |
# @FUNCTION: fortran-2_pkg_setup |
303 |
# @DESCRIPTION: |
304 |
# Setup functionality, |
305 |
# checks for a valid fortran compiler and optionally for its openmp support. |
306 |
fortran-2_pkg_setup() { |
307 |
debug-print-function ${FUNCNAME} "${@}" |
308 |
|
309 |
if [[ ${MERGE_TYPE} != binary ]]; then |
310 |
_fortran-2_pkg_setup |
311 |
fi |
312 |
} |
313 |
|
314 |
_FORTRAN_2_ECLASS=1 |
315 |
fi |
316 |
|
317 |
|
318 |
Best regards, |
319 |
Andrew Savchenko |