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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Tue Oct 16 20:18:42 2012 UTC (2 years, 2 months ago) by jlec
Branch: MAIN
Changes since 1.12: +7 -2 lines
Unset FC and F77 if no fortran support is wanted

1 axs 1.6 # Copyright 1999-2012 Gentoo Foundation
2 jlec 1.1 # Distributed under the terms of the GNU General Public License v2
3 jlec 1.13 # $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.12 2012/10/16 18:31:48 jlec Exp $
4 jlec 1.1
5     # @ECLASS: fortran-2.eclass
6     # @MAINTAINER:
7     # jlec@gentoo.org
8     # sci@gentoo.org
9 vapier 1.5 # @AUTHOR:
10     # Author Justin Lecher <jlec@gentoo.org>
11     # Test functions provided by Sebastien Fabbro and Kacper Kowalik
12 jlec 1.1 # @BLURB: Simplify fortran compiler management
13     # @DESCRIPTION:
14 jlec 1.12 # 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     #
18 jlec 1.1 # The eclass tests for working fortran compilers
19     # and exports the variables FC and F77.
20     # Optionally, it checks for extended capabilities based on
21     # the variable options selected in the ebuild
22     # The only phase function exported is fortran-2_pkg_setup.
23 jlec 1.12 #
24     # Example:
25     #
26     # FORTRAN_NEEDED="lapack fortran"
27     #
28     # inherit fortran-2
29     #
30     # FORTRAN_NEED_OPENMP=1
31 jlec 1.1
32     # @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
33     # @DESCRIPTION:
34     # Set to "1" in order to automatically have the eclass abort if the fortran
35     # compiler lacks openmp support.
36     : ${FORTRAN_NEED_OPENMP:=0}
37    
38     # @ECLASS-VARIABLE: FORTRAN_STANDARD
39     # @DESCRIPTION:
40     # Set this, if a special dialect needs to be supported.
41     # Generally not needed as default is sufficient.
42     #
43     # Valid settings are any combination of: 77 90 95 2003
44     : ${FORTRAN_STANDARD:=77}
45    
46 jlec 1.12 # @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    
59 jlec 1.10 inherit eutils toolchain-funcs
60 jlec 1.1
61 jlec 1.12 for _f_use in ${FORTRAN_NEEDED}; do
62     case ${_f_use} in
63     always)
64     DEPEND+=" virtual/fortran"
65     break
66     ;;
67     no)
68     break
69     ;;
70     *)
71     DEPEND+=" ${_f_use}? ( virtual/fortran )"
72     ;;
73     esac
74     done
75     RDEPEND="${DEPEND}"
76    
77 jlec 1.1 # @FUNCTION: _write_testsuite
78     # @INTERNAL
79 vapier 1.5 # @DESCRIPTION:
80     # writes fortran test code
81 jlec 1.1 _write_testsuite() {
82     local filebase=${T}/test-fortran
83    
84     # f77 code
85     cat <<- EOF > "${filebase}.f"
86     end
87     EOF
88    
89     # f90/95 code
90     cat <<- EOF > "${filebase}.f90"
91     end
92     EOF
93    
94     # f2003 code
95     cat <<- EOF > "${filebase}.f03"
96     procedure(), pointer :: p
97     end
98     EOF
99     }
100    
101     # @FUNCTION: _compile_test
102 vapier 1.5 # @INTERNAL
103 jlec 1.1 # @DESCRIPTION:
104     # Takes fortran compiler as first argument and dialect as second.
105     # Checks whether the passed fortran compiler speaks the fortran dialect
106     _compile_test() {
107     local filebase=${T}/test-fortran
108     local fcomp=${1}
109     local fdia=${2}
110     local fcode=${filebase}.f${fdia}
111     local ret
112    
113     [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
114    
115     [[ -f ${fcode} ]] || _write_testsuite
116    
117     ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
118     ret=$?
119    
120     rm -f "${fcode}.x"
121     return ${ret}
122     }
123    
124     # @FUNCTION: _fortran-has-openmp
125 vapier 1.5 # @INTERNAL
126 jlec 1.1 # @DESCRIPTION:
127     # See if the fortran supports OpenMP.
128     _fortran-has-openmp() {
129     local flag
130     local filebase=${T}/test-fc-openmp
131     local fcode=${filebase}.f
132     local ret
133     local _fc=$(tc-getFC)
134    
135     cat <<- EOF > "${fcode}"
136     call omp_get_num_threads
137     end
138     EOF
139    
140     for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
141     ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
142     ret=$?
143     (( ${ret} )) || break
144     done
145    
146     rm -f "${fcode}.x"
147     return ${ret}
148     }
149    
150     # @FUNCTION: _die_msg
151     # @INTERNAL
152 vapier 1.5 # @DESCRIPTION:
153     # Detailed description how to handle fortran support
154 jlec 1.1 _die_msg() {
155     echo
156     eerror "Please install currently selected gcc version with USE=fortran."
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"
159     eerror "fortran dialects are support."
160     echo
161     die "Currently no working fortran compiler is available"
162     }
163    
164     # @FUNCTION: fortran-2_pkg_setup
165     # @DESCRIPTION:
166     # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
167     fortran-2_pkg_setup() {
168 jlec 1.12 for _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 jlec 1.13 if use ${_f_use}; then
179     _fortran_test_function && break
180     else
181     unset FC
182     unset F77
183     fi
184 jlec 1.12 ;;
185     esac
186     done
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() {
194 jlec 1.1 local dialect
195    
196     : ${F77:=$(tc-getFC)}
197    
198     : ${FORTRAN_STANDARD:=77}
199     for dialect in ${FORTRAN_STANDARD}; do
200     case ${dialect} in
201     77) _compile_test $(tc-getF77) || _die_msg ;;
202     90|95) _compile_test $(tc-getFC) 90 || _die_msg ;;
203     2003) _compile_test $(tc-getFC) 03 || _die_msg ;;
204     2008) die "Future" ;;
205     *) die "${dialect} is not a Fortran dialect." ;;
206     esac
207     done
208    
209 jlec 1.12 tc-export F77 FC
210     einfo "Using following Fortran compiler:"
211     einfo " F77: ${F77}"
212     einfo " FC: ${FC}"
213    
214 jlec 1.1 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
215 jlec 1.12 if _fortran-has-openmp; then
216     einfo "${FC} has OPENMP support"
217     else
218 jlec 1.1 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
219 jlec 1.12 fi
220 jlec 1.1 fi
221     }
222    
223     case ${EAPI:-0} in
224 axs 1.6 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
225 jlec 1.1 *) die "EAPI=${EAPI} is not supported" ;;
226     esac

  ViewVC Help
Powered by ViewVC 1.1.20