我的Makefile中有这个:
VERSION=0.10.2
SED=sed
www/Makefile: www/Makefile.in Makefile .$(VERSION)
test -d www && $(SED) -e "s/{{VERSION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true
更新www目录中的Makefile,但我在github上的repo没有那个目录只在我的本地驱动器上,当我在克隆repo后调用它时我发现错误没有制作www / Makefile的规则。在
如果没有www / Makefile.in文件,如何才能使这项工作?
答案 0 :(得分:1)
如果没有www / Makefile.in文件,我怎样才能使这项工作?
要解决类似情况,我使用$(wildcard)
函数。正式地说,该函数用于扩展shell glob通配符,但它也检查文件/目录的可用性。重要提示:如果file / dir不存在,$(wildcard)
将返回空字符串。
例如,如果不存在,请从先决条件列表中删除www/Makefile.in
:
www/Makefile: $(wildcard www/Makefile.in) Makefile .$(VERSION)
test -d www && $(SED) -e "s/{{VERSION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true
或者,如果www
目录不存在,则完全禁用该规则:
ifneq (,$(wildcard www))
www/Makefile: www/Makefile.in Makefile .$(VERSION)
test -d www && $(SED) -e "s/{{VERSION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true
endif