Fortran: makefile error

708 views Asked by At

I have a fortran main program called solidsolver.f90, and a module called read_mesh.f90. The module contains two subroutines and is used in the main program. I can compile them manually but not with a makefile. My makefile is named makefile.makefile, and it gives me an error:

make: *** No targets specified and no makefile found. Stop.

I do need a makefile written in a concise way because in the future my code will grow exponentially. Here is the makefile:

  OBJECTS = read_file.o solidsolver.o

  MODULES = read_file.mod

  .PHONY: clean

  main.exe: $(MODULES) $(OBJECTS)
      gfortran $(OBJECTS) -o main.exe

  %.o: %.f90
      gfortran -c $<

  %.mod: %.f90
      gfortran -c $<

  clean:
      rm -f $(OBJECTS) $(MODULES) main.exe
2

There are 2 answers

0
Jie Cheng On BEST ANSWER

Alex is right. But actually the content of the makefile is wrong. I changed it as following and it works:

   OBJECTS = read_file.o solidsolver.o
   MODULES = read_file.mod 
   FC = gfortran
   main.exe: $(OBJECTS)
        $(FC) -o main $(OBJECTS)

   solidsolver.o: $(MODULES) solidsolver.f90
        $(FC) -c solidsolver.f90

   %.mod: %.f90
        $(FC) -c $<

   %.o: %.f90
        $(FC) -c $<

  clean:
       rm -f *.o *.mod main
1
Alexander Vogt On

GNU make is looking for makefiles in the following order (from the man page):

[...] GNUmakefile, makefile, and Makefile, in that order.

To use a file called makefile.makefile, you need to tell make to use that (non-standard) file explicitely:

make -f makefile.makefile