Makefile中的版本号比较 [英] Version number comparison inside makefile

查看:422
本文介绍了Makefile中的版本号比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在makefile中,我想定义一个变量,该变量指定当前的redhat-release是否大于5.3. (此变量将作为#define传递给gcc)

In a makefile, I'd like to define a variable specifying whether the current redhat-release is greater than 5.3. (This variable will be passed to gcc as a #define)

到目前为止,我已经提出了:

So far I've come up with:

# Find out which version of Red-Hat we're running
RH_VER_NUM = $(shell /bin/grep -o [0-9].[0-9] /etc/redhat-release)
RH_GT_5_3 = $RH_VER_NUM > '5.3'

定义RH_GT_5_3的正确方法是什么?

What would be the correct way to define RH_GT_5_3?

推荐答案

GNU Make除了相等性之外不包含任何字符串比较,并且test只能对整数进行小于/大于测试.将版本号拆分为不可分割的部分,然后进行比较.试试这个(还要注意,这里的:==好,因为make的惰性求值会比您的$(shell)命令调用次数更多:

GNU Make doesn't contain any string comparisons other than equality, and test can only do less-than/greater-than tests on integers. Split the version number into its integral parts and do the comparison that way. Try this (note also that := is better than = here, as make's lazy evaluation would call your $(shell) commands many more times than required:

RH_VER_MAJOR := $(shell echo $(RH_VER_NUM) | cut -f1 -d.)
RH_VER_MINOR := $(shell echo $(RH_VER_NUM) | cut -f2 -d.)
RH_GT_5_3 := $(shell [ $(RH_VER_MAJOR) -gt 5 -o \( $(RH_VER_MAJOR) -eq 5 -a $(RH_VER_MINOR) -ge 3 \) ] && echo true)

ifeq ($(RH_GT_5_3),true)
CPPFLAGS += -DRH_GT_5_3=1
endif

这篇关于Makefile中的版本号比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆