#make clean;make SUPPORT=-DWEIYOUQING
make clean;make SUPPORT=TESTDEFINE
#目标 TARGET = main #源代码文件路径 SRC_DIR := ./Src SRC_DIR := $(shell ls -R $(SRC_DIR) | grep '^./.*:$$' | awk '{gsub(":","");print}') #工作路径 WORK_DIR = $(shell pwd) #头文件路径 INCLUDE_DIR = -I$(WORK_DIR)/Src -I$(WORK_DIR)/Include #临时文件 INTER_DIR = Tmp/obj/Test CROSS= CC = $(CROSS)gcc CPP = $(CROSS)g++
#宏定义
#SUPPORT = -D WEIYOUQING
SUPPORT ?= NOTESTDEFINE
ifeq ($(strip $(SUPPORT)), TESTDEFINE)
CFLAGS += -D WEIYOUQING
endif
CFLAGS = $(SUPPORT) -Wall -O2 -g -fstack-protector-all CFLAGS += $(INCLUDE_DIR) LDLIBS = -L./Lib LFLAGS += $(LDLIBS) -lpthread -lrt -ldl -lgcov SRC_DIR := $(patsubst *, $(WORK_DIR)/*, ${SRC_DIR}) SRC_FILE_CPP := $(foreach dir, ${SRC_DIR}, $(wildcard $(dir)/*.cpp)) SRC_FILE_C := $(foreach dir, ${SRC_DIR}, $(wildcard $(dir)/*.c)) INTER_OBJ = $(patsubst %.cpp, $(INTER_DIR)/%.o, ${SRC_FILE_CPP}) INTER_OBJ += $(patsubst %.c, $(INTER_DIR)/%.o, ${SRC_FILE_C}) $(foreach dir, $(SRC_DIR), $(shell mkdir -p $(INTER_DIR)/$(dir))) all: $(TARGET) $(TARGET) : $(INTER_OBJ) $(CPP) $^ $(LFLAGS) -o $@ $(INTER_DIR)/%.o : $(WORK_DIR)/%.cpp $(CPP) -c $(CFLAGS) $< -o $@ @echo "-----------------------" echo $@ $(INTER_DIR)/%.o : $(WORK_DIR)/%.c $(CC) -c $(CFLAGS) $< -o $@ @echo "-----------------------" echo $@ clean: echo $(WORK_DIR) rm -rf ${INTER_OBJ} rm -rf $(TARGET)