CESR-lab / ucla-roms

GNU General Public License v3.0
5 stars 11 forks source link

update makefiles #48

Open dafyddstephenson opened 1 month ago

dafyddstephenson commented 1 month ago

This is more or less the same as #18 , but I've updated src/Makefile to fix the bug of not being able to run make twice without make compile_clean in between caused a failure. It would be good to extend this to be compatible with ifx.

Here's the text from the previous PR:

Hi again! This PR comes from our use of ROMS on multiple machines (I think I'm up to 6 now...), each with their own idiosyncrasies. I've overhauled Makedefs.inc and made changes to the other Makefiles so that they are more flexible, without losing any of the existing functionality. The makefiles should now be machine-independent, and options can now be directly invoked without modifying the files, e.g. make COMPILER=gnu BUILD_MODE=debug.

As always, happy to incorporate any feedback.

Here's a list of what I've done:

In Makedefs.inc :

  • include user options COMPILER (default intel), MPI_DIST (default generic, so use mpifort), BUILD_MODE (default regular, but can be set to, .e.g. debug ), KEEP_PPSRC (for keeping preprocessed source code after compilation, default false)
  • Add conditional logic to determine if user is likely using a case-insensitive filesystem and change extensions accordingly to avoid conflicts (e.g. when .F -> .f ; this is problematic on macOS)
  • ... accordingly, use variables for file extensions throughout
  • Change "comment/uncomment" FFLAGS approach to setting FFLAGS based on user option BUILD_MODE (e.g. debug)
  • Change flags and compile options based on compiler using COMPILER variable (currently either gnu or intel )
  • Check mpifort is wrapping the expected compiler, exit if not
  • Read cppdefs.opt (if present) to check if we need to compile with MARBL libraries. Without this change, MARBL include and lib statements are present in Makedefs.inc even when the user does not plan to use MARBL.
  • add fallback option if n{c,f}-config --args returns an empty string, as happens on some systems (perlmutter, cheyenne)

    In src/Makefile:

  • create SRCS list using shell instead of manually entering every .F file; manually include or exclude additional files
  • move .F files which seemingly did not belong to any target into src/other for further evaluation (possible Legacy code)
  • Add a fallback option in python (Tools-Roms/makedep.py) if makedepf90 fails, as happens on some distributions with .F files.
  • add a help target

    in Work/Makefile:

  • use perl instead of sed on add_git_hash, which is more consistent across distributions
  • add a tools-roms option, similarly to the nhmg option
  • modify the nhmg option to go straight to $ROMS_ROOT/NHMG/src and run make, as running make in $ROMS_ROOT/NHMG was effectively just doing cd src;make . Deleted $ROMS_ROOT/NHMG/Makefile

    in Tools-Roms/Makefile:

  • Removed the manual override of Makedefs.inc. There is now a check for the presence of the -ip flag in the FFLAGS variable inherited from Makedefs.inc, and it is removed automatically if so.
  • Made consistent formatting for each target, similar to r2r_bry before: make a list as a variable and provide that list to the target. This allowed for variable file extensions (as needed on case-insensitive filesystems) without cluttering the appearance of the file.

    in NHMG/src/Makefile:

  • cosmetic changes for consistency with other makefiles, e.g. $sources -> $SRCS
  • create SRCS list automatically rather than manually listing .f90 files, as in src/Makefile
  • deleted manual overrides of Makedefs.inc, no longer needed

I've tested it on a few machines and it works as expected, let me know your thoughts! Thanks Dafydd