考虑以下生成文件:如何有条件地将文件包含到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 [email protected] $<
depend: .depend
.depend: $(SRCS)
$(CPP) $(CPPFLAGS) -M $^ > [email protected]
clean:
rm -f $(OBJS)
rm .depend
-include .depend
此生成的文件创建使用g++ -M
命令的#include
依赖关系链,并包括它。这可能是一个相当长的过程。问题是即使调用了make clean
,该文件仍会被生成,但仍然会删除该文件。是否有条件地包含这个文件,并且如果干净的目标运行时不打扰创建它?
这回答详细[这里] [1]。 [1]:http://stackoverflow.com/questions/3714041/why-does-this-makefile-execute-a-target-on-make-clean/3714054#3714054 – 2011-02-02 09:17:05