Makefile 中的依赖关系
假设我有一个 Makefile:
all: $(BINARY)
$(BINARY): $(OBJS) $(DEBUG_OBJS)
#Link objects here
$(OBJS): headers
#Compile code into objects without debug option
$(DEBUG_OBJS): headers
#Compile code into objects with debug option
headers:
#Create on-the-fly header files
如您所见,$(OBJS)
和 $(DEBUG_OBJS)
都需要目标 headers
。问题是,headers
会被调用两次吗?另外,下面的代码是否与上面的代码相同/等效:
all: $(BINARY)
$(BINARY): headers $(OBJS) $(DEBUG_OBJS)
#Link objects here
$(OBJS):
#Compile code into objects without debug option
$(DEBUG_OBJS):
#Compile code into objects with debug option
headers:
#Create on-the-fly header files
其中,标头是否会在 $(OBJS)
和 $(DEBUG_OBJS)
之前由 $ 调用(二进制)?
Suppose I have a Makefile:
all: $(BINARY)
$(BINARY): $(OBJS) $(DEBUG_OBJS)
#Link objects here
$(OBJS): headers
#Compile code into objects without debug option
$(DEBUG_OBJS): headers
#Compile code into objects with debug option
headers:
#Create on-the-fly header files
As you can see, the target headers
is required by both $(OBJS)
and $(DEBUG_OBJS)
. The question is, will headers
be called twice? Also, would the below code be equal/equivalent to the above:
all: $(BINARY)
$(BINARY): headers $(OBJS) $(DEBUG_OBJS)
#Link objects here
$(OBJS):
#Compile code into objects without debug option
$(DEBUG_OBJS):
#Compile code into objects with debug option
headers:
#Create on-the-fly header files
in that, would headers get called before $(OBJS)
and $(DEBUG_OBJS)
by $(BINARY)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,
headers
只会执行一次。您可以编写一个简单的 makefile 来测试它:
在执行
make
时,hi
将仅回显一次。在第二种情况下, make 会首先看到
$(BINARY)
依赖于headers
,因此它会在其他依赖项之前执行headers
。No,
headers
will be done just once.You can write a simple makefile to test it:
On doing
make
,hi
will be echoed just once.And in your 2nd case make sees that
$(BINARY)
depends onheaders
first, so it goes and doesheaders
before other dependencies.