跳过某些目标的 makefile 依赖项生成(例如“clean”)
我有几个 C 和 C++ 项目,它们都遵循我已经使用了一段时间的基本结构。我的源文件位于 src/*.c
中,中间文件位于 obj/*.[do]
中,实际可执行文件位于顶级目录中。
我的 makefile 大致遵循这个模板:
# The final executable
TARGET := something
# Source files (without src/)
INPUTS := foo.c bar.c baz.c
# OBJECTS will contain: obj/foo.o obj/bar.o obj/baz.o
OBJECTS := $(INPUTS:%.cpp=obj/%.o)
# DEPFILES will contain: obj/foo.d obj/bar.d obj/baz.d
DEPFILES := $(OBJECTS:%.o=%.d)
all: $(TARGET)
obj/%.o: src/%.cpp
$(CC) $(CFLAGS) -c -o $@ $<
obj/%.d: src/%.cpp
$(CC) $(CFLAGS) -M -MF $@ -MT $(@:%.d=%.o) $<
$(TARGET): $(OBJECTS)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
.PHONY: clean
clean:
-rm -f $(OBJECTS) $(DEPFILES) $(RPOFILES) $(TARGET)
-include $(DEPFILES)
现在我正在为 Debian 系统打包它。我使用 debuild
来构建 Debian 源代码包,并使用 pbuilder
来构建二进制包。 debuild
步骤只需执行 clean
目标,但即使这样也会导致生成并包含依赖项文件。
简而言之,我的问题确实是:当我只想运行 clean
目标时,我能否以某种方式阻止 make 生成依赖项?
I have several C and C++ projects that all follow a basic structure I've been using for a while now. My source files go in src/*.c
, intermediate files in obj/*.[do]
, and the actual executable in the top level directory.
My makefiles follow roughly this template:
# The final executable
TARGET := something
# Source files (without src/)
INPUTS := foo.c bar.c baz.c
# OBJECTS will contain: obj/foo.o obj/bar.o obj/baz.o
OBJECTS := $(INPUTS:%.cpp=obj/%.o)
# DEPFILES will contain: obj/foo.d obj/bar.d obj/baz.d
DEPFILES := $(OBJECTS:%.o=%.d)
all: $(TARGET)
obj/%.o: src/%.cpp
$(CC) $(CFLAGS) -c -o $@ lt;
obj/%.d: src/%.cpp
$(CC) $(CFLAGS) -M -MF $@ -MT $(@:%.d=%.o) lt;
$(TARGET): $(OBJECTS)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
.PHONY: clean
clean:
-rm -f $(OBJECTS) $(DEPFILES) $(RPOFILES) $(TARGET)
-include $(DEPFILES)
Now I'm at the point where I'm packaging this for a Debian system. I'm using debuild
to build the Debian source package, and pbuilder
to build the binary package. The debuild
step only has to execute the clean
target, but even this causes the dependency files to be generated and included.
In short, my question is really: Can I somehow prevent make from generating dependencies when all I want is to run the clean
target?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案很简单,不要在 clean 下
-include
生成文件:The solution is easy, don't
-include
generated files under clean: