makefile - 检查变量是其中之一

标签 makefile

在我的项目的 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/

相关文章:

c++ - CMake 外壳查找

c++ - Makefile 中的 "Optional"目标文件目标?

c++ - 如何检查 makefile 中已定义符号(Eclipse-> 路径和符号)的值?

makefile - 如何检查 Makefile 中是否存在文件以便将其删除?

c++ - nginx rtmp compile for windows error U1052 & rtmp-module-master/config not found

我们可以在 make 中运行一个 python 脚本来生成一些 .c 和 .h 文件,然后构建一个镜像吗?

c++11 - SIGINT 未在此范围内声明

linux - 要求用户从 root 模式运行 makefile

c - GDB 看不到除 main 之外的源文件,这是由 makefile 引起的吗?

c++ - CMake 没有创建可以访问我的共享库的可执行文件