0

I have a module file in the include directory, which I compile using Makefile from root directory.

$(FC) -c include/my_mod.F90

Compilation works fine, just my module shows up in the root directory instead of the include directory. How can I specify location of the output file?

I am using linux system, and I would like to support both gfortran and ifort.

Andrew
  • 958
  • 13
  • 25
  • 1
    This will depend on your compiler, so please give further detail. And it's the `.mod` file not the `.o` (again, change the extensions to suit your system) you want to control? For gfortran, for example, you can [see here](https://stackoverflow.com/q/8855896/3157076). – francescalus Jul 31 '18 at 13:09
  • 1
    Maybe use an option to specify where to put the `.mod` files (when I'm not mistaken: gfortran `-J`, Intel `-module`). – albert Jul 31 '18 at 13:16
  • 1
    `$(FC) -c include/my_mod.F90 -module include/ -o include/my_mod.o` works perfectly! Thanks. I assume I have to write support for gfortran/ifortran (to switch `-J` and `-module`) by myself. – Andrew Jul 31 '18 at 13:35

1 Answers1

0

Thank @albert and @francescalus, the solution is:

ifeq ($(FC),ifort)
        FORTFLAGS=-module
else
        FORTFLAGS=-J
endif

module:
        $(FC) -c include/my_mod.F90 $(FORTFLAGS) include/ -o include/my_mod.o
Andrew
  • 958
  • 13
  • 25