Makefile指定目标文件和可执行文件存放的目录

    xiaoxiao2022-07-02  125

    INC = -I../include LIB = -L../lib -lsqlite3 CFLAGS = -lgcc -pthread -ldl DIR_OBJS = ../obj DIR_BIN = ../bin dirs := $(DIR_OBJS) $(DIR_BIN) bin = server src = $(wildcard *.c) obj = $(patsubst %.c,%.o,$(src)) #patsubst模式字符替换函数 #obj = $(src:.c=.o) obj := $(addprefix $(DIR_OBJS)/,$(obj)) bin := $(addprefix $(DIR_BIN)/,$(bin)) #$@ 目标(自动变量) #$^ 依赖 all: $(dirs) $(bin) $(dirs): mkdir $@ $(bin):$(obj) gcc $^ -o $@ $(CFLAGS) $(INC) $(LIB) $(DIR_OBJS)/%.o:%.c gcc $^ -o $@ -c $(CFLAGS) $(INC) $(LIB) clean: rm -rf $(dirs) $(bin) .PHONY:all clean

     

    最新回复(0)