LF Fortran 95

Building a Program with Module Dependencies

This example makefile builds a program consisting of three files, a main program and two modules. The main program (main.f90) uses a module (mod2.f90), which itself uses another module (mod1.f90). The order that the files are compiled in is critical, because any module that is used must be compiled before the procedure that uses it. If mod1.f90 is changed, all the source files must be recompiled in the order mod1.f90, mod2.f90, main.f90, to satisfy the use requirement. If mod2.f90 is changed, mod1.f90 does not need to be recompiled, but mod2.f90 and main.f90 must be recompiled in order. Because of these requirements, the dependencies need to be written in a way that ensures the correct files are compiled, in the correct order.

FC = lf95 .f90.obj : $(FC) -c $< OBJS = main.obj mod1.obj mod2.obj TARGET = main.exe $(TARGET) : $(OBJS) $(FC) $(OBJS) -out $@ main.obj : mod2.obj main.f90 mod2.obj : mod1.obj mod2.f90 mod1.obj : mod1.f90

When the dependency rule for a module-dependent object file is specified, the object will depend on both the object file from the used module along with the object's source file. If the used module is out of date, its build rule will be invoked before the module-using source file is compiled.

See Also

NMAKE Reference