gpt4 book ai didi

用于检查所需的最低 Linux 内核版本的 Linux makefile

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:07:39 28 4
gpt4 key购买 nike

我有一个需要在 2 个不同内核版本上编译的 linux makefile。 makefile 不是从 automake/autoconf 生成的。

C 代码已经使用宏进行条件化以针对不同的内核版本生成不同的代码,但是 makefile 中的某些功能也需要进行条件化。

在 makefile 中有没有办法做:

if (kernel_version > 2.6.30)
newer_kernel = 1
else
newer_kernel = 0
endif

最佳答案

好吧,我可以想出一种使用 bash 的快速方法:

KERNEL_VERSION=`uname -r`
HIGHER_VERSION=`echo -e "$KERNEL_VERSION\n2.6.30" | sort -g -t '.' | tail --lines=1`
if [ "$HIGHER_VERSION" == "2.6.30" ]
# its an older kernel
else
# its a newer kernel
fi

基本上,您使用 uname 获取当前内核的版本,然后使用 sort 将其与 2.6.30 进行比较(-g 标志启用数字排序,-t '.' 表示使用点作为字段分隔符),然后使用 tail 来确定列表中两个版本中哪个更高。不完全是一个漂亮的解决方案,但它会起作用。

您可以将其放入单独的脚本或直接放入 makefile 配方

关于用于检查所需的最低 Linux 内核版本的 Linux makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11143749/

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