How to convert a Makevars into a Makefile? (Windows, Fortran)

I am writing a package based on some Fortran code using the instructions at
https://www.avrahamadler.com/2018/12/09/the-need-for-speed-part-1-building-an-r-package-with-fortran/

My package builds with the following Makevars file and I can call it successfully from R.

Now I am trying to debug it using the GNU debugger gdb. I wrote a f90 wrapper to replace the C wrapper hotnetc.c, but I need to create a suitable Makefile based on this Makevars (I will use mingw32-make. What do I need to change/add to the below file?

I am working in VSCODE following the instructions at
https://www.youtube.com/watch?v=XuNjA230e3k
I was able to get make and debug working in Windows following his example,

Thanks!

# https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gfortran/Preprocessing-and-conditional-compilation.html
PKG_FCFLAGS += -x f95-cpp-input 

C_OBJS = hotnetc.o
FT_OBJS = nrtype.o ioinfo.o exit_hotnet.o empdis.o model_time.o 
FT_OBJS += simul_info.o basinparam.o basin_flux.o soilxs_bas.o hotnetf.o 

all: $(SHLIB) clean

$(SHLIB): $(FT_OBJS) $(C_OBJS)

empdis.o: nrtype.o 
basin_flux.o model_time.o simul_info.o: nrtype.o 
basinparams.o: empdis.o 
soilxs_bas.o: model_time.o basinparams.o basin_flux.o simul_info.o 
hotnetf.o: soilxs_bas.o 
hotnetmodule.mod: hotnetf.o 
hotnetc.o: hotnetmodule.mod 

clean:
	rm -rf *.mod *.o

Update:
The Makefile here seems to work work:
https://stackoverflow.com/questions/5871780/creating-a-fortran-makefile

Actually this is the one that works in Windows 10. I was able to build the package with the above Makevars and debug using a wrapper and this Makefile in the same folder.

FC=C:\\Rtools\\mingw_64\\bin\\gfortran
# https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gfortran/Preprocessing-and-conditional-compilation.html
# https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
# https://faculty.washington.edu/rjl/uwamath583s11/sphinx/notes/html/gfortran_flags.html
FCFLAGS=-c -g -x f95-cpp-input  
FLFLAGS=

FT_OBJS = nrtype.o ioinfo.o exit_hotnet.o empdis.o model_time.o 
FT_OBJS += simul_info.o basinparam.o basin_flux.o soilxs_bas.o hotnetf.o 
FT_OBJS += debug.o
SRCS:=$(patsubst %.f90, %.o, $(wildcard *.f90)) 

# https://stackoverflow.com/questions/5871780/creating-a-fortran-makefile
PROGRAM=debug

$(SHLIB): $(FT_OBJS)

empdis.o ioinfo.o basin_flux.o model_time.o simul_info.o: nrtype.o 
exit_hotnet.o: ioinfo.o
basinparam.o: empdis.o 
soilxs_bas.o: model_time.o basinparam.o basin_flux.o simul_info.o exit_hotnet.o
hotnetf.o: soilxs_bas.o 
hotnetmodule.mod: hotnetf.o 
debug.o: hotnetmodule.mod

all: $(PROGRAM) clean

$(PROGRAM): $(SRCS)
	$(FC) $(FLFLAGS) -o $@ $^

%.o: %.f90
	$(FC) $(FCFLAGS) -o $@ $<

clean:
	del *.o
	del *.mod

# run
run:
	C:\\Rtools\\mingw_64\\bin\\mingw32-make
	./debug.exe

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.