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

Contents of /eclass/fortran-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Tue Jun 21 08:06:56 2011 UTC (3 years, 3 months ago) by jlec
Branch: MAIN
Changes since 1.1: +2 -2 lines
Added EAPI=0 support to fortran.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.1 2011/06/21 06:44:02 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.
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 DEPEND="virtual/fortran"
38 RDEPEND="${DEPEND}"
39
40 # @FUNCTION: _write_testsuite
41 # @DESCRIPTION: writes fortran test code
42 # @INTERNAL
43 _write_testsuite() {
44 local filebase=${T}/test-fortran
45
46 # f77 code
47 cat <<- EOF > "${filebase}.f"
48 end
49 EOF
50
51 # f90/95 code
52 cat <<- EOF > "${filebase}.f90"
53 end
54 EOF
55
56 # f2003 code
57 cat <<- EOF > "${filebase}.f03"
58 procedure(), pointer :: p
59 end
60 EOF
61 }
62
63 # @FUNCTION: _compile_test
64 # @DESCRIPTION:
65 # Takes fortran compiler as first argument and dialect as second.
66 # Checks whether the passed fortran compiler speaks the fortran dialect
67 # @INTERNAL
68 _compile_test() {
69 local filebase=${T}/test-fortran
70 local fcomp=${1}
71 local fdia=${2}
72 local fcode=${filebase}.f${fdia}
73 local ret
74
75 [[ $# -eq 0 ]] && die "_compile_test() needs at least one argument"
76
77 [[ -f ${fcode} ]] || _write_testsuite
78
79 ${fcomp} "${fcode}" -o "${fcode}.x" >&/dev/null
80 ret=$?
81
82 rm -f "${fcode}.x"
83 return ${ret}
84 }
85
86 # @FUNCTION: _fortran-has-openmp
87 # @DESCRIPTION:
88 # See if the fortran supports OpenMP.
89 # @INTERNAL
90 _fortran-has-openmp() {
91 local flag
92 local filebase=${T}/test-fc-openmp
93 local fcode=${filebase}.f
94 local ret
95 local _fc=$(tc-getFC)
96
97 cat <<- EOF > "${fcode}"
98 call omp_get_num_threads
99 end
100 EOF
101
102 for flag in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
103 ${_fc} ${flag} "${fcode}" -o "${fcode}.x" >&/dev/null
104 ret=$?
105 (( ${ret} )) || break
106 done
107
108 rm -f "${fcode}.x"
109 return ${ret}
110 }
111
112 # @FUNCTION: _die_msg
113 # @DESCRIPTION: Detailed description how to handle fortran support
114 # @INTERNAL
115 _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 }
150
151 case ${EAPI:-0} in
152 0|1|2|3|4) EXPORT_FUNCTIONS pkg_setup ;;
153 *) die "EAPI=${EAPI} is not supported" ;;
154 esac

  ViewVC Help
Powered by ViewVC 1.1.20