Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Linux version with Autoconf?

Tags:

linux

autoconf

My program requires at least Linux 2.6.26 (I use timerfd and some other Linux-specific features).

I have an general idea how to write this macro but I don't have enough knowledge about writing test macros for Autoconf. Algorithm:

  1. Run "uname --release" and store output
  2. Parse output and subtract Linux version number (MAJOR.MINOR.MICRO)
  3. Compare version

I don't know how to run command, store output and parse it.

Maybe such macro already exists and it's available (I haven't found any)?

like image 413
Goofy Avatar asked Sep 16 '26 00:09

Goofy


2 Answers

I think you'd be better off detecting the specific functions you need using AC_CHECK_FUNC, rather than a specific kernel version. This will also prevent breakage if you find yourself cross-compiling at some point in the future

like image 105
Hasturkun Avatar answered Sep 19 '26 02:09

Hasturkun


There is a macro for steps 2 (parse) and 3 (compare) version, ax_compare_version. For example:

linux_version=$(uname --release)
AX_COMPARE_VERSION($linux_version, [eq3], [2.6.26],
    [AC_MSG_NOTICE([Ok])],
    [AC_MSG_ERROR([Bad Linux version])])

Here I used eq3 so that if $linux_version contained additional strings, such as -amd64, the comparison still succeeds. There is a plethora of comparison operators available.

like image 44
Ale Avatar answered Sep 19 '26 04:09

Ale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!