If I understand correctly then what you are doing is just fine.
When you build progA
the compiler encounters, on tackling sub.f90
, a statement such as use globals
. At that point the compiler will look for a file called globals.mod
which it should, by that point, have created by compiling the module source. Of course, that module source need not be in a file called globals.f90
but that's neither here nor there. The module source might, for example, be in a file called globals_for_a.f90
.
When you build progB
the compiler encounters, on tackling sub.f90
, a statement such as use globals
. At that point the compiler will look for a file called globals.mod
which it should, by that point, have created by compiling the module source. Of course, that module source need not be in a file called globals.f90
but that's neither here nor there. The module source might, for example, be in a file called globals_for_b.f90
.
So long as the compilation for each program finds the right source for globals.mod
everything should compile as you wish. You've chosen to divide your source files across a number of directories but that's not strictly necessary; a make file with suitably defined targets could build either program or both however you organise the source files and directories.
Note that almost all of this is outside the concern of the Fortran standards, it's more a question of how compilers and compilation work.