研究了不少文章,我行通了一个,但是也不全,目前只能适用当前文件夹,如果源文件有子文件夹处理不了,还得继续研究。很多人说编译完把O文件移动走或者直接删掉。我想说的是不符合我的要求,移走或者删除O文件,每次都要全部重新编译。
get_all_sources=$(shell find $(1) -name "*.$(2)")MAKE_CACHE := ../../vsout/Gate/release.x64-linux
DUMMY_CREATE_OUTPUT_DIR := $(shell mkdir -p $(MAKE_CACHE))
CPPSRC_FLIE=$(call get_all_sources,./,cpp)
TEMP_OBJ = $(patsubst %.cpp,$(MAKE_CACHE)/%.o, $(notdir $(CPPSRC_FLIE)))INCLUDE=-I ./ \-I ../Common \-I ../Extralib \-I ../thirdparty/protobuf-3.14.0/src \-I ../thirdparty/jsoncpp-master \-I ../thirdparty/mysql/linux_64/include \-I ../thirdparty/HP-Socket-dev/Linux/include/hpsocketLIB_INCLUDE = -L ../thirdparty/zLibThd/linux/TEMP_LIB=../../bin/GateLIBS = -lCommon -lExtralib -lprotobuf -ljsoncpp -lhpsocket -lrt -lpthreadall:$(TEMP_OBJ)
$(TEMP_LIB):$(TEMP_OBJ)g++ $(LIB_INCLUDE) -o $(TEMP_LIB) $(TEMP_OBJ) $(LIBS)$(MAKE_CACHE)/%.o:%.cppg++ -D__LINUX__ -D_GATE_SERVER_ $(INCLUDE) -std=gnu++0x -O0 -g3 -Wabi -w -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
1、wildcard : 扩展通配符
2、notdir : 去除路径
3、patsubst :替换通配符
去掉window字符 dos2unix
makefile 自定义函数
# 定义一个自定义函数
define my-function@echo "Function called with parameters: $1, $2"
endef# 使用自定义函数
all:$(call my-function, value1, value2)
https://blog.csdn.net/wuyiyu_/article/details/130632466
makefile 替换文件扩展名 patsubst
https://blog.csdn.net/liji_digital/article/details/127430952
makefile 隐藏文件扩展名 basename
https://blog.csdn.net/qianniuwei321/article/details/123488612
linux Makefile 如何将生成的 .o 文件放到指定文件夹
https://www.cnblogs.com/jzcn/p/17012331.html