tags:

views:

144

answers:

3

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)?

+3  A: 

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

Hasturkun
This will not work for me, because Linux function accepts flags in functrion timerfd_settime() since version 2.6.26 and I can check this only at runtime.Any other idea?
Goofy
Do you mean it accepts certain flags in 2.6.26 that didn't exist before? you could check for the existence of those flags using `AC_CHECK_DECL`, and if all else fails, you can use `AC_RUN_IFELSE` to compile and run a test program to check for anything else that can really only be tested at run time
Hasturkun
Yes, Linux supports flags in this function since version 2.6.26. AFAIR on older kernels timerfd_settime() faield with EINVAL error, when any flags were used.I will try to use AC_RUN_IFELSE as you suggested.
Goofy
+1  A: 

Without going too deep and write autoconf macros properly (which would be preferable anyway) don't forget that configure.ac is basically a shell script preprocessed by m4. So you can write shell commands directly.

 # prev. part of configure.ac
 if test `uname -r |cut -d. -f1` -lt 2 then; echo "major v. error"; exit 1; fi
 if test `uname -r |cut -d. -f2` -lt 6 then; echo "minor v. error"; exit 1; fi
 if test `uname -r |cut -d. -f3` -lt 26 then; echo "micro error"; exit 1; fi
 # ...

This is just an idea if you want to do it avoiding writing macros for autoconf. This choice is not good, but should work...

The best way is the already suggested one: you should check for features; so, say in a future kernel timerfd is no more available... or changed someway your code is broken... you won't catch it since you test for version.

ShinTakezou
+2  A: 

I would suggest you not to check the Linux version number, but for the specific type you need or function. Who knows, maybe someone decides to backport timerfd_settime() to 2.4.x? So I think AC_CANONICAL_TARGET and AC_CHECK_LIB or similar are your friends. If you need to check the function arguments or test behaviour, you'd better write a simple program and use AC_LANG_CONFTEST([AC_LANG_PROGRAM(...)])/AC_TRY_RUN to do the job.

dma_k