DIR_INC = ./include
DIR_SRC = ./src
DIR_OBJ = ./obj
DIR_BIN = ./bin
INCLUDES = -I${DIR_INC} -I.
CC = g++
CFLAGS = -g -Wall ${INCLUDES}
SRV_SRC = $(wildcard ${DIR_SRC}/srv/*.cpp)
CLI_SRC = $(wildcard ${DIR_SRC}/cli/*.cpp)
SRV_OBJ = $(patsubst %.cpp,${DIR_OBJ}/srv/%.o,$(notdir ${SRV_SRC}))
CLI_OBJ = $(patsubst %.cpp,${DIR_OBJ}/cli/%.o,$(notdir ${CLI_SRC}))
OBJ = ${SRV_OBJ} ${CLI_OBJ}
SRC = ${SRV_SRC} ${CLI_SRC}
SRV_BIN = ${DIR_BIN}/srvMain
CLI_BIN = ${DIR_BIN}/cliMain
BIN_TARGET = ${SRV_BIN} ${CLI_BIN}
all:${BIN_TARGET}
${SRV_BIN}:${SRV_OBJ}
$(CC) $(SRV_OBJ) -o $@
${CLI_BIN}:${CLI_OBJ}
$(CC) $(CLI_OBJ) -o $@
${DIR_OBJ}/srv/%.o:${DIR_SRC}/srv/%.cpp
$(CC) $(CFLAGS) -c $< -o $@
${DIR_OBJ}/cli/%.o:${DIR_SRC}/cli/%.cpp
$(CC) $(CFLAGS) -c $< -o $@
.PHONY:clean
clean:
rm -rf ${BIN_TARGET} ${CLI_OBJ} ${SRV_OBJ}
# find ${DIR_OBJ} -name *.o -exec rm -rf {}
wildcard: 从一个文件目录下过滤出我们需要格式的所有文件。 eg:从某目录下找出所有.cpp文件
patsubst: 从一个文件目录下某个格式的所有文件转换成对应的另外一种格式。 eg:目录下的所有.cpp文件转变成.o文件