I have a makefile with a recursive call to itself. When I first run make, the object files are created and linked just fine. But when I modify a source file and run make again, the objects are not recreated (make says the target is up to date). I need to run make clean
and then run make. Here is simplified version of my makefile which I think includes all relevant information:
PCC = mpicc
#Locations
OBJDIR = ./objects
#Compiler and linker flags
FLAGS = -g -lm
#Object files
SHAREDOBJS = $(addprefix $(OBJDIR)/,shared1.o shared2.o)
SPECIFICOBJS = $(addprefix $(OBJDIR)/,specific1.o specific2.o)
#How to compile and link
$(OBJDIR)/%.o: %.c
$(PCC) -c $*.c $(EXTRA_FLAGS) -o $(OBJDIR)/$*.o
PROGNAME:
$(MAKE) $(MAKEFLAGS) EXTRA_FLAGS="$(FLAGS)" PROGNAME_TARGET
PROGNAME_TARGET: $(SHAREDOBJS) $(SPECIFICOBJS)
$(PCC) $(SHAREDOBJS) $(SPECIFICOBJS) $(EXTRA_FLAGS) -o PROGNAME
So running make PROGNAME
the first time compiles just fine. But the second returns make: "PROGNAME" is up to date.
It appears to me that the recursive call is never made. For example, if I add an echo
right before the call to make, nothing is displayed in stdout
.
Why is this happening? Why are the timestamps on the source files not checked in the recursive call? I don't understand why the recursion breaks the dependency on the source files.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…