/[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.1 Revision 1.13
1# Copyright 1999-2011 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.1 2011/06/21 06:44:02 jlec Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.13 2012/10/16 20:18:42 jlec Exp $
4
5# Author Justin Lecher <jlec@gentoo.org>
6# Test functions provided by Sebastien Fabbro and Kacper Kowalik
7 4
8# @ECLASS: fortran-2.eclass 5# @ECLASS: fortran-2.eclass
9# @MAINTAINER: 6# @MAINTAINER:
10# jlec@gentoo.org 7# jlec@gentoo.org
11# sci@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 12# @BLURB: Simplify fortran compiler management
13# @DESCRIPTION: 13# @DESCRIPTION:
14# If you need a fortran compiler, then you should be inheriting this eclass. 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#
15# The eclass tests for working fortran compilers 18# The eclass tests for working fortran compilers
16# and exports the variables FC and F77. 19# and exports the variables FC and F77.
17# Optionally, it checks for extended capabilities based on 20# Optionally, it checks for extended capabilities based on
18# the variable options selected in the ebuild 21# the variable options selected in the ebuild
19# The only phase function exported is fortran-2_pkg_setup. 22# The only phase function exported is fortran-2_pkg_setup.
23#
24# Example:
25#
26# FORTRAN_NEEDED="lapack fortran"
27#
28# inherit fortran-2
29#
30# FORTRAN_NEED_OPENMP=1
20 31
21# @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP 32# @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
22# @DESCRIPTION: 33# @DESCRIPTION:
23# Set to "1" in order to automatically have the eclass abort if the fortran 34# Set to "1" in order to automatically have the eclass abort if the fortran
24# compiler lacks openmp support. 35# compiler lacks openmp support.
30# Generally not needed as default is sufficient. 41# Generally not needed as default is sufficient.
31# 42#
32# Valid settings are any combination of: 77 90 95 2003 43# Valid settings are any combination of: 77 90 95 2003
33: ${FORTRAN_STANDARD:=77} 44: ${FORTRAN_STANDARD:=77}
34 45
46# @ECLASS-VARIABLE: FORTRAN_NEEDED
47# @DESCRIPTION:
48# If your package has an optional fortran support, set this variable
49# to the space seperated list of USE triggering the fortran
50# dependence.
51#
52# e.g. FORTRAN_NEEDED=lapack would result in
53#
54# DEPEND="lapack? ( virtual/fortran )"
55#
56# If unset, we always depend on virtual/fortran.
57: ${FORTRAN_NEEDED:=always}
58
35inherit toolchain-funcs 59inherit eutils toolchain-funcs
36 60
61for _f_use in ${FORTRAN_NEEDED}; do
62 case ${_f_use} in
63 always)
37DEPEND="virtual/fortran" 64 DEPEND+=" virtual/fortran"
65 break
66 ;;
67 no)
68 break
69 ;;
70 *)
71 DEPEND+=" ${_f_use}? ( virtual/fortran )"
72 ;;
73 esac
74done
38RDEPEND="${DEPEND}" 75RDEPEND="${DEPEND}"
39 76
40# @FUNCTION: _write_testsuite 77# @FUNCTION: _write_testsuite
78# @INTERNAL
79# @DESCRIPTION:
41# @DESCRIPTION: writes fortran test code 80# writes fortran test code
42# @INTERNAL
43_write_testsuite() { 81_write_testsuite() {
44 local filebase=${T}/test-fortran 82 local filebase=${T}/test-fortran
45 83
46 # f77 code 84 # f77 code
47 cat <<- EOF > "${filebase}.f" 85 cat <<- EOF > "${filebase}.f"
59 end 97 end
60 EOF 98 EOF
61} 99}
62 100
63# @FUNCTION: _compile_test 101# @FUNCTION: _compile_test
102# @INTERNAL
64# @DESCRIPTION: 103# @DESCRIPTION:
65# Takes fortran compiler as first argument and dialect as second. 104# Takes fortran compiler as first argument and dialect as second.
66# Checks whether the passed fortran compiler speaks the fortran dialect 105# Checks whether the passed fortran compiler speaks the fortran dialect
67# @INTERNAL
68_compile_test() { 106_compile_test() {
69 local filebase=${T}/test-fortran 107 local filebase=${T}/test-fortran
70 local fcomp=${1} 108 local fcomp=${1}
71 local fdia=${2} 109 local fdia=${2}
72 local fcode=${filebase}.f${fdia} 110 local fcode=${filebase}.f${fdia}
82 rm -f "${fcode}.x" 120 rm -f "${fcode}.x"
83 return ${ret} 121 return ${ret}
84} 122}
85 123
86# @FUNCTION: _fortran-has-openmp 124# @FUNCTION: _fortran-has-openmp
125# @INTERNAL
87# @DESCRIPTION: 126# @DESCRIPTION:
88# See if the fortran supports OpenMP. 127# See if the fortran supports OpenMP.
89# @INTERNAL
90_fortran-has-openmp() { 128_fortran-has-openmp() {
91 local flag 129 local flag
92 local filebase=${T}/test-fc-openmp 130 local filebase=${T}/test-fc-openmp
93 local fcode=${filebase}.f 131 local fcode=${filebase}.f
94 local ret 132 local ret
108 rm -f "${fcode}.x" 146 rm -f "${fcode}.x"
109 return ${ret} 147 return ${ret}
110} 148}
111 149
112# @FUNCTION: _die_msg 150# @FUNCTION: _die_msg
151# @INTERNAL
152# @DESCRIPTION:
113# @DESCRIPTION: Detailed description how to handle fortran support 153# Detailed description how to handle fortran support
114# @INTERNAL
115_die_msg() { 154_die_msg() {
116 echo 155 echo
117 eerror "Please install currently selected gcc version with USE=fortran." 156 eerror "Please install currently selected gcc version with USE=fortran."
118 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"
119 eerror "set FC variable accordingly and take care that the neccessary" 158 eerror "set FC variable accordingly and take care that the neccessary"
124 163
125# @FUNCTION: fortran-2_pkg_setup 164# @FUNCTION: fortran-2_pkg_setup
126# @DESCRIPTION: 165# @DESCRIPTION:
127# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support. 166# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
128fortran-2_pkg_setup() { 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
190# @INTERNAL
191# @DESCRIPTION:
192# Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup
193_fortran_test_function() {
129 local dialect 194 local dialect
130 195
131 : ${F77:=$(tc-getFC)} 196 : ${F77:=$(tc-getFC)}
132 197
133 : ${FORTRAN_STANDARD:=77} 198 : ${FORTRAN_STANDARD:=77}
139 2008) die "Future" ;; 204 2008) die "Future" ;;
140 *) die "${dialect} is not a Fortran dialect." ;; 205 *) die "${dialect} is not a Fortran dialect." ;;
141 esac 206 esac
142 done 207 done
143 208
209 tc-export F77 FC
210 einfo "Using following Fortran compiler:"
211 einfo " F77: ${F77}"
212 einfo " FC: ${FC}"
213
144 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then 214 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
145 _fortran-has-openmp || \ 215 if _fortran-has-openmp; then
216 einfo "${FC} has OPENMP support"
217 else
146 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP" 218 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
219 fi
147 fi 220 fi
148 tc-export F77 FC
149} 221}
150 222
151case ${EAPI:-0} in 223case ${EAPI:-0} in
152 1|2|3|4) EXPORT_FUNCTIONS pkg_setup ;; 224 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
153 *) die "EAPI=${EAPI} is not supported" ;; 225 *) die "EAPI=${EAPI} is not supported" ;;
154esac 226esac

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.20