I have the following Makefile sample:
BUILD = build
PATH_POT3 = src/pot/pot3/
MPIFC = mpiifort
FFLAGS = -O3
MOL_LIST = $(shell find $(PATH_POT3) -mindepth 1 -maxdepth 1 -type d)
$(foreach MOL,$(MOL_LIST), \
$(eval LIST_MOL := $(shell find $(MOL) -name "*.f90")) \
$(info Fortran files: $(LIST_MOL)) \
$(foreach SRC,$(LIST_MOL), \
$(eval OBJ := $(BUILD)/$(notdir $(SRC:.f90=.o))) \
$(OBJ): $(SRC) ; \
$(info Compiling: $(SRC)) \
$(info Output: $(OBJ)) \
$(MPIFC) $(FFLAGS) -c $(SRC) -o $(OBJ) \
) \
)
all: $(foreach MOL,$(MOL_LIST),\
$(foreach SRC,$(shell find $(MOL) -name "*.f90"),\
$(BUILD)/$(notdir $(SRC:.f90=.o))\
)\
)
Here I would like to compile the (recursive) content of each PATH_POT3 subdirectory in a sequential way (one subdirectory after another).
Unfortunately, this construction does not provide the desired result as it compiles only the first object file in the list, all the other object files are skipped.
The Makefile prints out the following information for my test case:
Fortran files: src/pot/pot3/ar3/pot_ar3.f90 src/pot/pot3/ar3/ar43/pot_ar43.f90
Compiling: mpiifort -O3 -c src/pot/pot3/ar3/pot_ar3.f90 -o build/pot_ar3.o
Output: build/pot_ar3.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar3/ar43/pot_ar43.f90 -o build/pot_ar43.o
Output: build/pot_ar43.o
Fortran files: src/pot/pot3/ar33/pot_ar33.f90 src/pot/pot3/ar33/pot_ar333.f90 src/pot/pot3/ar33/ar53/pot_ar53.f90
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/pot_ar33.f90 -o build/pot_ar33.o
Output: build/pot_ar33.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/pot_ar333.f90 -o build/pot_ar333.o
Output: build/pot_ar333.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/ar53/pot_ar53.f90 -o build/pot_ar53.o
Output: build/pot_ar53.o
make: 'build/pot_ar3.o' is up to date.
Everything seems to be set correctly, but the compilation is executed only for build/pot_ar3.o.
How should I change this file to obtain the required behavior?