学习自狄泰软件学院唐佐临老师Makefile课程,文章中图片取自老师的PPT,仅用于个人笔记。
实验1
.PHONY : all first second third
all : first second third
@echo "\$$@ => $@"
@echo "$$^ => $^"
@echo "$$< => $<"
firtst:
second:
third:
@ubuntu:~/work/makefile1$
mhr@ubuntu:~/work/makefile1$ make all
$@ => all
$^ => first second third
$< => first
mhr@ubuntu:~/work/makefile1$
实验2 : 自动变量的使用 可以快速方便的添加新的依赖
CC := g++
TARGET := hello-world.out
$(TARGET) : func.o main.o
$(CC) -o $@ $^
func.o : func.c
$(CC) -o $@ -c $^
main.o : main.c
$(CC) -o $@ -c $^
.PHONY : rebuild clean all
rebuild : clean all
all : $(TARGET)
clean :
$(RM) *.o $(TARGET)
mhr@ubuntu:~/work/makefile1$ make all
g++ -o func.o -c func.c
g++ -o main.o -c main.c
g++ -o hello-world.out func.o main.o
mhr@ubuntu:~/work/makefile1$
实验3
.PHONY : all out
all out :
@echo "$(MAKE)"
@echo "$(MAKECMDGOALS)"
@echo "$(MAKEFILE_LIST)"
mhr@ubuntu:~/work/makefile1$ make
make // 当前解释器所对应的文件名就是 make
//make 这个应用程序的命令行参数 为空 没有带目标名
makefile //空格 + 当前makefile
mhr@ubuntu:~/work/makefile1$
mhr@ubuntu:~/work/makefile1$ make all //携带了目标名(make这个应用程序的命令行参数)
make // 当前解释器所对应的文件名就是 make
all //make 这个应用程序的命令行参数 目标名 all
makefile //空格 + 当前makefile
mhr@ubuntu:~/work/makefile1$
mhr@ubuntu:~/work/makefile1$ make all out //让 make 执行两个目标
make //先执行 all 目标
all out
makefile
make //再执行 out 目标
all out
makefile
mhr@ubuntu:~/work/makefile1$
实验4
.PHONY : all out first second third test
all out :
@echo "$(MAKE)"
@echo "$(MAKECMDGOALS)"
@echo "$(MAKEFILE_LIST)"
first :
@echo "first"
second :
@echo "second"
third :
@echo "third"
test :
$(MAKE) first
$(MAKE) second
$(MAKE) third
mhr@ubuntu:~/work/makefile1$ make test
make first
make[1]: Entering directory '/home/mhr/work/makefile1'
first
make[1]: Leaving directory '/home/mhr/work/makefile1'
make second
make[1]: Entering directory '/home/mhr/work/makefile1'
second
make[1]: Leaving directory '/home/mhr/work/makefile1'
make third
.PHONY : all out first second third test
all out :
@echo "$(MAKE)"
@echo "$(MAKECMDGOALS)"
@echo "$(MAKEFILE_LIST)"
first :
@echo "first"
second :
@echo "second"
third :
@echo "third"
test :
@$(MAKE) first
@$(MAKE) second
@$(MAKE) third
mhr@ubuntu:~/work/makefile1$ make test
make[1]: Entering directory '/home/mhr/work/makefile1'
first
make[1]: Leaving directory '/home/mhr/work/makefile1'
make[1]: Entering directory '/home/mhr/work/makefile1'
second
make[1]: Leaving directory '/home/mhr/work/makefile1'
make[1]: Entering directory '/home/mhr/work/makefile1'
third
make[1]: Leaving directory '/home/mhr/work/makefile1'
mhr@ubuntu:~/work/makefile1$
实验5
.PHONY : test1
test1 :
@echo "$(MAKE_VERSION)"
@echo "$(CURDIR)"
@echo "$(.VARIABLES)"
.PHONY : test1
TDelphi := Delphi Tang
D.T.Software := D.T.
test1 :
@echo "$(MAKE_VERSION)"
@echo "$(CURDIR)"
@echo "$(.VARIABLES)"