多级makefile嵌套执行时上层makefile中定义变量并不能影响下层makefile的执行(除非设置环境变量)
如分别在目录/home/zsli/test及/home/zsli/test/sub_test中创建文件Makefile_t及Makefile,内容如下:
CUR_DIR = $(shell pwd)
.PHONY: all;
all:
@echo $(ZSLI_TEST)
@$(MAKE) -C $(CUR_DIR)/sub_test/
ZSLI_TEST:= "test"
.PHONY: all;
all:
@echo $(ZSLI_TEST)
执行
make -f Makefile_t
得到
test
make[1]: Entering directory `/home/mumu/test/sub_test'
make[1]: Leaving directory `/home/mumu/test/sub_test'
若需嵌套子makefile可使用上传makefile中定义变量,可将该变量定义为环境变量(export)