递归调用生成文件不更新目标文件 [英] Recursive call to makefile does not update object files
问题描述
我有一个递归调用本身就是一个Makefile文件。当我第一次运行make,目标文件被创建并链接就好了。但是,当我修改的源文件,并运行make再次,对象不会被重建(让说,目标是最新的)。我需要运行使清洁
然后运行make。这里是我的makefile的简化版本,我认为包括所有相关信息:
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
所以运行使PROGNAME
第一次编译就好了。但第二返回作: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.
先谢谢了。
推荐答案
目标 PROGNAME
没有prerequisites。
The target PROGNAME
has no prerequisites.
首次使PROGNAME
,让看到的,有没有这样的文件,所以它执行的规则。
The first time you make PROGNAME
, Make sees that there is no such file, so it executes the rule.
第二次(修改 shared1.o
)后,使该看到 PROGNAME
已经存在,而且目标没有prerequisites,所以认为没有必要重建目标。它不知道 PROGNAME
取决于 shared1.o
,因为你没有告诉它。
The second time (after you modify shared1.o
), Make sees that PROGNAME
already exists, and that the target has no prerequisites, so it sees no need to rebuild the target. It doesn't know that PROGNAME
depends on shared1.o
, because you didn't tell it.
有是解决这个问题的一种以上的方法。我建议你弄死递归完全和使用特定目标变量的值:
There's more than one way to solve this problem. I suggest you do away with the recursion entirely and use a target-specific variable value:
PROGNAME: EXTRA_FLAGS="$(FLAGS)"
PROGNAME: PROGNAME_TARGET
(你的目标名称有待改进,但可以等待。)
(Your target names could be improved, but that can wait.)
这篇关于递归调用生成文件不更新目标文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!