目标文件,依赖关系,命令。
依赖关系更新了就要重新编译。
命令必须以tab键开头。
objects = $(wildcard *.o)
objects = *.o
前者的wildcard是关键字,表示匹配所有.o的文件。
文件搜索
VPATH变量
VPATH = src:./headers
vpath <pattern>;<directories>;
如:
vpath %.c foo
vpath & blish
vpath %.c bar
伪目标
.PHONY :clean
clean:
rm *.o temp
看下面这个makefile,
gcc -o ***
gcc *** -o -c ***
CC=gcc
CFLAGS=-g -Wall -O2 //表示带有调试信息
EXECUTABLE=hello
SRCS=$(wildcard *.c)
OBJS=$(patsubst %.c,%.o,$(SRCS))
.PHONY: clean target all strip welldone revlist load touch
all:clean target
target:touch $(EXECUTABLE)
clean:
rm -f $(EXECUTABLE)
strip: target
strip --strip-all $(EXECUTABLE)
touch:
find . -name "*" -print | xargs touch
$(EXECUTABLE):$(OBJS)
$(CC) $(CFLAGS) -o $(EXECUTABLE) $^ //表示所有的依赖目标
%o:%c
$(CC) $(CFLAGS) -c -D__KERNEL__ $< -o $@ //$<表示依赖目标中的第一个,如果是用%表示的,就表示一个一个的, $@表示所有的目标。
//注意这个makefile中的互相依赖关系
//注意其中的一些命令,strip --strip-all
//注意其每次都更新时间戳, touch