在我的项目的 makefile 中,有与此类似的代码:
ifneq ($(MAKECMDGOALS), rebuild)
ifneq ($(MAKECMDGOALS), rerun)
ifneq ($(MAKECMDGOALS), distclean)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), mostlyclean)
ifneq ($(MAKECMDGOALS), dep-clean)
ifneq ($(MAKECMDGOALS), tools)
ifneq ($(MAKECMDGOALS), tools-clean)
include $(DEPENDENCIES)
endif
endif
endif
endif
endif
endif
endif
endif
太累了。。有什么办法可以简单点?
最佳答案
@keltar 的答案有效,但 findstring
并不是真正的最佳选择,因为它甚至对子字符串也能成功。更好的是使用 filter
它是精确的单词匹配:
GOALS := rebuild rerun distclean clean mostlyclean dep-clean tools tools-clean
ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
include $(DEPENDENCIES)
endif
关于makefile - 检查变量是其中之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24802528/