如果存在文件,我想添加要构建的目标。如果文件不存在,我希望跳过目标。
一个例子:
FILENAME = f
TARGETS := normal
ifneq($(shell stat test_$(FILENAME).c), "")
TARGETS += test
endif
all: $(TARGETS)
normal:
@echo normal
test:
@echo test
我不确定$(shell stat ...)
部分是否有效,但更大的问题是make
当前文件夹中的任何文件test_f.c
都会给出:
Makefile:4: *** multiple target patterns. Stop.
删除ifneq ... endif
块会使目标normal
成为目标test
。如果test_f.c
存在,我该如何才能运行目标 .bootstrap-select.btn-group .dropdown-menu li a:hover {
color: whitesmoke !important;
background: #bf5279 !important;
}
答案 0 :(得分:1)
你可以做的是生成一个字符串变量(让我们称之为OPTIONAL
),这样当'test_f.c'存在时,OPTIONAL=test
;否则,OPTIONAL=_nothing_
。然后添加OPTIONAL
作为all
的先决条件。 e.g:
FILENAME = f
TARGETS = normal
OPTIONAL = $(if $(wildcard test_f.c), test, )
all: $(TARGETS) $(OPTIONAL)
normal:
@echo normal
test:
@echo test
答案 1 :(得分:1)
您还可以使用for循环
迭代目标.PHONY: all
RECIPES = one
all: RECIPES += $(if $(wildcard test_f.c), two, )
all:
for RECIPE in ${RECIPES} ; do \
$(MAKE) $${RECIPE} ; \
done
one:
$(warning "One")
two:
$(warning "Two")
> make
for RECIPE in one ; do \
/Applications/Xcode.app/Contents/Developer/usr/bin/make ${RECIPE} ; \
done
makefile:11: "One"
make[1]: `one' is up to date.
> touch test_f.c
> make
for RECIPE in one two ; do \
/Applications/Xcode.app/Contents/Developer/usr/bin/make ${RECIPE} ; \
done
makefile:11: "One"
make[1]: `one' is up to date.
makefile:14: "Two"
make[1]: `two' is up to date.