diff --git a/.github/workflows/verify-linux.yml b/.github/workflows/verify-linux.yml index 4c2817f4ee..2931c7fdc9 100644 --- a/.github/workflows/verify-linux.yml +++ b/.github/workflows/verify-linux.yml @@ -14,8 +14,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - name: Check white space (non-blocking) run: | @@ -50,13 +48,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with symmetric indexing run: make -C .testing -j build/symmetric/MOM6 @@ -75,13 +74,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with asymmetric indexing run: make -C .testing -j build/asymmetric/MOM6 @@ -100,13 +100,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with bit-reproducible optimization run: make -C .testing -j build/repro/MOM6 @@ -125,13 +126,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 supporting OpenMP run: make -C .testing -j build/openmp/MOM6 @@ -151,12 +153,10 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile target FMS + - name: Compile target depedencies run: | make -C .testing \ DO_REGRESSION_TESTS=1 \ @@ -184,13 +184,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with aggressive optimization run: make -C .testing -j build/opt/MOM6 @@ -217,12 +218,10 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile target FMS + - name: Compile target dependencies run: | make -C .testing \ DO_REGRESSION_TESTS=1 \ @@ -260,13 +259,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with code coverage run: make -C .testing -j build/cov/MOM6 @@ -296,13 +296,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 for the GFDL coupled driver run: make -C .testing -j check_mom6_api_coupled @@ -317,8 +318,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -350,8 +349,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -375,8 +372,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -400,8 +395,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -425,8 +418,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -460,8 +451,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -487,8 +476,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -522,8 +509,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -558,8 +543,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -592,8 +575,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -638,8 +619,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup @@ -670,8 +649,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/ubuntu-setup diff --git a/.github/workflows/verify-macos.yml b/.github/workflows/verify-macos.yml index d058336053..f4f473290d 100644 --- a/.github/workflows/verify-macos.yml +++ b/.github/workflows/verify-macos.yml @@ -16,13 +16,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with symmetric indexing run: make -C .testing -j build/symmetric/MOM6 @@ -41,13 +42,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with asymmetric indexing run: make -C .testing -j build/asymmetric/MOM6 @@ -66,13 +68,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 with bit-reproducible optimization run: make -C .testing -j build/repro/MOM6 @@ -91,13 +94,14 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup/ - - name: Compile FMS - run: make -C .testing -j build/deps/lib/libFMS.a + - name: Compile dependencies + run: | + make -C .testing -j build/deps/lib/libFMS.a + make -C .testing -j build/deps/lib/libgsw.a + make -C .testing -j build/deps/lib/libcvmix.a - name: Compile MOM6 supporting OpenMP run: make -C .testing -j build/openmp/MOM6 @@ -117,12 +121,10 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup/ - - name: Compile target FMS + - name: Compile target dependencies run: | make -C .testing \ DO_REGRESSION_TESTS=1 \ @@ -155,8 +157,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -188,8 +188,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -213,8 +211,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -238,8 +234,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -263,8 +257,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -298,8 +290,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -325,8 +315,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -360,8 +348,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup @@ -396,8 +382,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: ./.github/actions/macos-setup diff --git a/.gitignore b/.gitignore index c57b950fc2..d246027b44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,2 @@ -# Ignore vim and emacs files -*.swp -*~ -html - - # Build output -*.o -*.mod -MOM6 build/ -deps/ -pkg/MARBL - - -# Autoconf output -aclocal.m4 -autom4te.cache/ -config.log -config.status -configure -/Makefile -Makefile.mkmf diff --git a/.testing/Makefile b/.testing/Makefile index 71d5b464f0..0d80e28fde 100644 --- a/.testing/Makefile +++ b/.testing/Makefile @@ -311,7 +311,7 @@ $(BUILD)/opt_target: | $(TARGET_CODEBASE) $(BUILD)/%/Makefile: $(BUILD)/%/Makefile.in $(BUILD)/%/config.status cd $(@D) && ./config.status -$(BUILD)/%/config.status: $(BUILD)/%/configure $(DEPS)/lib/libFMS.a +$(BUILD)/%/config.status: $(BUILD)/%/configure $(DEPS)/lib/libFMS.a $(DEPS)/lib/libgsw.a $(DEPS)/lib/libcvmix.a cd $(@D) && $(MOM_ENV) ./configure -n --srcdir=$(AC_SRCDIR) $(MOM_ACFLAGS) \ || (cat config.log && false) @@ -340,19 +340,18 @@ $(TARGET_CODEBASE): endif -## FMS +## Dependencies # Set up the FMS build environment variables -FMS_ENV = \ +DEPS_ENV = \ PATH="${PATH}:$(realpath ../ac)" \ FCFLAGS="$(FCFLAGS_FMS)" \ REPORT_ERROR_LOGS="$(REPORT_ERROR_LOGS)" -$(DEPS)/lib/libFMS.a: $(DEPS)/Makefile $(DEPS)/Makefile.fms.in $(DEPS)/configure.fms.ac $(DEPS)/m4 - $(FMS_ENV) $(MAKE) -C $(DEPS) lib/libFMS.a +# FMS -$(DEPS)/Makefile: ../ac/deps/Makefile | $(DEPS) - cp ../ac/deps/Makefile $(DEPS)/Makefile +$(DEPS)/lib/libFMS.a: $(DEPS)/Makefile $(DEPS)/Makefile.fms.in $(DEPS)/configure.fms.ac $(DEPS)/m4 + $(DEPS_ENV) $(MAKE) -C $(DEPS) lib/libFMS.a $(DEPS)/Makefile.fms.in: ../ac/deps/Makefile.fms.in | $(DEPS) cp ../ac/deps/Makefile.fms.in $(DEPS)/Makefile.fms.in @@ -360,6 +359,33 @@ $(DEPS)/Makefile.fms.in: ../ac/deps/Makefile.fms.in | $(DEPS) $(DEPS)/configure.fms.ac: ../ac/deps/configure.fms.ac | $(DEPS) cp ../ac/deps/configure.fms.ac $(DEPS)/configure.fms.ac +# GSW + +$(DEPS)/lib/libgsw.a: $(DEPS)/Makefile $(DEPS)/Makefile.gsw.in $(DEPS)/configure.gsw.ac $(DEPS)/m4 + $(DEPS_ENV) $(MAKE) -C $(DEPS) lib/libgsw.a + +$(DEPS)/Makefile.gsw.in: ../ac/deps/Makefile.gsw.in | $(DEPS) + cp ../ac/deps/Makefile.gsw.in $(DEPS)/Makefile.gsw.in + +$(DEPS)/configure.gsw.ac: ../ac/deps/configure.gsw.ac | $(DEPS) + cp ../ac/deps/configure.gsw.ac $(DEPS)/configure.gsw.ac + +# CVMix + +$(DEPS)/lib/libcvmix.a: $(DEPS)/Makefile $(DEPS)/Makefile.cvmix.in $(DEPS)/configure.cvmix.ac $(DEPS)/m4 + $(DEPS_ENV) $(MAKE) -C $(DEPS) lib/libcvmix.a + +$(DEPS)/Makefile.cvmix.in: ../ac/deps/Makefile.cvmix.in | $(DEPS) + cp ../ac/deps/Makefile.cvmix.in $(DEPS)/Makefile.cvmix.in + +$(DEPS)/configure.cvmix.ac: ../ac/deps/configure.cvmix.ac | $(DEPS) + cp ../ac/deps/configure.cvmix.ac $(DEPS)/configure.cvmix.ac + +# Generic dependency content + +$(DEPS)/Makefile: ../ac/deps/Makefile | $(DEPS) + cp ../ac/deps/Makefile $(DEPS)/Makefile + $(DEPS)/m4: ../ac/deps/m4 | $(DEPS) cp -r ../ac/deps/m4 $(DEPS)/ diff --git a/.testing/tc4/.gitignore b/.testing/tc4/.gitignore index 4f9cc2826f..0532a48da7 100644 --- a/.testing/tc4/.gitignore +++ b/.testing/tc4/.gitignore @@ -3,7 +3,9 @@ aclocal.m4 autom4te.cache/ config.log config.status +configure configure~ +Makefile # Output gen_grid diff --git a/.testing/tc4/configure.ac b/.testing/tc4/configure.ac index c431ad65ef..faba7ab7af 100644 --- a/.testing/tc4/configure.ac +++ b/.testing/tc4/configure.ac @@ -51,8 +51,8 @@ AX_FC_CHECK_C_LIB([netcdf], [nc_create], [], [ # - We test nf_create, rather than nf90_create, since AX_FC_CHECK_LIB can # not currently probe the Fortran 90 interfaces. # - nf-config does not have --libdir, so we parse the --flibs output. -AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ - AS_UNSET([ax_fc_cv_lib_netcdff_nf_create]) +MOM6_FC_CHECK_LIB([netcdff], [nf_create], [], [], [], [], [ + AS_UNSET([mom6_fc_cv_lib_netcdff_nf_create]) AC_PATH_PROG([NF_CONFIG], [nf-config]) AS_IF([test -n "$NF_CONFIG"], [ AC_SUBST([LDFLAGS], @@ -61,7 +61,7 @@ AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ ], [ AC_MSG_ERROR([Could not find nf-config.]) ]) - AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ + MOM6_FC_CHECK_LIB([netcdff], [nf_create], [], [], [], [], [ AC_MSG_ERROR([Could not find netCDF Fortran library.]) ]) ]) diff --git a/ac/Makefile.in b/ac/Makefile.in index c4d23efdfb..1821bda43d 100644 --- a/ac/Makefile.in +++ b/ac/Makefile.in @@ -14,8 +14,7 @@ CPPFLAGS = @CPPFLAGS@ FCFLAGS = @FCFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -SRC_DIRS = @SRC_DIRS@ - +MAKEDEP_FLAGS = @MAKEDEP_FLAGS@ -include Makefile.dep @@ -31,8 +30,8 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su # Generate dependencies .PHONY: depend depend: Makefile.dep -Makefile.dep: $(MAKEDEP) $(call rwildcard,$(SRC_DIRS),*.h *.c *.inc *.F90) - $(PYTHON) $(MAKEDEP) $(DEFS) -o Makefile.dep -e $(SRC_DIRS) +Makefile.dep: $(call rwildcard,$(SRC_DIRS),*.h *.c *.inc *.F90) + $(PYTHON) $(MAKEDEP) $(DEFS) -o Makefile.dep $(MAKEDEP_FLAGS) # Delete any files associated with configuration (including the Makefile). diff --git a/ac/configure.ac b/ac/configure.ac index 071f43f5a9..ded488a0bf 100644 --- a/ac/configure.ac +++ b/ac/configure.ac @@ -51,7 +51,7 @@ AS_VAR_IF([MOM_MEMORY], [], ) # Confirm that MOM_MEMORY is named 'MOM_memory.h' -AS_IF([test $(basename "${MOM_MEMORY}") == "MOM_memory.h"], [], +AS_IF([test $(basename "${MOM_MEMORY}") = "MOM_memory.h"], [], [AC_MSG_ERROR([MOM_MEMORY header ${MOM_MEMORY} must be named 'MOM_memory.h'])] ) @@ -142,8 +142,8 @@ AX_FC_CHECK_C_LIB([netcdf], [nc_create], [], [ # - We test nf_create, rather than nf90_create, since AX_FC_CHECK_LIB can # not currently probe the Fortran 90 interfaces. # - nf-config does not have --libdir, so we parse the --flibs output. -AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ - AS_UNSET([ax_fc_cv_lib_netcdff_nf_create]) +MOM6_FC_CHECK_LIB([netcdff], [nf_create], [], [], [], [], [ + AS_UNSET([mom6_fc_cv_lib_netcdff_nf_create]) AC_PATH_PROG([NF_CONFIG], [nf-config]) AS_IF([test -n "$NF_CONFIG"], [ AC_SUBST([LDFLAGS], @@ -152,7 +152,7 @@ AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ ], [ AC_MSG_ERROR([Could not find nf-config.]) ]) - AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ + MOM6_FC_CHECK_LIB([netcdff], [nf_create], [], [], [], [], [ AC_MSG_ERROR([Could not find netCDF Fortran library.]) ]) ]) @@ -160,9 +160,9 @@ AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ # Force 8-byte reals AX_FC_REAL8 -AS_IF( - [test "$enable_real8" != no], - [FCFLAGS="$FCFLAGS $REAL8_FCFLAGS"]) +AS_IF([test "$enable_real8" != no], + [FCFLAGS="$FCFLAGS $REAL8_FCFLAGS"] +) # OpenMP configuration @@ -177,8 +177,7 @@ m4_version_prereq([2.69], [AC_OPENMP], [ ]) # NOTE: Only apply OpenMP flags if explicitly enabled. -AS_IF( - [test "$enable_openmp" = yes], [ +AS_IF([test "$enable_openmp" = yes], [ FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS" LDFLAGS="$LDFLAGS $OPENMP_FCFLAGS" ]) @@ -196,10 +195,10 @@ AX_FC_CHECK_MODULE([fms_mod], [], [ ]) # Test for fms_init to verify FMS library linking -AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], +MOM6_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], [], [], [], [ - AS_UNSET([ax_fc_cv_lib_FMS_fms_init]) - AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], [ + AS_UNSET([mom6_fc_cv_lib_FMS_fms_init]) + MOM6_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], [], [], [ AC_SUBST([LDFLAGS], ["-L${srcdir}/ac/deps/lib $LDFLAGS"]) AC_SUBST([LIBS], ["-lFMS $LIBS"]) ], @@ -231,7 +230,29 @@ AX_FC_CHECK_MODULE([fms2_io_mod], [ ]) -# Python interpreter test +# GSW configuration +AX_FC_CHECK_MODULE([gsw_mod_toolbox], [], [ + AC_MSG_ERROR([Could not find module gsw_mod_toolbox.]) +]) +MOM6_FC_CHECK_LIB([gsw], [gsw_gibbs], [gsw_mod_toolbox], + [ns,nt,np,s,t,p], [x], [], [ + AC_MSG_ERROR([Could not find gsw_gibbs in gsw_mod_toolbox.]) + ] +) + + +# CVMix configuration +AX_FC_CHECK_MODULE([cvmix_utils], [], [ + AC_MSG_ERROR([Could not find module cvmix_utils.]) +]) +MOM6_FC_CHECK_LIB([cvmix], [cvmix_update_wrap], [cvmix_utils], [i,nlev], [], + [], [ + AC_MSG_ERROR([Could not find cvmix_update_wrap in cvmix_utils.]) + ] +) + + +## Python configuration # Declare the Python interpreter variable AC_ARG_VAR([PYTHON], [Python interpreter command]) @@ -255,14 +276,33 @@ AC_PATH_PROG([MAKEDEP], [makedep], [${srcdir}/ac/makedep]) AC_SUBST([MAKEDEP]) -# Generate source list and configure dependency command -AC_SUBST([SRC_DIRS], ["\\ +# Generate Makedep source list and configure dependency command +MAKEDEP_FLAGS="-e" + +# NOTE: Some pattern rules for this multiline flag constructor. +# - Previous args have no line continuation, so the next arg leads with `\\`. +# - Flag lines precede with a space ` -s` for syntax clarity. +EXCLUDE_DIRS="\\ + -s ${srcdir}/src/equation_of_state/TEOS10 \\ + -s ${srcdir}/src/parameterizations/CVmix" + +# TODO: This may be optional in the future, so we use AS_IF. +AS_IF([test -n "${EXCLUDE_DIRS}"], [ + MAKEDEP_FLAGS="${MAKEDEP_FLAGS} ${EXCLUDE_DIRS}" +]) + +SRC_DIRS="\\ ${srcdir}/src \\ ${MODEL_FRAMEWORK} \\ ${srcdir}/config_src/external \\ ${DRIVER_DIR} \\ - ${MOM_MEMORY_DIR}"] -) + ${MOM_MEMORY_DIR}" +MAKEDEP_FLAGS="${MAKEDEP_FLAGS} ${SRC_DIRS}" + +MAKEDEP_FLAGS="${MAKEDEP_FLAGS# }" +AC_SUBST([MAKEDEP_FLAGS]) + +# Add makedep to config.status AC_CONFIG_COMMANDS(Makefile.dep, [make depend]) diff --git a/ac/deps/.gitignore b/ac/deps/.gitignore index 8cfaa6ebcb..80256cfe1d 100644 --- a/ac/deps/.gitignore +++ b/ac/deps/.gitignore @@ -1,5 +1,7 @@ /bin/ /fms/ +/gsw/ +/cvmix/ /include/ /lib/ /mkmf/ diff --git a/ac/deps/Makefile b/ac/deps/Makefile index 01431cef8c..452369f93b 100644 --- a/ac/deps/Makefile +++ b/ac/deps/Makefile @@ -10,6 +10,12 @@ MAKEFLAGS += -R FMS_URL ?= https://github.com/NOAA-GFDL/FMS.git FMS_COMMIT ?= 2023.03 +GSW_URL ?= https://github.com/mom-ocean/GSW-Fortran.git +GSW_COMMIT ?= 29e64d652786e1d076a05128c920f394202bfe10 + +CVMIX_URL ?= https://github.com/mom-ocean/CVMix-src.git +CVMIX_COMMIT ?= 65ef5c73bc7f5663d5688f75c3855d431da4baea + # List of source files to link this Makefile's dependencies to model Makefiles # Assumes a depth of two, and the following extensions: F90 inc c h @@ -18,6 +24,8 @@ SOURCE = \ $(foreach ext,F90 inc c h,$(wildcard $(1)/*/*.$(ext) $(1)/*/*/*.$(ext))) FMS_SOURCE = $(call SOURCE,fms/src) +GSW_SOURCE = $(call SOURCE,gsw/src) +CVMIX_SOURCE = $(call SOURCE,CVMix-src/src/shared) # If `true`, print logs if an error is encountered. @@ -29,53 +37,66 @@ REPORT_ERROR_LOGS ?= .PHONY: all all: lib/libFMS.a +all: lib/libgsw.a +all: lib/libcvmix.a -#--- -# FMS build +# Library build rules template +# +# $(1): target library +# $(2): dependency label +# $(3): library source files +# $(4): library source URL +# $(5): library source commit -# NOTE: We emulate the automake `make install` stage by storing libFMS.a to -# ${srcdir}/deps/lib and copying module files to ${srcdir}/deps/include. -lib/libFMS.a: fms/build/libFMS.a - mkdir -p lib include - cp fms/build/libFMS.a lib/libFMS.a - cp fms/build/*.mod include +define LIB_RULES +lib/$(1): $(2)/build/$(1) + mkdir -p $$(@D) include/ + cp $$< $$@ + cp $$(dir $$<)/*.mod include/ -fms/build/libFMS.a: fms/build/Makefile - $(MAKE) -C fms/build libFMS.a +$(2)/build/$(1): $(2)/build/Makefile + $$(MAKE) -C $$(@D) $(1) -fms/build/Makefile: fms/build/Makefile.in fms/build/configure - cd $(@D) && { \ +$(2)/build/Makefile: $(2)/build/Makefile.in $(2)/build/configure + cd $$(@D) && { \ ./configure --srcdir=../src \ || { \ - if [ "${REPORT_ERROR_LOGS}" = true ]; then cat config.log ; fi ; \ + if [ "$${REPORT_ERROR_LOGS}" = true ]; then cat config.log ; fi ; \ false; \ } \ } -fms/build/Makefile.in: Makefile.fms.in | fms/build - cp Makefile.fms.in fms/build/Makefile.in +$(2)/build/Makefile.in: Makefile.$(2).in | $(2)/build + cp $$< $$@ + +$(2)/build/configure: $(2)/build/configure.ac $(3) | $(2)/src + autoreconf $$(@D) + +$(2)/build/configure.ac: configure.$(2).ac m4 | $(2)/build + cp $$< $$@ + cp -r m4 $$(@D) + +$(2)/build: + mkdir -p $$@ -fms/build/configure: fms/build/configure.ac $(FMS_SOURCE) | fms/src - autoreconf fms/build +$(2)/src: + git clone $(4) $$@ + git -C $$@ checkout $(5) -fms/build/configure.ac: configure.fms.ac m4 | fms/build - cp configure.fms.ac fms/build/configure.ac - cp -r m4 fms/build +endef -fms/build: - mkdir -p fms/build +$(eval $(call LIB_RULES,libFMS.a,fms,$(FMS_SOURCE),$(FMS_URL),$(FMS_COMMIT))) +$(eval $(call LIB_RULES,libgsw.a,gsw,$(GSW_SOURCE),$(GSW_URL),$(GSW_COMMIT))) +$(eval $(call LIB_RULES,libcvmix.a,cvmix,$(CVMIX_SOURCE),$(CVMIX_URL),$(CVMIX_COMMIT))) -fms/src: - git clone $(FMS_URL) $@ - git -C $@ checkout $(FMS_COMMIT) # Cleanup .PHONY: clean clean: - rm -rf fms/build lib include + rm -rf fms/build gsw/build cvmix/build lib include .PHONY: distclean distclean: clean - rm -rf fms + rm -rf fms gsw cvmix diff --git a/ac/deps/Makefile.cvmix.in b/ac/deps/Makefile.cvmix.in new file mode 100644 index 0000000000..b8254d9b11 --- /dev/null +++ b/ac/deps/Makefile.cvmix.in @@ -0,0 +1,30 @@ +# Makefile template for CVMix +# +# Compiler flags are configured by autoconf's configure script. +# +# Source code dependencies are configured by makedep and saved to Makefile.dep. + +FC = @FC@ +LD = @FC@ +AR = @AR@ +PYTHON = @PYTHON@ +MAKEDEP = @MAKEDEP@ + +DEFS = @DEFS@ +CPPFLAGS = @CPPFLAGS@ +FCFLAGS = @FCFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +ARFLAGS = @ARFLAGS@ + +-include Makefile.dep + +# Generate Makefile from template +Makefile: Makefile.in config.status + ./config.status + + +.PHONY: depend +depend: Makefile.dep +Makefile.dep: + $(PYTHON) $(MAKEDEP) $(DEFS) -o Makefile.dep -e -x libcvmix.a @srcdir@/src/shared diff --git a/ac/deps/Makefile.gsw.in b/ac/deps/Makefile.gsw.in new file mode 100644 index 0000000000..5cbc14bbbe --- /dev/null +++ b/ac/deps/Makefile.gsw.in @@ -0,0 +1,30 @@ +# Makefile template for GSW +# +# Compiler flags are configured by autoconf's configure script. +# +# Source code dependencies are configured by makedep and saved to Makefile.dep. + +FC = @FC@ +LD = @FC@ +AR = @AR@ +PYTHON = @PYTHON@ +MAKEDEP = @MAKEDEP@ + +DEFS = @DEFS@ +CPPFLAGS = @CPPFLAGS@ +FCFLAGS = @FCFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +ARFLAGS = @ARFLAGS@ + +-include Makefile.dep + +# Generate Makefile from template +Makefile: Makefile.in config.status + ./config.status + + +.PHONY: depend +depend: Makefile.dep +Makefile.dep: + $(PYTHON) $(MAKEDEP) $(DEFS) -o Makefile.dep -e -x libgsw.a @srcdir@ diff --git a/ac/deps/configure.cvmix.ac b/ac/deps/configure.cvmix.ac new file mode 100644 index 0000000000..9105a62ddd --- /dev/null +++ b/ac/deps/configure.cvmix.ac @@ -0,0 +1,82 @@ +# Autoconf configuration +AC_PREREQ([2.63]) + +AC_INIT( + [GSW], + [ ], + [https://github.com/TEOS-10/GSW-Fortran/issues]) + +# Validate srdcir and configure input +AC_CONFIG_SRCDIR([src/shared/cvmix_utils.F90]) +AC_CONFIG_MACRO_DIR([m4]) + + +# Standard Fortran configuration +AC_LANG([Fortran]) +AC_FC_SRCEXT([f90]) +AC_PROG_FC + + +# netCDF configuration + +# Check for netcdf.h header function declarations. +# If unavailable, then try to invoke nc-create. +AC_LANG_PUSH([C]) +AC_CHECK_HEADERS([netcdf.h], [], [ + AS_UNSET([ac_cv_header_netcdf_h]) + AC_PATH_PROG([NC_CONFIG], [nc-config]) + AS_IF([test -n "$NC_CONFIG"], [ + AC_SUBST([CPPFLAGS], ["$CPPFLAGS -I$($NC_CONFIG --includedir)"]) + ], + [AC_MSG_ERROR([Could not find nc-config.])] + ) + AC_CHECK_HEADERS([netcdf.h], [], [ + AC_MSG_ERROR([Could not find netcdf.h]) + ]) +]) +AC_LANG_POP([C]) + +# Search for the Fortran netCDF module, fallback to nf-config. +AX_FC_CHECK_MODULE([netcdf], [], [ + AS_UNSET([ax_fc_cv_mod_netcdf]) + AC_PATH_PROG([NF_CONFIG], [nf-config]) + AS_IF([test -n "$NF_CONFIG"], [ + AC_SUBST([FCFLAGS], ["$FCFLAGS -I$($NF_CONFIG --includedir)"]) + ], + [AC_MSG_ERROR([Could not find nf-config.])] + ) + AX_FC_CHECK_MODULE([netcdf], [], [ + AC_MSG_ERROR([Could not find netcdf module.]) + ]) +]) + + +# 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]) +], [ + AC_MSG_ERROR(["Could not find makedep."]) +]) + + +# Autoconf does not configure the archiver (ar), as it is handled by Automake. +AR=ar +ARFLAGS=rv +AC_SUBST([AR]) +AC_SUBST([ARFLAGS]) + +AC_CONFIG_COMMANDS([Makefile.dep], [make depend]) + +AC_SUBST([CPPFLAGS]) + +# Prepare output +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/ac/deps/configure.gsw.ac b/ac/deps/configure.gsw.ac new file mode 100644 index 0000000000..237ac74e0d --- /dev/null +++ b/ac/deps/configure.gsw.ac @@ -0,0 +1,82 @@ +# Autoconf configuration +AC_PREREQ([2.63]) + +AC_INIT( + [GSW], + [ ], + [https://github.com/TEOS-10/GSW-Fortran/issues]) + +# Validate srdcir and configure input +AC_CONFIG_SRCDIR([modules/gsw_mod_toolbox.f90]) +AC_CONFIG_MACRO_DIR([m4]) + + +# Standard Fortran configuration +AC_LANG([Fortran]) +AC_FC_SRCEXT([f90]) +AC_PROG_FC + + +# netCDF configuration + +# Check for netcdf.h header function declarations. +# If unavailable, then try to invoke nc-create. +AC_LANG_PUSH([C]) +AC_CHECK_HEADERS([netcdf.h], [], [ + AS_UNSET([ac_cv_header_netcdf_h]) + AC_PATH_PROG([NC_CONFIG], [nc-config]) + AS_IF([test -n "$NC_CONFIG"], [ + AC_SUBST([CPPFLAGS], ["$CPPFLAGS -I$($NC_CONFIG --includedir)"]) + ], + [AC_MSG_ERROR([Could not find nc-config.])] + ) + AC_CHECK_HEADERS([netcdf.h], [], [ + AC_MSG_ERROR([Could not find netcdf.h]) + ]) +]) +AC_LANG_POP([C]) + +# Search for the Fortran netCDF module, fallback to nf-config. +AX_FC_CHECK_MODULE([netcdf], [], [ + AS_UNSET([ax_fc_cv_mod_netcdf]) + AC_PATH_PROG([NF_CONFIG], [nf-config]) + AS_IF([test -n "$NF_CONFIG"], [ + AC_SUBST([FCFLAGS], ["$FCFLAGS -I$($NF_CONFIG --includedir)"]) + ], + [AC_MSG_ERROR([Could not find nf-config.])] + ) + AX_FC_CHECK_MODULE([netcdf], [], [ + AC_MSG_ERROR([Could not find netcdf module.]) + ]) +]) + + +# 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]) +], [ + AC_MSG_ERROR(["Could not find makedep."]) +]) + + +# Autoconf does not configure the archiver (ar), as it is handled by Automake. +AR=ar +ARFLAGS=rv +AC_SUBST([AR]) +AC_SUBST([ARFLAGS]) + +AC_CONFIG_COMMANDS([Makefile.dep], [make depend]) + +AC_SUBST([CPPFLAGS]) + +# Prepare output +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/ac/m4/mom6_fc_check_lib.m4 b/ac/m4/mom6_fc_check_lib.m4 new file mode 100644 index 0000000000..474919812a --- /dev/null +++ b/ac/m4/mom6_fc_check_lib.m4 @@ -0,0 +1,71 @@ +dnl MOM6_FC_CHECK_LIB(LIBRARY, PROCEDURE, +dnl [MODULE], [ARGS], [FUNC-RESULT], +dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], +dnl [OTHER-LDFLAGS], [OTHER-LIBS]) +dnl +dnl This macro checks if a Fortran library containing a designated function +dnl is available to the compiler. For the most part, this macro should behave +dnl like the Autoconf AC_CHECK_LIB macro. +dnl +dnl This macro differs somewhat from AC_CHECK_LIB, since it includes several +dnl additional arguments: +dnl +dnl 1. MODULE specifies the Fortran module containing the procedure. +dnl +dnl 2. ARGS is used to specify any arguments of the procedure. +dnl +dnl 3. FUNC-RESULT, if set, identifies the procedure as a function rather than +dnl a subroutine, and specifies the function test result. +dnl +dnl 4. OTHER-LDFLAGS allows specification of supplemental LDFLAGS arguments. +dnl This can be used, for example, to test for the library with different +dnl -L flags, or perhaps other ld configurations. +dnl +dnl Results are cached in the mom6_fc_cv_lib_LIBRARY_PROCEDURE variable. +dnl +AC_DEFUN([MOM6_FC_CHECK_LIB],[ + AS_VAR_PUSHDEF([mom6_fc_Lib], [mom6_fc_cv_lib_$1_$2]) + m4_ifval([$8], + [mom6_fc_lib_msg_LDFLAGS=" with $8"], + [mom6_fc_lib_msg_LDFLAGS=""] + ) + AC_CACHE_CHECK( + [for $2 in -l$1$mom6_fc_lib_msg_LDFLAGS], + [mom6_fc_cv_lib_$1_$2],[ + mom6_fc_check_lib_save_LDFLAGS=$LDFLAGS + LDFLAGS="$8 $LDFLAGS" + mom6_fc_check_lib_save_LIBS=$LIBS + LIBS="-l$1 $9 $LIBS" + AS_IF([test -n "$3"], + [mom6_fc_use_mod="use $3"], + [mom6_fc_use_mod=""] + ) + AS_IF([test -n "$5"], + [mom6_fc_proc="$5 = $2"], + [mom6_fc_proc="call $2"] + ) + AS_IF([test -n "$4"], + [mom6_fc_proc="${mom6_fc_proc}($4)"] + ) + AC_LANG_PUSH([Fortran]) + AC_LINK_IFELSE([dnl +dnl Begin 7-column code block +AC_LANG_PROGRAM([], [dnl + $mom6_fc_use_mod + $mom6_fc_proc])dnl +dnl End code block + ], + [AS_VAR_SET([mom6_fc_Lib], [yes])], + [AS_VAR_SET([mom6_fc_Lib], [no])] + ) + AC_LANG_POP([Fortran]) + LIBS=$mom6_fc_check_lib_save_LIBS + LDFLAGS=$mom6_fc_check_lib_save_LDFLAGS + ] + ) + AS_VAR_IF([mom6_fc_Lib], [yes], + [m4_default([$6], [LIBS="-l$1 $LIBS"])], + [$7] + ) + AS_VAR_POPDEF([mom6_fc_Lib]) +])