Makefile模板

CFLAGS = -g -Wall
INCLUDE = -I/home/CStudy/DateStru/include
IDLIBS = -lpthread
CC = gcc
TARGET = program
SOURCE = $(wildcard *.c /home/CStudy/DateStru/src/pub/*.c)
#DIR = $(notdir $SOURCE)                --notdir把展开的文件去掉路径
#OBJS = $(patsubst %.c,%.o,$(DIR))      --patsubst把$(DIR)符合后缀.c的都替换为.o
OBJECTS = $(SOURCE:.c=.o)

.PHONY:all clean
all:$(TARGET)

%.o:%.c
    $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<

$(TARGET):$(OBJECTS)
    $(CC) $^ -o $@

clean:
    -rm $(OBJECTS)
    -rm $(TARGET)
 

你可能感兴趣的:(Linux,C语言)