Re: git: 4191c71fbd22 - main - Mk/Uses/fortran.mk: Make gfortran respect USE_GCC

From: Tijl Coosemans <tijl_at_FreeBSD.org>
Date: Fri, 18 Nov 2022 19:41:10 UTC
On Wed, 16 Nov 2022 21:39:50 GMT Lorenzo Salvadore
<salvadore@FreeBSD.org> wrote:
> The branch main has been updated by salvadore:
> 
> URL: https://cgit.FreeBSD.org/ports/commit/?id=4191c71fbd229e5a96382bc6fa271a1ce5668b0f
> 
> commit 4191c71fbd229e5a96382bc6fa271a1ce5668b0f
> Author:     Lorenzo Salvadore <salvadore@FreeBSD.org>
> AuthorDate: 2022-11-16 14:43:40 +0000
> Commit:     Lorenzo Salvadore <salvadore@FreeBSD.org>
> CommitDate: 2022-11-16 21:38:54 +0000
> 
>     Mk/Uses/fortran.mk: Make gfortran respect USE_GCC
>     
>     Allow choosing a specific version of gfortran through USE_GCC variable.
>     
>     PR:             266196
>     Approved by:    thierry (fortran)
>     Co-authored by: thierry
> ---
>  Mk/Uses/fortran.mk | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Mk/Uses/fortran.mk b/Mk/Uses/fortran.mk
> index 09ebd62b1a0f..d335fad4dc8e 100644
> --- a/Mk/Uses/fortran.mk
> +++ b/Mk/Uses/fortran.mk
> @@ -14,7 +14,11 @@ fortran_ARGS=	${FORTRAN_DEFAULT}
>  .  endif
>  
>  .  if ${fortran_ARGS} == gfortran
> +.    if empty(USE_GCC)
>  _GCC_VER=	${GCC_DEFAULT:S/.//}
> +.    else
> +_GCC_VER=	${_USE_GCC}
> +.    endif
>  BUILD_DEPENDS+=	gfortran${_GCC_VER}:lang/gcc${_GCC_VER}
>  RUN_DEPENDS+=	gfortran${_GCC_VER}:lang/gcc${_GCC_VER}
>  F77=		gfortran${_GCC_VER}

When I wrote this file I didn't include this because users will end up
with multiple versions of GCC installed, each with its own set of runtime
libraries.  So they'll have programs/libraries built against different
runtime libraries and those don't always work together.  For instance,
science/octopus is now built with GCC 11 but its dependencies like
lapack are built with GCC 12.  These dependencies may require features
from GCC 12 runtime libraries while science/octopus programs probably
(I haven't checked) load GCC 11 runtime libraries when you run them.
Even if this happens to work now it may not work when the default
switches to 13.  I believe it's better for ports like science/octopus to
have something like this in their Makefile:

.if ${GCC_DEFAULT} != 11
IGNORE= This port only works with gcc 11.  You can add DEFAULT_VERSIONS+=gcc=11 to /etc/make.conf
.endif

I noticed there's a new version of Octopus so maybe an update would fix
this particular case.