linux - 在 Makefile 中使用条件运算符比较两个变量
问题描述
下面是我的 Makefile。我只想使用 && 运算符(或其等价物)进行比较,如以下伪代码所示。我想在“all”目标中运行以下逻辑
# if (CUR_PI_VERSION == LAST_PI_VERSION) && (CUR_GIT_VERSION == LAST_GIT_VERSION)
# print "everything matched. Nothing to do"
# else
# print "files not matched"
# run python script.
#
# How do I achieve this.
我已经查看了其他答案,但我无法得到我希望的结果。我附上了我的示例代码以供参考。
CUR_PI_VERSION:= "abc"
CUR_GIT_VERSION:= "cde"
LAST_PI_VERSION:= "abc"
LAST_GIT_VERSION:= "cde"
$(info $$CUR_GIT_VERSION is [${CUR_GIT_VERSION}])
$(info $$CUR_PI_VERSION is [${CUR_PI_VERSION}])
$(info $$LAST_GIT_VERSION is [${LAST_GIT_VERSION}])
$(info $$LAST_PI_VERSION is [${LAST_PI_VERSION}])
all:
# The pseudocode of what I want to do is as follows
# if (CUR_PI_VERSION == LAST_PI_VERSION) && (CUR_GIT_VERSION == LAST_GIT_VERSION)
# print "everything matched. Nothing to do"
# else
# print "files not matched"
# run python script.
#
# How do I achieve this.
#
ifeq ($(CUR_GIT_VERSION),$(LAST_GIT_VERSION))
ifeq ($(CUR_FPI_VERSION),$(LAST_FPI_VERSION))
echo "Everything matched, so don't need the make top"
endif
endif
非常感谢任何帮助。
解决方案
你可以试试这个:
all:
ifeq ($(CUR_PI_VERSION)@$(CUR_GIT_VERSION),$(LAST_PI_VERSION)@$(LAST_GIT_VERSION))
echo "Everything matched, so don't need the make top"
endif
上面的测试比较了两个连接的字符串(由 连接@
):
$(CUR_PI_VERSION)@$(CUR_GIT_VERSION)
和
$(LAST_PI_VERSION)@$(LAST_GIT_VERSION)
推荐阅读
- charts - 谷歌图表,y轴未排序,无法修复
- functional-programming - 如何在 OCaml 中进行函数覆盖?
- c++ - 滑动窗口最大值问题中的分段错误
- java - 在 Eclipse 项目中哪里可以找到文件
- node.js - 找不到入口模块中的错误:错误:无法解析“./src”
- android - Android 应用程序在安装 @react-native-firebase/messaging (v6) 时崩溃
- ocaml - 字符串 printf 的 Ocaml 循环
- vba - 为什么访问 Vb 代码中的这段代码给了我语法错误编译器错误
- java - 开发 Minecraft 插件时遇到问题
- c# - 我想将 XERO 集成到 WebAPI C# 有人可以为我提供 oauth2 的示例代码吗