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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Tue Jun 21 14:11:31 2011 UTC (3 years, 3 months ago) by jlec
Branch: MAIN
Changes since 1.3: +3 -2 lines
Add note on dependency of virtual/fortran to fortran-2.eclass

1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/fortran-2.eclass,v 1.3 2011/06/21 14:05:30 jlec Exp $
4
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 and
15 # adding virtual/fortran to your dependencies.
16 # 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 # @DESCRIPTION: writes fortran test code
40 # @INTERNAL
41 _write_testsuite() {
42 local filebase=${T}/test-fortran
43
44 # f77 code
45 cat <<- EOF > "${filebase}.f"
46 end
47 EOF
48
49 # f90/95 code
50 cat <<- EOF > "${filebase}.f90"
51 end
52 EOF
53
54 # f2003 code
55 cat <<- EOF > "${filebase}.f03"
56 procedure(), pointer :: p
57 end
58 EOF
59 }
60
61 # @FUNCTION: _compile_test
62 # @DESCRIPTION:
63 # Takes fortran compiler as first argument and dialect as second.
64 # Checks whether the passed fortran compiler speaks the fortran dialect
65 # @INTERNAL
66 _compile_test() {
67 local filebase=${T}/test-fortran
68 local fcomp=${1}
69 local fdia=${2}
70 local fcode=${filebase}.f${fdia}
71 local ret
72
73 [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
74
75 [[ -f ${fcode} ]] || _write_testsuite
76
77 ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
78 ret=$?
79
80 rm -f "${fcode}.x"
81 return ${ret}
82 }
83
84 # @FUNCTION: _fortran-has-openmp
85 # @DESCRIPTION:
86 # See if the fortran supports OpenMP.
87 # @INTERNAL
88 _fortran-has-openmp() {
89 local flag
90 local filebase=${T}/test-fc-openmp
91 local fcode=${filebase}.f
92 local ret
93 local _fc=$(tc-getFC)
94
95 cat <<- EOF > "${fcode}"
96 call omp_get_num_threads
97 end
98 EOF
99
100 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
101 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
102 ret=$?
103 (( ${ret} )) || break
104 done
105
106 rm -f "${fcode}.x"
107 return ${ret}
108 }
109
110 # @FUNCTION: _die_msg
111 # @DESCRIPTION: Detailed description how to handle fortran support
112 # @INTERNAL
113 _die_msg() {
114 echo
115 eerror "Please install currently selected gcc version with USE=fortran."
116 eerror "If you intend to use a different compiler then gfortran, please"
117 eerror "set FC variable accordingly and take care that the neccessary"
118 eerror "fortran dialects are support."
119 echo
120 die "Currently no working fortran compiler is available"
121 }
122
123 # @FUNCTION: fortran-2_pkg_setup
124 # @DESCRIPTION:
125 # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
126 fortran-2_pkg_setup() {
127 local dialect
128
129 : ${F77:=$(tc-getFC)}
130
131 : ${FORTRAN_STANDARD:=77}
132 for dialect in ${FORTRAN_STANDARD}; do
133 case ${dialect} in
134 77) _compile_test $(tc-getF77) || _die_msg ;;
135 90|95) _compile_test $(tc-getFC) 90 || _die_msg ;;
136 2003) _compile_test $(tc-getFC) 03 || _die_msg ;;
137 2008) die "Future" ;;
138 *) die "${dialect} is not a Fortran dialect." ;;
139 esac
140 done
141
142 if [[ ${FORTRAN_NEED_OPENMP} == 1 ]]; then
143 _fortran-has-openmp || \
144 die "Please install current gcc with USE=openmp or set the FC variable to a compiler that supports OpenMP"
145 fi
146 tc-export F77 FC
147 }
148
149 case ${EAPI:-0} in
150 0|1|2|3|4) EXPORT_FUNCTIONS pkg_setup ;;
151 *) die "EAPI=${EAPI} is not supported" ;;
152 esac

  ViewVC Help
Powered by ViewVC 1.1.20