FOLDER_NAME = $*
%.clean:
ifeq ($(FOLDER_NAME),cdr)
@ echo " condition passed $(FOLDER_NAME)"
else
@ echo " condition failed $(FOLDER_NAME)"
endif
在此运行make cdr.clean时,我得到以下输出。 条件失败的cdr
无法弄清楚可能出现的问题。
答案 0 :(得分:1)
读取makefile时会计算条件ifeq
。那时$*
评估为空字符串,因此ifeq
看到空FOLDER_NAME
。 $*
仅在以后在运行时评估规则时才有意义。
为了实现您的目标,您可以为不同的情况定义不同的规则(* clean2如下)或使用shell命令来评估条件(* clean3如下)。
FOLDER_NAME = $*
cdr.clean2:
@ echo " condition passed $(FOLDER_NAME)"
%.clean2:
@ echo " condition failed $(FOLDER_NAME)"
%.clean3:
@ if [ $(FOLDER_NAME) == cdr ]; \
then echo " condition passed $(FOLDER_NAME)" ; \
else echo " condition failed $(FOLDER_NAME)"; \
fi