(1) 宏(变量)
CC=gcc
$(CC) test.c
$@: current target
$<:first prerequisite
$^:all prerequisites
(2) 后缀规则(suffix rules)
.c.o:
$(CC) -c $(CFLAGS) -o $@ $<
(3) 模式规则(pattern rules)
%.o:%.c
$(CC) -c $(CFLAGS) -o $@ $<
(4) 通配符*
objects = *.o
objects := $(wildcard *.o)
objects := $(patsubst %.c,%.o,$(wildcard *.c))
foo : $(objects)
cc -o foo $(objects)
(5) phony target(哑/假目标):不对应实际的文件,只是一个目标
.PHONY: clean #如果这行不加,若当前目录下有一个clean文件,则make clean 没有动作
clean: #这是phony target
rm *.o temp