I have been trying to create a makefile that takes multiple sources in a file tree and produces an individual binary for each source. My current project is structured like so:
topdir/
bin/
[Other Directories]
Gamma/
Makefile
5a5/
prog1.5.f03
prog2.5.f03
.
.
.
5a10/
prog1.10.f03
prog2.10.f03
.
.
.
5a15/
.
.
.
I would like to produce a binary for every source file in the subdirectories and place those in bin/
.
Below is my current Makefile:
#Compliler
FC=gfortran
#Directories for build and sources
BIN=topdir/bin
FROOT=topdir/Gamma
#Source files
SRCF =$(wildcard $(FROOT)/5a5/*.f03)
SRCF+=$(wildcard $(FROOT)/5a10/*.f03)
SRCF+=$(wildcard $(FROOT)/5a15/*.f03)
SRCF+=$(wildcard $(FROOT)/5a20/*.f03)
SRCF+=$(wildcard $(FROOT)/5a25/*.f03)
#Binary targets
EXES=$(addprefix $(BIN)/,$(notdir $(patsubst %.f03,%,$(SRCF))))
#Flag to place mods with binaries
FCFLAGS= -J $(BIN)
all: $(EXES)
$(EXES): $(SRCF)
$(FC) $(FCFLAGS) -o $@ $<
This works but only compiles the first file in $(SRCF) to all targets. I would like to find a way for this to run my list of sources and match one target to one source of the same name.
I looked through these three other questions to get me to this point, but I am missing a final piece to get me to my goal.
*C++ Single Makefile Multiple Binaries
*Compile multiple executables from multiple source directories to single bin directory using makefile
*Makefile: Compiling from directory to another directory
Thanks in advance!