Skip to content

Makefiles: make FC default to gfortran again - #696

Open
BenjaminDEMAILLE wants to merge 1 commit into
rgcgithub:masterfrom
BenjaminDEMAILLE:makefile-fortran-compiler
Open

BenjaminDEMAILLE wants to merge 1 commit into
rgcgithub:masterfrom
BenjaminDEMAILLE:makefile-fortran-compiler

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor

Follow-up to #694, noted in #695.

Problem

external_libs/quadpack/Makefile and external_libs/mvtnorm/Makefile both do:

FC   ?= gfortran

That assignment never takes effect. GNU make already defines FC as f77 as a built-in variable, and ?= assigns only when the variable is undefined, which a built-in is not. So a build that does not set FC in the environment uses f77 and stops at:

make: f77: No such file or directory
make: *** [mvt.o] Error 1
make: *** [d1mach.o] Error 1

Machines with a f77 in PATH (often a wrapper around gfortran) do not notice; those without it cannot build regenie unless they know to pass FC=gfortran themselves. It also means the -std=legacy in FLAG is being handed to whatever f77 happens to be, rather than to gfortran as intended.

Fix

Use $(origin FC), which distinguishes make's own default from a value the user supplied:

ifeq ($(origin FC),default)
FC   := gfortran
endif

An FC passed on the command line or exported in the environment still wins, so cross-compilation and non-gfortran toolchains are unaffected.

Testing

macOS 26.6 arm64, GCC 15 gfortran:

$ env -u FC make            # before: make: f77: No such file or directory
gfortran -O2 -DNDEBUG -fPIC -std=legacy -c d1mach.f
...
$ ls libquad.a
libquad.a

$ make FC=gfortran-16       # explicit FC still honoured
gfortran-16 -O2 -DNDEBUG -fPIC -std=legacy -c d1mach.f

Same for external_libs/mvtnorm. Found while packaging regenie for Homebrew, where the build environment does not provide f77.

🤖 Generated with Claude Code

`FC ?= gfortran` never takes effect: GNU make already defines FC as `f77`
as a built-in, and `?=` only assigns when the variable is undefined. A build
that does not set FC in the environment therefore stops at:

    make: f77: No such file or directory
    make: *** [mvt.o] Error 1

Use `$(origin FC)` so gfortran is used when make supplied the default, while
an FC given on the command line or in the environment is still respected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant