1、设计一个可以被包含的头make文件 " make.rule "
SRC_FILE += $(wildcard ${DIR_SRC}/*.cpp)
OBJ += $(patsubst %.cpp,${DIR_OBJ_SRC}/%.o, $(notdir ${SRC_FILE}))
LIB += -L. -levent -lpthread -lcurl -lhiredis
BIN_TARGET += ${DIR_BIN}/${TARGET}
CC = g++
CFLAGS += -std=c++0x -Wall -g ${DIR_INC}
#----------------------------------------------------
$(filter %.a, $(TARGET)):${OBJ}
ar -cr ${BIN_TARGET} $(OBJ)
$(filter %.so, $(TARGET)):${OBJ}
${CC} -shared -fpic -o ${BIN_TARGET} $(OBJ) ${LIB}
${BIN_TARGET}:${OBJ}
$(CC) $(CFLAGS) $(OBJ) -o $@ ${LIB}
${DIR_OBJ_SRC}/%.o:${DIR_SRC}/%.cpp
$(CC) $(CFLAGS) -c $< -o $@
#-------------------------------------------------------
.PHONY:clean
clean:
-rm -f ${DIR_OBJ_SRC}/*.o ${BIN_TARGET}
2、补全该头文件缺失的部分, " MakeFile "
DIR_SRC = ./src #源文件所在位置
DIR_OBJ_SRC = ./obj #生成的OBJ文件所在的位置
DIR_BIN =./lib #依赖的静态库目录
TARGET = libcirus.a #.a结尾表示,将生成静态库;.so结尾表示生成动态库;其他表示可执行文件
#------------------------------------------------
DIR_INC += -I ./include #头文件包含目录
#LIB += -L ../CirusLib/lib/ -lcirus #静态库依赖
#------------------------------------------------
include ../make.rule #引入make头文件