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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sun Oct 7 13:15:52 2012 UTC (21 months, 2 weeks ago) by jlec
Branch: MAIN
Changes since 1.8: +2 -4 lines
Revert last change to not  break packages with optional fortran support

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.8 # $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.7 2012/10/07 12:06:54 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.9 # If you need a fortran compiler, then you should be inheriting this eclass and
15     # adding virtual/fortran to your dependencies.
16 jlec 1.1 # The eclass tests for working fortran compilers
17     # and exports the variables FC and F77.
18     # Optionally, it checks for extended capabilities based on
19     # the variable options selected in the ebuild
20     # The only phase function exported is fortran-2_pkg_setup.
21    
22     # @ECLASS-VARIABLE: FORTRAN_NEED_OPENMP
23     # @DESCRIPTION:
24     # Set to "1" in order to automatically have the eclass abort if the fortran
25     # compiler lacks openmp support.
26     : ${FORTRAN_NEED_OPENMP:=0}
27    
28     # @ECLASS-VARIABLE: FORTRAN_STANDARD
29     # @DESCRIPTION:
30     # Set this, if a special dialect needs to be supported.
31     # Generally not needed as default is sufficient.
32     #
33     # Valid settings are any combination of: 77 90 95 2003
34     : ${FORTRAN_STANDARD:=77}
35    
36     inherit toolchain-funcs
37    
38     # @FUNCTION: _write_testsuite
39     # @INTERNAL
40 vapier 1.5 # @DESCRIPTION:
41     # writes fortran test code
42 jlec 1.1 _write_testsuite() {
43     local filebase=${T}/test-fortran
44    
45     # f77 code
46     cat <<- EOF > "${filebase}.f"
47     end
48     EOF
49    
50     # f90/95 code
51     cat <<- EOF > "${filebase}.f90"
52     end
53     EOF
54    
55     # f2003 code
56     cat <<- EOF > "${filebase}.f03"
57     procedure(), pointer :: p
58     end
59     EOF
60     }
61    
62     # @FUNCTION: _compile_test
63 vapier 1.5 # @INTERNAL
64 jlec 1.1 # @DESCRIPTION:
65     # Takes fortran compiler as first argument and dialect as second.
66     # Checks whether the passed fortran compiler speaks the fortran dialect
67     _compile_test() {
68     local filebase=${T}/test-fortran
69     local fcomp=${1}
70     local fdia=${2}
71     local fcode=${filebase}.f${fdia}
72     local ret
73    
74     [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
75    
76     [[ -f ${fcode} ]] || _write_testsuite
77    
78     ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
79     ret=$?
80    
81     rm -f "${fcode}.x"
82     return ${ret}
83     }
84    
85     # @FUNCTION: _fortran-has-openmp
86 vapier 1.5 # @INTERNAL
87 jlec 1.1 # @DESCRIPTION:
88     # See if the fortran supports OpenMP.
89     _fortran-has-openmp() {
90     local flag
91     local filebase=${T}/test-fc-openmp
92     local fcode=${filebase}.f
93     local ret
94     local _fc=$(tc-getFC)
95    
96     cat <<- EOF > "${fcode}"
97     call omp_get_num_threads
98     end
99     EOF
100    
101     for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
102     ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
103     ret=$?
104     (( ${ret} )) || break
105     done
106    
107     rm -f "${fcode}.x"
108     return ${ret}
109     }
110    
111     # @FUNCTION: _die_msg
112     # @INTERNAL
113 vapier 1.5 # @DESCRIPTION:
114     # Detailed description how to handle fortran support
115 jlec 1.1 _die_msg() {
116     echo
117     eerror "Please install currently selected gcc version with USE=fortran."
118     eerror "If you intend to use a different compiler then gfortran, please"
119     eerror "set FC variable accordingly and take care that the neccessary"
120     eerror "fortran dialects are support."
121     echo
122     die "Currently no working fortran compiler is available"
123     }
124    
125     # @FUNCTION: fortran-2_pkg_setup
126     # @DESCRIPTION:
127     # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
128     fortran-2_pkg_setup() {
129     local dialect
130    
131     : ${F77:=$(tc-getFC)}
132    
133     : ${FORTRAN_STANDARD:=77}
134     for dialect in ${FORTRAN_STANDARD}; do
135     case ${dialect} in
136     77) _compile_test $(tc-getF77) || _die_msg ;;
137     90|95) _compile_test $(tc-getFC) 90 || _die_msg ;;
138     2003) _compile_test $(tc-getFC) 03 || _die_msg ;;
139     2008) die "Future" ;;
140     *) die "${dialect} is not a Fortran dialect." ;;
141     esac
142     done
143    
144     if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
145     _fortran-has-openmp || \
146     die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
147     fi
148     tc-export F77 FC
149 jlec 1.7 einfo "Using following Fortran compiler"
150     einfo " F77: ${F77}"
151     einfo " FC: ${FC}"
152 jlec 1.1 }
153    
154     case ${EAPI:-0} in
155 axs 1.6 0|1|2|3|4|5) EXPORT_FUNCTIONS pkg_setup ;;
156 jlec 1.1 *) die "EAPI=${EAPI} is not supported" ;;
157     esac

  ViewVC Help
Powered by ViewVC 1.1.20