Automatic Ordering of Object Files “*.o” in a Fortran Makefile

后端 未结 2 1094
一向
一向 2020-12-14 12:18

Here I have two Fortran90 files and a makefile:

Contents of file main_mod.f90:

module main_mod

contains

  subroutine add(         


        
相关标签:
2条回答
  • 2020-12-14 12:28

    ... Specify them in your rules.

    main_mod2.o: main_mod.o
    
    0 讨论(0)
  • 2020-12-14 12:43

    While gcc does have -M and related flags for doing exactly this with C/C++ files, they unfortunately do not work with gfortran. Actually, it is possible, but only if you already know the dependencies. Therefore you will need an external program to generate your dependencies.

    In my projects, I use this python script, and add the following to my makefile:

    # Script to generate the dependencies
    MAKEDEPEND=/path/to/fort_depend.py
    
    # $(DEP_FILE) is a .dep file generated by fort_depend.py
    DEP_FILE = my_project.dep
    
    # Source files to compile
    OBJECTS = mod_file1.f90 \
              mod_file2.f90
    
    # Make sure everything depends on the .dep file
    all: $(actual_executable) $(DEP_FILE)
    
    # Make dependencies
    .PHONY: depend
    depend: $(DEP_FILE)
    
    # The .dep file depends on the source files, so it automatically gets updated
    # when you change your source
    $(DEP_FILE): $(OBJECTS)
        @echo "Making dependencies!"
        cd $(SRCPATH) && $(MAKEDEPEND) -w -o /path/to/$(DEP_FILE) -f $(OBJECTS)
    
    include $(DEP_FILE)
    

    fort_depend.py basically just makes a list of all the modules USEd in a given file.

    0 讨论(0)
提交回复
热议问题