在我的项目的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
太累了..有没有办法让它更简单?
答案 0 :(得分:10)
@ keltar的答案有效,但findstring
并不是最好的选择,因为它甚至可以成功获得子串。更好的是使用filter
,这是完全匹配的词:
GOALS := rebuild rerun distclean clean mostlyclean dep-clean tools tools-clean
ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
include $(DEPENDENCIES)
endif
答案 1 :(得分:1)
你可以使用类似的东西
GOALS:=rebuild rerun distclean clean mostlyclean dep-clean tools tools-clean
ifneq ($(findstring $(MAKECMDGOALS), $(GOALS)),)
include $(DEPENDENCIES)
endif
但如果您一次指定多个目标(例如make clean distclean
),则会出现问题。
但是,你首先需要它吗?为什么不使用-include
代替,包含文件但不会失败,即使它不能?