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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Jun 21 14:05:30 2011 UTC (3 years, 2 months ago) by jlec
Branch: MAIN
Changes since 1.2: +1 -4 lines
Remove dependency on virtual/fortran from fortran-2.eclass

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

  ViewVC Help
Powered by ViewVC 1.1.20