如何有条件地将文件包含到 Makefile 中?
考虑以下 Makefile:
# <include global configuration Makefile>
INCL = -I../include \
-I<whatever>
CPPFLAGS=$(DEFS) $(INCL)
CXXFLAGS = -O0 -g -Wall -fmessage-length=0
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
all: $(OBJS)
%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
depend: .depend
.depend: $(SRCS)
$(CPP) $(CPPFLAGS) -M $^ > $@
clean:
rm -f $(OBJS)
rm .depend
-include .depend
此 Makefile 使用 g++ -M
命令创建一个 #include
依赖链,并将其包含在内。这可能是一个相当漫长的过程。问题是,即使调用 make clean
也会生成该文件,而该文件无论如何都会被删除。有没有一种方法可以有条件地包含此文件,并且在运行干净目标时无需创建它?
Consider the following Makefile:
# <include global configuration Makefile>
INCL = -I../include \
-I<whatever>
CPPFLAGS=$(DEFS) $(INCL)
CXXFLAGS = -O0 -g -Wall -fmessage-length=0
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
all: $(OBJS)
%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ lt;
depend: .depend
.depend: $(SRCS)
$(CPP) $(CPPFLAGS) -M $^ > $@
clean:
rm -f $(OBJS)
rm .depend
-include .depend
This Makefile creates an #include
dependency chain using the g++ -M
command, and includes it. This can be a rather long process. The problem is that this file is generated even if make clean
is called, when this file would be deleted anyway. Is ther a way to conditionally include this file, and not bother creating it if the clean target is run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情:
请参阅关于目标的制作手册页更多信息
编辑:
-include
不能制表符缩进,否则会被忽略。Something like this:
See the make manual page on Goals for more information
Edit:
-include
cannot be tab indented, otherwise it is ignored.您可以在编译期间免费执行此类依赖项(即无需运行时成本)。当您运行
clean
时,依赖项自然不会被重新创建。请参阅 Paul Smith 的高级自动依赖生成中的组合编译和依赖生成部分 纸。You can do such dependencies for free (i.e., at no runtime cost) during the compile. When you run
clean
, the dependencies are naturally not remade. See the section Combining Compilation and Dependency Generation in Paul Smith's Advanced Auto-Dependency Generation paper.