FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Development

 
 
LinkBack Thread Tools
 
Old 06-13-2011, 09:06 AM
justin
 
Default Please review fortran-2.eclass

Hi all,

please review and comment the attached eclass.

Purpose of this eclass is the correct setting of a working fortran
compiler. There are numerous bugs which suffer from one or the other
defect here. Anybody who touch a fortran package knows what I am talking
about.
Currently we support two fortran compilers in the tree, soonish there
will be three. But we also like to like to allowed any out-of-tree
compiler. So depending on gcc[fortran] or virtual/fortran doesn't
fullfill the needs for one or the other reason, which I will not
elaborate again.

Our solution:
1. Depend on virtual/fortran. This will force the ordinary user to use
gfortran through gcc[fortran]. Or the intel compiler has to be selected
via FC=ifort. With this also any other solution can be selected.

2. Test whether FC is a working fortran compiler. Why? gcc:4.5[fortran]
and gcc:4.6[-fortran] can be emerged and gcc-4.6 selected. Thereby
virtual/fortran dependdencies are fullfiled but no working compiler is
there. Same happens in many other constellations.

3. Test for openmp support. For a mixture of the above reasons, it is
impossible to depend on openmp capabilities if user do change anything
from default.

4. Get_fcomp is needed for some packages which do not work with the full
name, e.g. seperate makefiles for intel and gnu compiler.

5. Once FC is working, set all other variable possibly defining fortran
compilers of any flavour to FC.

6. It is still possible without any change to ebuilds to integrate the
test functions in the toolchain-funcs eclass later, if we decide this is
a better way to handle those functions.

Thanks for attention, justin
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# Author Justin Lecher <jlec@gentoo.org>
# Test functions provided by Sebastien Fabbro and Kacper Kowalik

# @ECLASS: fortran-2.eclass
# @MAINTAINER:
# jlec@gentoo.org
# sci@gentoo.org
# @BLURB: Packages, which need a fortran compiler should inherit this eclass.
# @DESCRIPTION:
# If you need a fortran compiler, inherit this eclass. This eclass tests for
# working fortran compilers. Optional, it checks for openmp capability of the
# current fortran compiler through FC_NEED_OPENMP=1.
# Only phase function exported is pkg_setup.

# @ECLASS-VARIABLE: FC_NEED_OPENMP
# @DESCRIPTION:
# Set FC_NEED_OPENMP=1 in order to test FC for openmp capabilities
#
# Default is 0

inherit toolchain-funcs

DEPEND="virtual/fortran"
RDEPEND="${DEPEND}"

# internal function
#
# FUNCTION: _have-valid-fortran
# DESCRIPTION:
# Check whether FC returns a working fortran compiler
_have-valid-fortran() {
local base=${T}/test-tc-fortran
cat <<- EOF > "${base}.f"
end
EOF
$(tc-getFC "$@") "${base}.f" -o "${base}" >&/dev/null
local ret=$?
rm -f "${base}"*
return ${ret}
}

# internal function
#
# FUNCTION: _fortran-has-openmp
# DESCRIPTION:
# See if the fortran supports OpenMP.
_fortran-has-openmp() {
local flag
case $(tc-getFC) in
*gfortran*|pathf*)
flag=-fopenmp ;;
ifort)
flag=-openmp ;;
mpi*)
local _fcomp=$($(tc-getFC) -show | awk '{print $1}')
FC=${_fcomp} _fortran-has-openmp
return $? ;;
*)
return 0 ;;
esac
local base=${T}/test-fc-openmp
# leave extra leading space to make sure it works on fortran 77 as well
cat <<- EOF > "${base}.f"
call omp_get_num_threads
end
EOF
$(tc-getFC "$@") ${flag} "${base}.f" -o "${base}" >&/dev/null
local ret=$?
rm -f "${base}"*
return ${ret}
}

# @FUNCTION: get_fcomp
# @DESCRIPTION:
# Returns the canonical name or the native compiler of the current fortran compiler
#
# e.g.
#
# x86_64-linux-gnu-gfortran -> gfortran
get_fcomp() {
case $(tc-getFC) in
*gfortran* )
echo "gfortran" ;;
ifort )
echo "ifc" ;;
pathf*)
echo "pathcc" ;;
mpi*)
local _fcomp=$($(tc-getFC) -show | awk '{print $1}')
echo $(FC=${_fcomp} get_fcomp) ;;
* )
echo $(tc-getFC) ;;
esac
}

# @FUNCTION: fortran-2_pkg_setup
# @DESCRIPTION:
# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
fortran-2_pkg_setup() {
_have-valid-fortran ||
die "Please emerge the current gcc with USE=fortran or export FC defining a working fortran compiler"
export FC=$(tc-getFC)
export F77=$(tc-getFC)
export F90=$(tc-getFC)
export F95=$(tc-getFC)
if [[ ${FC_NEED_OPENMP} == 1 ]]; then
_fortran-has-openmp ||
die "Please emerge current gcc with USE=openmp or export FC with compiler that supports OpenMP"
fi
}

EXPORT_FUNCTIONS pkg_setup
 
Old 06-13-2011, 09:19 AM
"Paweł Hajdan, Jr."
 
Default Please review fortran-2.eclass

On 6/13/11 11:06 AM, justin wrote:
> # @FUNCTION: fortran-2_pkg_setup
> # @DESCRIPTION:
> # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
> fortran-2_pkg_setup() {
> _have-valid-fortran ||
> die "Please emerge the current gcc with USE=fortran or export FC defining a working fortran compiler"
> export FC=$(tc-getFC)
> export F77=$(tc-getFC)
> export F90=$(tc-getFC)
> export F95=$(tc-getFC)
> if [[ ${FC_NEED_OPENMP} == 1 ]]; then
> _fortran-has-openmp ||
> die "Please emerge current gcc with USE=openmp or export FC with compiler that supports OpenMP"
> fi
> }
>
> EXPORT_FUNCTIONS pkg_setup

I wonder if it's possible to take advantage of EAPI4's pkg_pretend, and
fall back to pkg_setup for older EAPIs. pkg_pretend makes it possible to
fix the setup before running emerge, instead of things breaking in the
middle.

It's just a suggestion.
 
Old 06-13-2011, 09:30 AM
justin
 
Default Please review fortran-2.eclass

On 6/13/11 11:19 AM, "Paweł Hajdan, Jr." wrote:
> On 6/13/11 11:06 AM, justin wrote:
>> # @FUNCTION: fortran-2_pkg_setup
>> # @DESCRIPTION:
>> # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
>> fortran-2_pkg_setup() {
>> _have-valid-fortran ||
>> die "Please emerge the current gcc with USE=fortran or export FC defining a working fortran compiler"
>> export FC=$(tc-getFC)
>> export F77=$(tc-getFC)
>> export F90=$(tc-getFC)
>> export F95=$(tc-getFC)
>> if [[ ${FC_NEED_OPENMP} == 1 ]]; then
>> _fortran-has-openmp ||
>> die "Please emerge current gcc with USE=openmp or export FC with compiler that supports OpenMP"
>> fi
>> }
>>
>> EXPORT_FUNCTIONS pkg_setup
>
> I wonder if it's possible to take advantage of EAPI4's pkg_pretend, and
> fall back to pkg_setup for older EAPIs. pkg_pretend makes it possible to
> fix the setup before running emerge, instead of things breaking in the
> middle.
>
> It's just a suggestion.
>

You are right. Thought about it, but refused it, because I din't want to
force EAPI=4. But right I can just use a fall back for EAPI<4. Thanks
for the suggestion.
 
Old 06-13-2011, 10:30 AM
justin
 
Default Please review fortran-2.eclass

On 6/13/11 11:19 AM, "Paweł Hajdan, Jr." wrote:
> On 6/13/11 11:06 AM, justin wrote:
>> # @FUNCTION: fortran-2_pkg_setup
>> # @DESCRIPTION:
>> # Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
>> fortran-2_pkg_setup() {
>> _have-valid-fortran ||
>> die "Please emerge the current gcc with USE=fortran or export FC defining a working fortran compiler"
>> export FC=$(tc-getFC)
>> export F77=$(tc-getFC)
>> export F90=$(tc-getFC)
>> export F95=$(tc-getFC)
>> if [[ ${FC_NEED_OPENMP} == 1 ]]; then
>> _fortran-has-openmp ||
>> die "Please emerge current gcc with USE=openmp or export FC with compiler that supports OpenMP"
>> fi
>> }
>>
>> EXPORT_FUNCTIONS pkg_setup
>
> I wonder if it's possible to take advantage of EAPI4's pkg_pretend, and
> fall back to pkg_setup for older EAPIs. pkg_pretend makes it possible to
> fix the setup before running emerge, instead of things breaking in the
> middle.
>
> It's just a suggestion.
>

Now using the new pkg_pretend for EAPI=4
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# Author Justin Lecher <jlec@gentoo.org>
# Test functions provided by Sebastien Fabbro and Kacper Kowalik

# @ECLASS: fortran-2.eclass
# @MAINTAINER:
# jlec@gentoo.org
# sci@gentoo.org
# @BLURB: Packages, which need a fortran compiler should inherit this eclass.
# @DESCRIPTION:
# If you need a fortran compiler, inherit this eclass. This eclass tests for
# working fortran compilers. Optional, it checks for openmp capability of the
# current fortran compiler through FC_NEED_OPENMP=1.
# Only phase function exported is pkg_setup.

# @ECLASS-VARIABLE: FC_NEED_OPENMP
# @DESCRIPTION:
# Set FC_NEED_OPENMP=1 in order to test FC for openmp capabilities
#
# Default is 0

inherit toolchain-funcs

DEPEND="virtual/fortran"
RDEPEND="${DEPEND}"

# internal function
#
# FUNCTION: _have-valid-fortran
# DESCRIPTION:
# Check whether FC returns a working fortran compiler
_have-valid-fortran() {
local base=${T}/test-tc-fortran
cat <<- EOF > "${base}.f"
end
EOF
$(tc-getFC "$@") "${base}.f" -o "${base}" >&/dev/null
local ret=$?
rm -f "${base}"*
return ${ret}
}

# internal function
#
# FUNCTION: _fortran-has-openmp
# DESCRIPTION:
# See if the fortran supports OpenMP.
_fortran-has-openmp() {
local flag
case $(tc-getFC) in
*gfortran*|pathf*)
flag=-fopenmp ;;
ifort)
flag=-openmp ;;
mpi*)
local _fcomp=$($(tc-getFC) -show | awk '{print $1}')
FC=${_fcomp} _fortran-has-openmp
return $? ;;
*)
return 0 ;;
esac
local base=${T}/test-fc-openmp
# leave extra leading space to make sure it works on fortran 77 as well
cat <<- EOF > "${base}.f"
call omp_get_num_threads
end
EOF
$(tc-getFC "$@") ${flag} "${base}.f" -o "${base}" >&/dev/null
local ret=$?
rm -f "${base}"*
return ${ret}
}

# @FUNCTION: get_fcomp
# @DESCRIPTION:
# Returns the canonical name or the native compiler of the current fortran compiler
#
# e.g.
#
# x86_64-linux-gnu-gfortran -> gfortran
get_fcomp() {
case $(tc-getFC) in
*gfortran* )
echo "gfortran" ;;
ifort )
echo "ifc" ;;
pathf*)
echo "pathcc" ;;
mpi*)
local _fcomp=$($(tc-getFC) -show | awk '{print $1}')
echo $(FC=${_fcomp} get_fcomp) ;;
* )
echo $(tc-getFC) ;;
esac
}

# @FUNCTION: fortran-2_pkg_pretend
# @DESCRIPTION:
# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support.
fortran-2_pkg_pretend() {
_have-valid-fortran ||
die "Please emerge the current gcc with USE=fortran or export FC defining a working fortran compiler"
export FC=$(tc-getFC)
export F77=$(tc-getFC)
export F90=$(tc-getFC)
export F95=$(tc-getFC)
if [[ ${FC_NEED_OPENMP} == 1 ]]; then
_fortran-has-openmp ||
die "Please emerge current gcc with USE=openmp or export FC with compiler that supports OpenMP"
fi
}


# @FUNCTION: fortran-2_pkg_setup
# @DESCRIPTION:
# Setup functionallity, checks for a valid fortran compiler and optionally for its openmp support, used in EAPI < 4.
fortran-2_pkg_setup() {
has ${EAPI:-0} 0 1 2 3 && fortran-2_pkg_pretend
}

case "${EAPI:-0}" in
0|1|2|3)
EXPORT_FUNCTIONS pkg_setup;;
4)
EXPORT_FUNCTIONS pkg_pretend;;
*) die "EAPI=${EAPI} is not supported" ;;
esac
 

Thread Tools




All times are GMT. The time now is 03:15 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org