#include "stdio.h"
int main()
{
printf("LINE: %d\n", __LINE__);
return 0;
}
#第一个makefile脚本
#(命令开头是一个Tab不然报错:*** missing separator. Stop.)
#没有逗号,加逗号不打印$(info,"begin compile")
#首先执行没有缩进的行
A = 1000
B = "BBB"
$(info A = $(A))
$(info B: $(B))
$(info PWD: $(PWD))
$(info "begin compile")
$(warning "begin compile")
#在make时没有指定编译哪个,会默认编译默认目标。
#一般Makefile中第一个定义的目标就是默认目标
#因此把最终要生成的目标(hello)写在最前面
#这里 make <==> make hello
#若仅仅生成hello.o,不生成hello可执行文件,make hello.o
#若仅仅清理之前的编译内容, make clean
hello: hello.o
cc hello.o -o hello
$(warning "linking")
hello.o: hello.c
gcc -c hello.c -o hello.o
$(warning "compiling")
$(warning "begin compile")
clean:
rm -rf hello.o hello
$(info "!!!! clean !!!!")
$(warning "begin compile")
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ reset
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
makefile:22: "linking"
cc hello.o -o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello hello.c hello.o makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make clean
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
"!!!! clean !!!!"
rm -rf hello.o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make hello
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
makefile:22: "linking"
cc hello.o -o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello hello.c hello.o makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make clean
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
"!!!! clean !!!!"
rm -rf hello.o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make hello.o
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c hello.o makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$