Makefile5--预定义变量的使用

学习自狄泰软件学院唐佐临老师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)"

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Linux老A

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值