Linux 如何将可选文件添加到Makefile

Linux 如何将可选文件添加到Makefile,linux,makefile,Linux,Makefile,我的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没有该目录,它只在我的本地驱

我的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.in的规则

当文件中没有www/Makefile.in时,如何使此工作正常

当文件中没有www/Makefile.in时,如何使此工作正常

为了解决类似的情况,我使用了
$(通配符)
函数。正式来说,该函数用于扩展shell glob通配符,但它也检查文件/目录的可用性。重要提示:如果文件/dir不存在,
$(通配符)
将返回空字符串

例如,从prereq列表中删除
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
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
或者,如果
www
目录不存在,则完全禁用该规则:

www/Makefile: $(wildcard www/Makefile.in) Makefile .$(VERSION)
    test -d www && $(SED) -e "s/{{VERSION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true
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
当文件中没有www/Makefile.in时,如何使此工作正常

为了解决类似的情况,我使用了
$(通配符)
函数。正式来说,该函数用于扩展shell glob通配符,但它也检查文件/目录的可用性。重要提示:如果文件/dir不存在,
$(通配符)
将返回空字符串

例如,从prereq列表中删除
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
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
或者,如果
www
目录不存在,则完全禁用该规则:

www/Makefile: $(wildcard www/Makefile.in) Makefile .$(VERSION)
    test -d www && $(SED) -e "s/{{VERSION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true
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

也许我误解了这个问题,但是如果没有
www/Makiefile.in
?@Beta,请忽略这个事实并继续。也许我误解了这个问题,但是,如果没有
www/Makiefile,你想怎么做呢?@Beta忽略这个事实并继续。第一个解决方案有效,第二个抛出错误,即如果缺少www,则www/Makefile没有规则。如果第二个不起作用,这意味着你在某个地方依赖
www/Makefile
。您还可以尝试删除/使依赖项成为可选的,例如,
$(如果$(通配符www),www/Makefile)
。祝你好运。第一个解决方案有效第二个抛出错误,即如果缺少www,则www/Makefile没有规则。如果第二个解决方案无效,则意味着您在某个地方依赖于
www/Makefile
。您还可以尝试删除/使依赖项成为可选的,例如,
$(如果$(通配符www),www/Makefile)
。祝你好运