【问题标题】:Add prerequisite on condition根据条件添加先决条件
【发布时间】:2013-05-01 08:46:29
【问题描述】:
如果在工作区中找到另一个文件,是否可以添加先决条件?或者我还能如何实现以下想法?基本上,如果我的工作区在特定位置有一个 lcf 文件,我需要制作另一个文件。像这样的东西:
lcf := ../base_sw/lcf/base.lcf
.PHONY :
all : $(objects)
# if $(lcf) file exists then
all : $(objects) sup.a2l
sup.a2l :
# Perl script runs here to produce sup.a2l
@echo Chris > $@
【问题讨论】:
标签:
makefile
prerequisites
【解决方案1】:
应该这样做:
lcf := $(wildcard ../base_sw/lcf/base.lcf)
.PHONY :
all : $(objects) $(lcf)
【解决方案2】:
认为我自己已经设法回答了这个问题!
如果 lcf 文件不存在,通配符函数不返回任何内容:
lcf := $(wildcard ../base_sw/lcf/base.lcf)
开始构建需要制作的文件:
make_these_file := $(obejcts)
如果 lcf 变量不为空,则追加到文件列表:
ifneq ($(lcf),)
make_these_file += sup.a2l
endif
现在我们的目标是制作所需的文件:
.PHONY :
all : $(make_these_file)
sup.a2l :
# Perl script here to produce sup.a2l
@echo Chris > $@
为我工作:)