makefile使用MAKEFILE_LIST获取inlcude文件所在的目录

文章目的

记录下MAKEFILE_LIST的获取目录的使用技巧

测试目录

|----Makefile
|----test01
		|----test.txt
		|----001
			  |----test.txt
|----test02
		|----test.txt
		|----002
			  |----test.txt

makefile 文件

#inlcue获取路径技
pkgdir       = $(dir $(lastword $(MAKEFILE_LIST)))
pkgname      = $(lastword $(subst /, ,$(pkgdir)))

include test01/test.txt
$(info "$(MAKEFILE_LIST)")
include test01/001/test.txt
$(info "$(MAKEFILE_LIST)")
include test02/test.txt
$(info "$(MAKEFILE_LIST)")
include test02/002/test.txt
$(info "$(MAKEFILE_LIST)")
all:
	@echo "....all"
	@echo "all:$(pkgname)"
	
#目标的依赖可以拆分,但只能有一个跟命令,如果有多处跟命令,只有最后一个起作用
tag3:a.c 
tag3:c.c
tag3:b.c
tag3:
	@echo "$@:$^"

test.txt文件

$(info "test:pkgname:$(pkgname)")

输出结果

执行make的输出结果:
"test:pkgname:test01"
" Makefile test01/test.txt"
"test:pkgname:001"
" Makefile test01/test.txt test01/001/test.txt"
"test:pkgname:test02"
" Makefile test01/test.txt test01/001/test.txt test02/test.txt"
"test:pkgname:002"
" Makefile test01/test.txt test01/001/test.txt test02/test.txt test02/002/test.txt"
....all
all:002
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值