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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Thu Jul 18 07:03:33 2013 UTC (13 months, 4 weeks ago) by jlec
Branch: MAIN
Changes since 1.17: +19 -10 lines
Wrap lines at 80 char

1 jlec 1.17 # Copyright 1999-2013 Gentoo Foundation
2 jlec 1.1 # Distributed under the terms of the GNU General Public License v2
3 jlec 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.17 2013/03/13 11:03:12 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.18 [[ $# -lt 1 ]] && \
113     die "_fortran_compile_test() needs at least one arguments"
114 jlec 1.1
115 jlec 1.16 [[ -f ${fcode} ]] || _fortran_write_testsuite
116 jlec 1.1
117 jlec 1.18 ${fcomp} "${fcode}" -o "${fcode}.x" \
118     >> "${T}"/_fortran_compile_test.log 2>&1
119 jlec 1.1 ret=$?
120    
121     rm -f "${fcode}.x"
122     return ${ret}
123     }
124    
125     # @FUNCTION: _fortran-has-openmp
126 jlec 1.16 # @RETURN: compilers return value
127 vapier 1.5 # @INTERNAL
128 jlec 1.1 # @DESCRIPTION:
129     # See if the fortran supports OpenMP.
130     _fortran-has-openmp() {
131     local flag
132     local filebase=${T}/test-fc-openmp
133     local fcode=${filebase}.f
134     local ret
135     local _fc=$(tc-getFC)
136    
137     cat <<- EOF > "${fcode}"
138     call omp_get_num_threads
139     end
140     EOF
141    
142     for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
143 jlec 1.18 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" \
144     &>> "${T}"/_fortran_compile_test.log
145 jlec 1.1 ret=$?
146     (( ${ret} )) || break
147     done
148    
149     rm -f "${fcode}.x"
150     return ${ret}
151     }
152    
153 jlec 1.16 # @FUNCTION: _fortran_die_msg
154 jlec 1.1 # @INTERNAL
155 vapier 1.5 # @DESCRIPTION:
156     # Detailed description how to handle fortran support
157 jlec 1.16 _fortran_die_msg() {
158 jlec 1.1 echo
159     eerror "Please install currently selected gcc version with USE=fortran."
160     eerror "If you intend to use a different compiler then gfortran, please"
161     eerror "set FC variable accordingly and take care that the neccessary"
162     eerror "fortran dialects are support."
163     echo
164     die "Currently no working fortran compiler is available"
165     }
166    
167 jlec 1.12 # @FUNCTION: _fortran_test_function
168     # @INTERNAL
169     # @DESCRIPTION:
170 jlec 1.18 # Internal testfunction for working fortran compiler.
171     # It is called in fortran-2_pkg_setup
172 jlec 1.12 _fortran_test_function() {
173 jlec 1.1 local dialect
174    
175     : ${F77:=$(tc-getFC)}
176    
177     : ${FORTRAN_STANDARD:=77}
178     for dialect in ${FORTRAN_STANDARD}; do
179     case ${dialect} in
180 jlec 1.18 77) _fortran_compile_test $(tc-getF77) || \
181     _fortran_die_msg ;;
182     90|95) _fortran_compile_test $(tc-getFC) 90 || \
183     _fortran_die_msg ;;
184     2003) _fortran_compile_test $(tc-getFC) 03 || \
185     _fortran_die_msg ;;
186 jlec 1.1 2008) die "Future" ;;
187     *) die "${dialect} is not a Fortran dialect." ;;
188     esac
189     done
190    
191 jlec 1.12 tc-export F77 FC
192     einfo "Using following Fortran compiler:"
193     einfo " F77: ${F77}"
194 jlec 1.14 einfo " FC: ${FC}"
195 jlec 1.12
196 jlec 1.1 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
197 jlec 1.12 if _fortran-has-openmp; then
198     einfo "${FC} has OPENMP support"
199     else
200 jlec 1.18 die "Please install current gcc with USE=openmp or " \
201     "set the FC variable to a compiler that supports OpenMP"
202 jlec 1.12 fi
203 jlec 1.1 fi
204     }
205    
206 jlec 1.16 # @FUNCTION: fortran-2_pkg_setup
207     # @DESCRIPTION:
208 jlec 1.18 # Setup functionallity,
209     # checks for a valid fortran compiler and optionally for its openmp support.
210 jlec 1.16 fortran-2_pkg_setup() {
211     for _f_use in ${FORTRAN_NEEDED}; do
212     case ${_f_use} in
213     always)
214     _fortran_test_function && break
215     ;;
216     no)
217     einfo "Forcing fortran support off"
218     break
219     ;;
220     *)
221     if use ${_f_use}; then
222     _fortran_test_function && break
223     else
224     unset FC
225     unset F77
226     fi
227     ;;
228     esac
229     done
230     }
231    
232 jlec 1.1 case ${EAPI:-0} in
233 axs 1.6 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
234 jlec 1.1 *) die "EAPI=${EAPI} is not supported" ;;
235     esac

  ViewVC Help
Powered by ViewVC 1.1.20