Makefile模板
CC = gcc LD = gcc CFLAGS = -Wall -c LDFLAGS = SRC_DIRS = src test INC_DIRS = inc OBJ_DIR = obj OUT_DIR = out SRCS = $(foreach DIR, ${SRC_DIRS}, $(wildcard ${DIR}/*.c)) INCS = $(addprefix -I, ${INC_DIRS}) OBJS = $(patsubst %.c, ${OBJ_DIR}/%.o, ${SRCS}) DEPS = $(patsubst ${OBJ_DIR}/%.o, ${OBJ_DIR}/%.dep, ${OBJS}) VPATH = ${SRC_DIRS} OUT = ${OUT_DIR}/mk_test .PHONY: all clean run all: ${OUT} ${OUT}: ${OBJS} ${LD} ${LDFLAGS} -o $@ ${OBJS} ${OBJ_DIR}/%.o: %.c $(shell if test ! -d $(dir $@); then mkdir -p $(dir $@); fi) ${CC} ${CFLAGS} ${INCS} -MMD -MP -MF$(@:%.o=%.dep) -MT$@ -o $@ $< clean: rm -f ${OUT} ${OBJS} ${DEPS} run: @${OUT} -include ${DEPS}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步