我想添加几行,以便在某些目录(由Makefile变量DIR1设置)不存在的情况下,make处理过程可能出错。这是添加的部分,但是即使存在DIR1设置的目录,也会出现此错误。例如,我创建了名为“ dir1”的目录,但出错了。怎么了?
DIR1 = dir1
.PHONY : check_dir
$(info DIR1 = $(DIR1))
check_dir:
if [ ! -d $(DIR1) ]; then \
$(error "DIR1 does not exist! check Makefile!"); \
fi
这是运行结果。(我的目录dir1
在当前目录中被调用)。
> ckim@chan-ubuntu:~/testmake/test1$ make
> DIR1 = dir1 Makefile:8:
> *** "DIR1 does not exist! check Makefile!". Stop.
在$(error ...)
有系统地化妆传递配方前壳扩大。因此,每次运行此配方时都会引发错误,而与shellif
语句的结果无关。
仅使用壳结构:
check_dir:
if [ ! -d "$(DIR1)" ]; then \
echo "$(DIR1) does not exist! check Makefile!"; \
exit 1; \
fi
或者(稍微紧凑一点,如果不容易理解的话):
MESSAGE := $(DIR1) does not exist! check Makefile!
check_dir:
@[ -d "$(DIR1)" ] || { echo "$(MESSAGE)"; exit 1; }
还有其他可能性,例如:
check_dir: $(DIR1)
$(DIR1):
$(error $(DIR1) does not exist! check Makefile!)
但是,这在命名文件$(DIR1)
和目录之间没有区别。
注意:如果要在make解析Makefile并发现目录不存在时引发错误,则可以使用该shell
函数和make条件:
OK := $(shell if [ -d $(DIR1) ]; then echo "ok"; fi)
ifeq ($(OK),)
$(error $(DIR1) does not exist! check Makefile!)
endif
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句