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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Wed Nov 28 13:03:30 2012 UTC (16 months, 2 weeks ago) by jlec
Branch: MAIN
Changes since 1.15: +41 -39 lines
* Reduce potential clash of function names in global scope
* Use more manpage tags
* resort phase functions to the end
* require at least arguments for _fortran_compile_test()
* log compile tests

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.16 # $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.15 2012/11/28 12:11:51 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.15 # @EXAMPLE:
24 jlec 1.12 # FORTRAN_NEEDED="lapack fortran"
25     #
26     # inherit fortran-2
27     #
28     # FORTRAN_NEED_OPENMP=1
29 jlec 1.1
30     # @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
31     # @DESCRIPTION:
32     # Set to "1" in order to automatically have the eclass abort if the fortran
33     # compiler lacks openmp support.
34     : ${FORTRAN_NEED_OPENMP:=0}
35    
36     # @ECLASS-VARIABLE: FORTRAN_STANDARD
37     # @DESCRIPTION:
38     # Set this, if a special dialect needs to be supported.
39     # Generally not needed as default is sufficient.
40     #
41     # Valid settings are any combination of: 77 90 95 2003
42     : ${FORTRAN_STANDARD:=77}
43    
44 jlec 1.12 # @ECLASS-VARIABLE: FORTRAN_NEEDED
45     # @DESCRIPTION:
46     # If your package has an optional fortran support, set this variable
47     # to the space seperated list of USE triggering the fortran
48     # dependence.
49     #
50     # e.g. FORTRAN_NEEDED=lapack would result in
51     #
52     # DEPEND="lapack? ( virtual/fortran )"
53     #
54     # If unset, we always depend on virtual/fortran.
55     : ${FORTRAN_NEEDED:=always}
56    
57 jlec 1.10 inherit eutils toolchain-funcs
58 jlec 1.1
59 jlec 1.12 for _f_use in ${FORTRAN_NEEDED}; do
60     case ${_f_use} in
61     always)
62     DEPEND+=" virtual/fortran"
63     break
64     ;;
65     no)
66     break
67     ;;
68     *)
69     DEPEND+=" ${_f_use}? ( virtual/fortran )"
70     ;;
71     esac
72     done
73     RDEPEND="${DEPEND}"
74    
75 jlec 1.16 # @FUNCTION: _fortran_write_testsuite
76 jlec 1.1 # @INTERNAL
77 vapier 1.5 # @DESCRIPTION:
78     # writes fortran test code
79 jlec 1.16 _fortran_write_testsuite() {
80 jlec 1.1 local filebase=${T}/test-fortran
81    
82     # f77 code
83     cat <<- EOF > "${filebase}.f"
84     end
85     EOF
86    
87     # f90/95 code
88     cat <<- EOF > "${filebase}.f90"
89     end
90     EOF
91    
92     # f2003 code
93     cat <<- EOF > "${filebase}.f03"
94     procedure(), pointer :: p
95     end
96     EOF
97     }
98    
99 jlec 1.16 # @FUNCTION: _fortran_compile_test
100     # @USAGE: <compiler> [dialect]
101 vapier 1.5 # @INTERNAL
102 jlec 1.1 # @DESCRIPTION:
103     # Takes fortran compiler as first argument and dialect as second.
104     # Checks whether the passed fortran compiler speaks the fortran dialect
105 jlec 1.16 _fortran_compile_test() {
106 jlec 1.1 local filebase=${T}/test-fortran
107     local fcomp=${1}
108     local fdia=${2}
109     local fcode=${filebase}.f${fdia}
110     local ret
111    
112 jlec 1.16 [[ $# -lt 1 ]] && die "_fortran_compile_test() needs at least one arguments"
113 jlec 1.1
114 jlec 1.16 [[ -f ${fcode} ]] || _fortran_write_testsuite
115 jlec 1.1
116 jlec 1.16 ${fcomp} "${fcode}" -o "${fcode}.x" &>> "${T}"/_fortran_compile_test.log
117 jlec 1.1 ret=$?
118    
119     rm -f "${fcode}.x"
120     return ${ret}
121     }
122    
123     # @FUNCTION: _fortran-has-openmp
124 jlec 1.16 # @RETURN: compilers return value
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 jlec 1.16 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" &>> "${T}"/_fortran_compile_test.log
142 jlec 1.1 ret=$?
143     (( ${ret} )) || break
144     done
145    
146     rm -f "${fcode}.x"
147     return ${ret}
148     }
149    
150 jlec 1.16 # @FUNCTION: _fortran_die_msg
151 jlec 1.1 # @INTERNAL
152 vapier 1.5 # @DESCRIPTION:
153     # Detailed description how to handle fortran support
154 jlec 1.16 _fortran_die_msg() {
155 jlec 1.1 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 jlec 1.12 # @FUNCTION: _fortran_test_function
165     # @INTERNAL
166     # @DESCRIPTION:
167     # Internal testfunction for working fortran compiler. It is called in fortran-2_pkg_setup
168     _fortran_test_function() {
169 jlec 1.1 local dialect
170    
171     : ${F77:=$(tc-getFC)}
172    
173     : ${FORTRAN_STANDARD:=77}
174     for dialect in ${FORTRAN_STANDARD}; do
175     case ${dialect} in
176 jlec 1.16 77) _fortran_compile_test $(tc-getF77) || _fortran_die_msg ;;
177     90|95) _fortran_compile_test $(tc-getFC) 90 || _fortran_die_msg ;;
178     2003) _fortran_compile_test $(tc-getFC) 03 || _fortran_die_msg ;;
179 jlec 1.1 2008) die "Future" ;;
180     *) die "${dialect} is not a Fortran dialect." ;;
181     esac
182     done
183    
184 jlec 1.12 tc-export F77 FC
185     einfo "Using following Fortran compiler:"
186     einfo " F77: ${F77}"
187 jlec 1.14 einfo " FC: ${FC}"
188 jlec 1.12
189 jlec 1.1 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
190 jlec 1.12 if _fortran-has-openmp; then
191     einfo "${FC} has OPENMP support"
192     else
193 jlec 1.1 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
194 jlec 1.12 fi
195 jlec 1.1 fi
196     }
197    
198 jlec 1.16 # @FUNCTION: fortran-2_pkg_setup
199     # @DESCRIPTION:
200     # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
201     fortran-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    
223 jlec 1.1 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