gpt4 book ai didi

makefile - makefile 内的版本号比较

转载 作者:行者123 更新时间:2023-12-02 15:14:31 25 4
gpt4 key购买 nike

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

到目前为止我想出了:

# 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 的正确方法是什么?

最佳答案

GNU Make 不包含除相等之外的任何字符串比较,并且 test 只能对整数进行小于/大于测试。将版本号拆分为各个组成部分并以这种方式进行比较。试试这个(另请注意,这里 :== 更好,因为 make 的惰性求值会多次调用您的 $(shell) 命令超出要求:

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 - makefile 内的版本号比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3728372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com