tech-pkg archive

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

Re: possible gfortran.mk changes



"Dr. Thomas Orgis" <thomas.orgis%uni-hamburg.de@localhost> writes:

> Am Tue, 31 Oct 2023 09:54:46 -0400
> schrieb Greg Troxel <gdt%lexort.com@localhost>:
>
>>   - Change the logic that says "only if gcc" to not say that.  Clearly
>>     we don't mean it.
>
> The comment above that rather clearly formulates that it is meant. When
> using clang, one probably wants to use flang (or one of the differing
> flangs that exist) instead of gfortran. Similar for OpenMP. You can
> have varying combinations. Or maybe you don't

I read more code.  I can find absolutely no support for flang in pkgsrc.
There is no flang.mk.  clang.mk sets PKGSRC_FORTRAN to gfortran.  So
while the "if clang use flang" makes sense, it is currently "it would be
nice if someone implemented it".  I don't think what I'm changing makes
that harder.

So the comment about "only if gcc" is off base.  The real question is
thus:

  if the base compiler isn't gcc, then what version of gfortran should
  we use?

I would say that the same "version V is broken on platform P" logic
applies; if gcc/gfortran V is broken if the base is cc, then it's almost
certainly still broken if the base is clang.   So if the logic has said
"this is the version to use", we should try it, at least until there is
contrary evidence.

> Before touching that logic, it would be good to have someone around who
> uses a clang-based toolchain and wants Fortran stuff (math/blas, for
> example).

I don't think it's ok to have to wait for theoretical people; the normal
path is to propose on tech-pkg and so far no such people have commented.

Your point about testing on macOS is of course valid.  I have tested and
fixed my patch on macOS 10.13, and just kicked off a build of blas.  It
pulls in gcc12, which is what would have happened before, so I think it
does no harm.

Testing revealed that the old code set POSSIBLE_GFORTRAN_VERSION to
something like "clang-4" if the base compiler is clang.

If with this patch, blas builds on macOS, on NetBSD 9/armv7hf-el and
NetBSD 10/amd64, I will commit it (absent someone explaining why it's
wrong, of course).



Index: gfortran.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/gfortran.mk,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 gfortran.mk
--- gfortran.mk	4 Nov 2023 12:50:06 -0000	1.26
+++ gfortran.mk	4 Nov 2023 13:20:47 -0000
@@ -33,20 +33,30 @@ COMPILER_GFORTRAN_MK=	defined
 
 .include "../../mk/bsd.prefs.mk"
 
+# This file is gfortran.mk, which is defined to find, depend on, and
+# set up for a gfortran version.  Using gfortran is thus appropriate
+# even if the base compiler is clang; if flang usage is desired then
+# clang.mk or the user should set PKGSRC_FORTRAN to flang (and
+# implement as necessary).
+
 # If the pkgsrc base compiler is GCC, define POSSIBLE_GORTRAN_VERSION
-# (meaning a candidate we would like) to match.  If that version is
-# known to be problematic on a platform, pick a better one.
-# \todo If the base compiler is clang, we probably should use flang
-# rather than gfortran, but this is gfortran.mk.
+# (meaning a candidate we would like) to match.
+.if !empty(PKGSRC_COMPILER:Mgcc)
 POSSIBLE_GFORTRAN_VERSION?=	${CC_VERSION:S/gcc-//:C/.[0-9].[0-9]$//}
+.endif
+
+# On a variety of platforms various versions of gfortran are
+# problematic.
 
+# Choose gcc12 for Darwin/aarch64.  \todo Explain why.
+# gcc7 does not build on Darwin 12.6.x, so match aarch64.
 .if ${MACHINE_PLATFORM:MDarwin-*-*}
-# \todo For parallel structure this should set POSSIBLE_GFORTRAN_VERSION instead.
-GFORTRAN_VERSION?=	12
+POSSIBLE_GFORTRAN_VERSION=	12
 .endif
 
 # pkgsrc gcc9 is missing NetBSD patches for aarch64, so if 9 is
-# selected (historical current only?), advance to 10.
+# selected (historical current, or elevated gcc for this package on
+# NetBSD 9 or older), advance to 10.
 .if !empty(POSSIBLE_GFORTRAN_VERSION:M9) && \
     !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64*)
 POSSIBLE_GFORTRAN_VERSION=	10
@@ -58,10 +68,9 @@ POSSIBLE_GFORTRAN_VERSION=	10
 POSSIBLE_GFORTRAN_VERSION=	10
 .endif
 
-# If we are using gcc, and the POSSIBLE version exists in pkgsrc, use it.
+# If the POSSIBLE version exists in pkgsrc, use it.
 # Otherwise, pick gcc 10 as a mainstream default.
-.if !empty(PKGSRC_COMPILER:Mgcc) && \
-    exists(${PKGSRCDIR}/lang/gcc${POSSIBLE_GFORTRAN_VERSION}/buildlink3.mk)
+.if exists(${PKGSRCDIR}/lang/gcc${POSSIBLE_GFORTRAN_VERSION}/buildlink3.mk)
 GFORTRAN_VERSION?=		${POSSIBLE_GFORTRAN_VERSION}
 .else
 GFORTRAN_VERSION?=		10



Home | Main Index | Thread Index | Old Index