文章目的
记录下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