make
是一条指令
Makefile
是一个文件
hello.c文件
1 #include<stdio.h>
2
3 int main()
4 {
5 printf("hello Makefile!\n");
6 return 0;
7 }
Makefile文件
1 hello:hello.o
2 gcc hello.o -o hello
3 ello.o:hello.s
4 gcc -c hello.s -o hello.o
5 hello.s:hello.i
6 gcc -S hello.i -o hello.s
7 hello.i:hello.c
8 gcc -E hello.c -o hello.i
9 .PHONY:clean
10 clean:
11 rm -f hello.i hello.s hello.o hello
执行
[admin@bogon code]$ make
cc -c -o hello.o hello.c
gcc hello.o -o hello
[admin@bogon code]$ make
make: `hello' is up to date.
[admin@bogon code]$ clean
bash: clean: command not found
[admin@bogon code]$ make clean
rm -f hello.i hello.s hello.o hello
[admin@bogon code]$ make clean
rm -f hello.i hello.s hello.o hello
make不是总能执行的,它和文件的修改时间有关,
make clean 总能执行是因为用.PHONY 修饰了
.PHONY
修饰之后就变成了伪目标
特征:总是被执行
Makefile文件
1 hello:hello.c
2 gcc hello.c -o hello
3 .PHONY:clean
4 clean:
5 rm -f hello.i hello.s hello.o hello