萬能Makefile
fromhttp://blog.csdn.net/autumnqin/article/details/44080841##################################################### Generic makefile - 萬能Makefile# for compiling and linking C++ projects on Linux# Author: George Foot Modified:Jackie Lee####################################################### Customising## Adjust the following if necessary; EXECUTABLE is the target# executable"s filename, and LIBS is a list of libraries to link in# (e.g. alleg, stdcx, iostr, etc). You can override these on make"s# command line of course, if you prefer to do it that way.##EXECUTABLE := main # 可執行文件名LIBDIR:= # 靜態庫目錄LIBS := # 靜態庫文件名INCLUDES:=. # 頭文件目錄SRCDIR:= # 除了當前目錄外,其他的源代碼文件目錄## # Now alter any implicit rules" variables if you like, e.g.:CC:=g++CFLAGS := -g -Wall -O3CPPFLAGS := $(CFLAGS)CPPFLAGS += $(addprefix -I,$(INCLUDES))CPPFLAGS += -MMD## # The next bit checks to see whether rm is in your djgpp bin# # directory; if not it uses del instead, but this can cause (harmless)# # `File not found" error messages. If you are not using DOS at all,# # set the variable to something which will unquestioningly remove# # files.#RM-F := rm -f# # You shouldn"t need to change anything below this point.#SRCS := $(wildcard *.cpp) $(wildcard $(addsuffix /*.cpp, $(SRCDIR)))OBJS := $(patsubst %.cpp,%.o,$(SRCS))DEPS := $(patsubst %.o,%.d,$(OBJS))MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.cpp,$(MISSING_DEPS))).PHONY : all deps objs clean veryclean rebuild infoall: $(EXECUTABLE)deps : $(DEPS)objs : $(OBJS)clean :@$(RM-F) *.o@$(RM-F) *.dveryclean: clean@$(RM-F) $(EXECUTABLE)rebuild: veryclean allifneq ($(MISSING_DEPS),)$(MISSING_DEPS) :@$(RM-F) $(patsubst %.d,%.o,$@)endif-include $(DEPS)$(EXECUTABLE) : $(OBJS)$(CC) -o $(EXECUTABLE) $(OBJS) $(addprefix -L,$(LIBDIR)) $(addprefix -l,$(LIBS))info:@echo $(SRCS)@echo $(OBJS)@echo $(DEPS)@echo $(MISSING_DEPS)@echo $(MISSING_DEPS_SOURCES)##註:1)命令行前的空白符必須為一個製表符(Tab);如,@$(RM-F) *.o前不是空格,而是一個製表符;內容解析1.Makefile基本語法target為要生成的目標文件;dependency為target的依賴文件;command為用於生成target的命令行; : ...(tab)