考慮以下生成文件:如何有條件地將文件包含到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