[英]Makefile Selecting type of compilation
我怎樣才能做到這一點,以便我可以使用make debug
或make release
之類的命令,以便它們都調用下面的規則集但具有不同的編譯標志(例如 -g 用於調試和 -DNDEBUG 用於發布)?
# Object Files
OBJECTS := $(addprefix $(BUILDDIR)/,$(SOURCEFILES:.cpp=.o))
compile: $(OUTPUT) $(MAIN)
$(OUTPUT):
@mkdir $(BUILDDIR)
$(MAIN): $(OBJECTS)
@$(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -o $(OUTPUTMAIN) $(OBJECTS)
$(BUILDDIR)/%.o: %.cpp
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
.PHONY: debug release
debug:
... Compile with debug flags ...
release:
... Compile with release flags ...
這並不難,只需使用特定於目標的變量值:
debug: CXXFLAGS += -g -whatever
release: CXXFLAGS += -DNDEBUG -otherstuff
debug release: $(OBJECTS)
link things...
但是你的設計有問題。 您使用debug
標志或release
標志構建 object foo.o
,但無論哪種方式,您都將其命名為foo.o
並將其放在同一個構建目錄中。 所以稍后,當你構建時,說release
,並且已經有一個foo.o
,Make 會很高興地使用它。 看到問題了嗎? 我建議你有兩個構建目錄,一個用於debug
,一個用於release
; 還有其他方法,但您必須在修補 makefile 之前做出決定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.