From fd22b66116f7b63ac4c702de7ba25591bc5993a9 Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Thu, 16 Feb 2023 07:55:02 -0500 Subject: [PATCH] Autoconf configuration of Python The introduction of makedep means that Python is now a dependency of the MOM6 compilation. On some systems, we cannot assume that `python` is the name of the interpreter, and strictly should not even assume that it exists. This is notably an issue on the recent MacOS M1 systems, which use `python3` as its interpreter, and do not provide one named `python`. This patch adds macros to the MOM6 and FMS autoconf builds to detect if Python is on the system, and makes a few attempts to determine the name of the interpreter (python, python3, python2). Perhaps more can be done here, but this is probably sufficient in nearly all cases. --- ac/Makefile.in | 3 ++- ac/configure.ac | 7 +++++++ ac/deps/Makefile.fms.in | 3 ++- ac/deps/configure.fms.ac | 9 ++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ac/Makefile.in b/ac/Makefile.in index 930816bc8c..43262027e6 100644 --- a/ac/Makefile.in +++ b/ac/Makefile.in @@ -6,6 +6,7 @@ FC = @FC@ LD = @FC@ +PYTHON = @PYTHON@ MAKEDEP = @MAKEDEP@ DEFS = @DEFS@ @@ -32,7 +33,7 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su .PHONY: depend depend: Makefile.dep Makefile.dep: $(MAKEDEP) $(call rwildcard,$(SRC_DIRS),*.h *.c *.inc *.F90) - $(MAKEDEP) -o Makefile.dep -e $(SRC_DIRS) + $(PYTHON) $(MAKEDEP) -o Makefile.dep -e $(SRC_DIRS) # Delete any files associated with configuration (including the Makefile). diff --git a/ac/configure.ac b/ac/configure.ac index 049325a891..dead0579a6 100644 --- a/ac/configure.ac +++ b/ac/configure.ac @@ -221,6 +221,13 @@ AC_COMPILE_IFELSE( ) +# Verify that Python is available +AC_PATH_PROGS([PYTHON], [python python3 python2], [ + AC_MSG_ERROR([Could not find python.]) +]) +AC_ARG_VAR([PYTHON], [Python interpreter command]) + + # Verify that makedep is available AC_PATH_PROG([MAKEDEP], [makedep], [${srcdir}/ac/makedep]) AC_SUBST([MAKEDEP]) diff --git a/ac/deps/Makefile.fms.in b/ac/deps/Makefile.fms.in index e2581cf817..caf4abb9c7 100644 --- a/ac/deps/Makefile.fms.in +++ b/ac/deps/Makefile.fms.in @@ -8,6 +8,7 @@ CC = @CC@ FC = @FC@ LD = @FC@ AR = @AR@ +PYTHON = @PYTHON@ MAKEDEP = @MAKEDEP@ DEFS = @DEFS@ @@ -22,4 +23,4 @@ ARFLAGS = @ARFLAGS@ .PHONY: depend depend: Makefile.dep Makefile.dep: - $(MAKEDEP) -o Makefile.dep -e -x libFMS.a @srcdir@ + $(PYTHON) $(MAKEDEP) -o Makefile.dep -e -x libFMS.a @srcdir@ diff --git a/ac/deps/configure.fms.ac b/ac/deps/configure.fms.ac index 4e0c0f1390..a52533970b 100644 --- a/ac/deps/configure.fms.ac +++ b/ac/deps/configure.fms.ac @@ -158,7 +158,14 @@ AX_FC_ALLOW_ARG_MISMATCH FCFLAGS="$FCFLAGS $ALLOW_ARG_MISMATCH_FCFLAGS" -# Verify makedep +# Verify that Python is available +AC_PATH_PROGS([PYTHON], [python python3 python2], [ + AC_MSG_ERROR([Could not find python.]) +]) +AC_ARG_VAR([PYTHON], [Python interpreter command]) + + +# Verify that makedep is available AC_PATH_PROGS([MAKEDEP], [makedep], [], ["${PATH}:${srcdir}/../../.."]) AS_IF([test -n "${MAKEDEP}"], [ AC_SUBST([MAKEDEP])