title: Makefile with Fortran - src and bin directories
body: <p>I'm having some trouble understanding how to design my makefile to build my project the way I want to. Specifically, I can't figure out how to keep all source files in a <code>src</code> directory, while putting all binaries in a <code>bin</code> directory except the linked executable, which goes in the project root.</p>
  
  <p>This is my makefile:</p>
  
  <pre><code># Compiler options
  FC          :=  mpif90
  FFLAGS      :=  -O3 -g -Wall -Warray-bounds -ffixed-line-length-none -fbounds-check 
  VPATH       :=  src
  BINDIR      :=  bin
  
  # Define file extensions
  .SUFFIXES:
  .SUFFIXES: .f .o .mod 
  
  # All modules
  OBJS        :=  $(BINDIR)/ratecoeffs.o $(BINDIR)/interpolation.o $(BINDIR)/io.o $(BINDIR)/eedf.o $(BINDIR)/single_particle.o $(BINDIR)/physics.o $(BINDIR)/random.o $(BINDIR)/mpi.o $(BINDIR)/precision.o $(BINDIR)/populations.o 
  
  # Build rules
  all: runner | $(BINDIR)
  
  $(BINDIR):
      mkdir -p $(BINDIR)
  
  $(BINDIR)/%.o: $(VPATH)/%.f | $(BINDIR)
      $(FC) $(FFLAGS) -c $^ -o $@
  
  runner: $(OBJS)
  
  clean:
      @rm -rf $(BINDIR)
  </code></pre>
  
  <p>Running <code>make</code> builds everything allright - it finds all source files in <code>src</code> and puts all <code>.o</code> files in <code>bin</code> - but the module files (<code>.mod</code>) that are generated by the compiler are put in the project root instead of in the <code>bin</code> directory. I realize I could just specify a rule to place them there, but <a href="http://lagrange.mechse.illinois.edu/mwest/f90_mod_deps/" rel="nofollow">that messes with the build order, and will sometimes break the build</a>.</p>
  
  <p>What is the "correct" way to get this behavior?</p>
  
  <p><em>And yes, I've looked at autotools and automake, but I've never used them before and they seem to be overkill for this project. As I couldn't find any good tutorials on how they work (no, I didn't like <a href="http://www.gnu.org/software/autoconf/#introduction" rel="nofollow">the tutorial on gnu.org</a>) I'd prefer if I could avoid having to learn this tool just to get this work...</em></p>