tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

fortran in pkgsrc



I've been trying to work out how to persuade pkgsrc to use a different 
fortran than f2c-f77 on current NetBSD's -- specifically g95.  
Increasingly there are packages (or potential packages) that wont build 
with f2c, or prefer to use g95 if they detect it or produce significantly 
better code with g95 (my users report 5-10% improvement in their R code).

My current approach is to set it up as a "pseudo compiler" like f2c 
(compiler/g95.mk attached) and then in mk.conf set:

        PKGSRC_COMPILER= g95 gcc
        FC= g95

However because "gcc" automatically pulls in f2c on current I currently 
have the following changes to the compiler framework:

Index: compiler.mk
===================================================================
RCS file: /src/cvs/netbsd/pkgsrc/mk/compiler.mk,v
retrieving revision 1.66
diff -u -r1.66 compiler.mk
--- compiler.mk 13 Feb 2008 09:00:52 -0000      1.66
+++ compiler.mk 5 Jun 2008 12:23:01 -0000
@@ -94,7 +94,7 @@
 .endif
 
 _COMPILERS=            ccc gcc icc ido mipspro mipspro-ucode sunpro xlc hp pcc
-_PSEUDO_COMPILERS=     ccache distcc f2c
+_PSEUDO_COMPILERS=     ccache distcc f2c g95
 
 .if defined(NOT_FOR_COMPILER) && !empty(NOT_FOR_COMPILER)
 .  for _compiler_ in ${_COMPILERS}
@@ -131,7 +131,7 @@
 _PKGSRC_COMPILER:=     ${_compiler_} ${_PKGSRC_COMPILER}
 .  endif
 .endfor
-_PKGSRC_COMPILER:=     ${_COMPILER} ${_PKGSRC_COMPILER}
+_PKGSRC_COMPILER:=     ${_PKGSRC_COMPILER} ${_COMPILER}
 
 _COMPILER_STRIP_VARS=  # empty
 
Index: compiler/gcc.mk
===================================================================
RCS file: /src/cvs/netbsd/pkgsrc/mk/compiler/gcc.mk,v
retrieving revision 1.93
diff -u -r1.93 gcc.mk
--- compiler/gcc.mk     7 Feb 2008 20:59:05 -0000       1.93
+++ compiler/gcc.mk     6 Jun 2008 03:50:35 -0000
@@ -466,6 +466,9 @@
 .    endif
 .  endfor
 .endif
+.if defined(_USE_G95) && !empty(_USE_G95:M[yY][eE][sS])
+_GCC_USE_F2C=  no
+.endif
 .if !empty(_GCC_USE_F2C:M[yY][eE][sS])
 .  include "../../mk/compiler/f2c.mk"
 .endif

I don't believe reversing the order in _PKGSRC_COMPILER is correct (think 
it will break ccache and distcc and probably get the wrong fortran in 
older NetBSD's where gcc actually sets one itself) but I did it initially 
to try and get gcc.mk to notice that g95.mk had set FCPATH and when that 
didn't work to pick up the _USE_G95.

Another problem with this approach is that packages that set 
ONLY_FOR_COMPILER=gcc, such as mplayer, fail to build.

Suggestions?

One possibility would be to replace in gcc.mk all the _GCC_USE_F2C with 
_GCC_NEEDS_A_FORTRAN and the
 .  include "../../mk/compiler/f2c.mk"
with
 .  include "../../mk/compiler/${PKGSRC_FORTRAN}.mk"

and default PKGSRC_FORTRAN to f2c and allow users to set it to g95 if 
desired.

cheers
mark

# $NetBSD: f2c.mk,v 1.11 2008/05/24 07:27:11 obache Exp $
#
# Copyright (c) 2005 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by the NetBSD
#        Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

.if !defined(COMPILER_G95_MK)
COMPILER_G95_MK=        defined

.include "../../mk/bsd.prefs.mk"

.if !empty(PKGPATH:Mlang/g95) || !empty(PKGPATH:Mdevel/patch) || \
    !empty(PKGPATH:Mdevel/libtool-base)
IGNORE_G95=     yes
MAKEFLAGS+=     IGNORE_G95=yes
.endif

.if defined(IGNORE_G95)
_USE_G95=       NO
.endif

# LANGUAGES.<compiler> is the list of supported languages by the compiler.
# _LANGUAGES.<compiler> is ${LANGUAGES.<compiler>} restricted to the ones
# requested by the package in USE_LANGUAGES.
#
LANGUAGES.g95=  fortran
_LANGUAGES.g95= # empty
.for _lang_ in ${USE_LANGUAGES}
_LANGUAGES.g95+=        ${LANGUAGES.g95:M${_lang_}}
.endfor
.if empty(_LANGUAGES.g95)
_USE_G95=       NO
.endif

.if !defined(_USE_G95)
_USE_G95=       YES
.endif

.if !empty(_USE_G95:M[yY][eE][sS])
EVAL_PREFIX+=           _G95BASE=g95
_G95BASE_DEFAULT=       ${LOCALBASE}

_G95_DIR=       ${WRKDIR}/.g95
_G95_VARS=      # empty
.  if !empty(_LANGUAGES.g95:Mfortran)
PKG_FC?=        ${FC}
_G95_VARS+=     FC
_G95_FC:=       ${_G95_DIR}/bin/${PKG_FC:T}
_ALIASES.FC+=   f77 g77 g95
FCPATH=         ${_G95BASE}/bin/g95
PKG_FC:=        ${_G95_FC}
#
# The f2c-f77 shell script invokes the C compiler, so ensure that it finds
# the cc wrapper for proper transformations.
#
# XXX This shouldn't really be leaking into here, as it breaks encapsulation.
# XXX It should really be handled within the wrapper framework.
#
# _WRAP_ENV.FC= PATH="${WRAPPER_BINDIR}:${_WRAP_PATH}"; export PATH
.  endif

# Prepend the path the to the compiler to the PATH
.  if !empty(_LANGUAGES.g95)
PREPEND_PATH+=  ${_G95_DIR}/bin
.  endif

# Add the dependency on f2c.
.  include "../../lang/g95/buildlink3.mk"

.  if defined(G95_DIR) && !empty(G95_DIR)
PKGSRC_MAKE_ENV+=       G95_DIR=${G95_DIR:Q}
.  endif

# Create symlinks for the compiler into ${WRKDIR}.
.  for _var_ in ${_G95_VARS}
.    if !target(${_G95_${_var_}})
override-tools: ${_G95_${_var_}}
${_G95_${_var_}}:
        ${RUN}${MKDIR} ${.TARGET:H}
        ${RUN}                                  \
        ${LN} -fs ${_G95BASE}/bin/g95 ${.TARGET}
.      for _alias_ in ${_ALIASES.${_var_}:S/^/${.TARGET:H}\//}
        ${RUN}                                  \
        if [ ! -x "${_alias_}" ]; then                                  \
                ${LN} -fs ${_G95BASE}/bin/g95 ${_alias_};               \
        fi
.      endfor
.    endif
.  endfor
.endif  # _USE_G95 == "yes"

.endif  # COMPILER_G95_MK


Home | Main Index | Thread Index | Old Index