标签:
.PHONY: clean all FILETYPE = c # what language is used: c or cpp TARGETS = program #target name TREE = 0 # whether the source files are organised in tree or not # (source files are divided into ‘inc‘ ‘src‘ ‘lib‘ directories): # 0 not; 1 yes ifeq ($(strip $(FILETYPE)), c) CC = gcc else CC = g++ endif MKDIR = mkdir RM = rm RMFLAGS = -rf CFLAGS = -Wall -W -g LDLIBS = # libraries to link to ,default not DIR = $(shell pwd) ifeq ($(strip $(TREE)), 0) SRC_DIR = $(DIR) LIB_DIR = $(DIR) INC_DIR = $(DIR) else SRC_DIR = $(DIR)/src LIB_DIR = $(DIR)/lib INC_DIR = $(DIR)/inc endif DEPS_DIR = $(DIR)/.deps OBJ_DIR = $(DIR)/.obj DIRS = $(DEPS_DIR) $(OBJ_DIR) RMS = $(DIRS) INCLUDE = -I$(INC_DIR) SRCS = $(wildcard $(SRC_DIR)/*.$(FILETYPE)) OBJS = $(patsubst $(SRC_DIR)/%.$(FILETYPE), $(OBJ_DIR)/%.o, $(SRCS)) DEPS = $(patsubst $(OBJ_DIR)/%.o, $(DEPS_DIR)/%.dep, $(OBJS)) RMS += $(TARGETS) $(OBJS) all: $(TARGETS) $(DEPS) ifneq ($(MAKECMDGOALS), clean) -include $(DEPS) endif $(DIRS): $(MKDIR) $(DIRS) $(TARGETS):$(OBJS) $(CC) $(INCLUDE) -L$(LIB_DIR) -o $@ $(filter %.o, $^) $(LDLIBS) $(OBJ_DIR)/%.o:$(OBJ_DIR) $(SRC_DIR)/%.$(FILETYPE) $(CC) -o $@ -c $(filter %.$(FILETYPE), $^) $(CFLAGS) $(INCLUDE) $(DEPS_DIR)/%.dep:$(SRC_DIR)/%.$(FILETYPE) $(DEPS_DIR) $(CC) -MM $(INCLUDE) $(CFLAGS) $< | sed -e ‘s,^\(.*\.o\),$(OBJ_DIR)/\1,‘ > $@ clean: $(RM) $(RMFLAGS) $(RMS).PHONY: clean all
标签:
原文地址:http://www.cnblogs.com/venus024/p/4262331.html