makefile实验五 make clean rebuild 以及规则中的模式替换. 综合小小实验
makefile代码:
.PHONY : rebuild clean $(TARGET) #声明伪目标时,除直接使用目标名外, 也可以使用 $(变量) 这是取变量的值 CC := g++ TARGET := hello-makefile.out OBJS := func.o main.o $(TARGET) : $(OBJS) $(CC) -o $@ $^ $(OBJS) : %.o : %.c $(CC) -o $@ -c $^ clean : $(RM) $(OBJS) $(RM) $(TARGET) @echo "clean" #.PHONY : rebuild clean $(TARGET) #本代码的伪目标声明在这里,和写在上面实测都是可以的。都可以产生伪目标的效果。
#实测时,以make clean测试,无论本地是否存在clean文件,clean都是伪目标的效果。 rebuild : clean $(TARGET) @echo "rebuild"
测试过程:
root@ubuntu:~/Makefile_Test/5make_test# ls func.c func.o hello-makefile.out main.c main.o makefile root@ubuntu:~/Makefile_Test/5make_test# make clean rm -f func.o main.o rm -f hello-makefile.out clean root@ubuntu:~/Makefile_Test/5make_test# ls func.c main.c makefile root@ubuntu:~/Makefile_Test/5make_test# make g++ -o func.o -c func.c g++ -o main.o -c main.c g++ -o hello-makefile.out func.o main.o root@ubuntu:~/Makefile_Test/5make_test# ls func.c func.o hello-makefile.out main.c main.o makefile root@ubuntu:~/Makefile_Test/5make_test# make rebuild rm -f func.o main.o rm -f hello-makefile.out clean g++ -o func.o -c func.c g++ -o main.o -c main.c g++ -o hello-makefile.out func.o main.o rebuild root@ubuntu:~/Makefile_Test/5make_test# ls func.c func.o hello-makefile.out main.c main.o makefile root@ubuntu:~/Makefile_Test/5make_test#
root@ubuntu:~/Makefile_Test/5make_test# ./hello-makefile.out
hello world
main.c: a = 0
root@ubuntu:~/Makefile_Test/5make_test#
源码:
/************* 社会的有色眼光是:博士生、研究生、本科生、车间工人; 重点大学高材生、普通院校、二流院校、野鸡大学; 年薪百万、五十万、五万; 这些都只是帽子,可以失败千百次,但我和社会都觉得,人只要成功一次,就能换一顶帽子,只是社会看不见你之前的失败的帽子。 当然,换帽子决不是最终目的,走好自己的路就行。 杭州.大话西游 *******/