Reputation: 131
I want to test the version of some package (e.g PCRE) in a configure.in script, and define C++ variables in a Makefile accordingly. I thought that the autoconf function m4_version_compare would do the trick, but I can't get it to work. I am sure I am not using it correctly. I have the following in configure.in:
AC_INIT([MyPackage], 0.4)
# Checks for common programs using default macros
AC_PROG_CC
PCREVERSION=`pcre-config --version`
AC_MSG_RESULT([Detected PCRE version ${PCREVERSION}])
PCRE_POST_8_0=m4_version_compare([PCREVERSION], [8.0])
AC_MSG_RESULT([PCRE version >= 8.0: ${PCRE_POST_8_0}])
AC_SUBST(PCRE_POST_8_0)
AC_OUTPUT(src/Makevars)
then autoconf + ./configure produces the following output:
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
Detected PCRE version 8.12
PCRE version >= 8.0: -1
configure: creating ./config.status
config.status: creating src/Makevars
What am I doing wrong? It seems that m4_version_compare sees the variable PCREVERSION as being 0. Should I define this variable in another way? How? Thank you.
Renaud
Upvotes: 1
Views: 330
Reputation: 131
I got this working using AS_VERSION_COMPARE, which is run at runtime (unlike m4_version_compare, as pointed out by adl). So the code I eventually use for achieving this is:
AC_INIT([MyPackage], 0.4)
# Checks for common programs using default macros
AC_PROG_CC
PCREVERSION=`pcre-config --version`
CMPV="8.0"
AC_MSG_CHECKING([is PCRE version >= ${CMPV}])
AS_VERSION_COMPARE(${PCREVERSION}, ${CMPV}, [PCRE_POST_8_0=-1], [PCRE_POST_8_0=0],[PCRE_POST_8_0=1])
AS_IF([test "${PCRE_POST_8_0}" != "-1"], AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]))
AC_SUBST(PCRE_POST_8_0)
AC_OUTPUT(src/Makevars)
I think it is nice because it is generic and will work with any program that provides a command to retrieve its version. But I will keep in mind adl's trick for the case where the version is not directly accessible from the shell. Thanks!
Upvotes: 2
Reputation: 16054
You cannot use m4_version_compare
to compare version numbers found at configure
-time.
The m4_version_compare
macro takes two strings that must be known at the time autoconf
runs to build the configure
script. Here you are comparing the string PCREVERSION
to the string 8.0
, and the former is reported to be lesser than the latter.
What you would like to use is in fact the value of the shell variable named PCREVERSION
, i.e., $PCREVERSION
, unfortunately this value is only known when ./configure
runs, so that won't work.
You should make your own comparison using the shell or some other means. Personaly I would rely on AC_PREPROC_IFELSE
to let the preprocessor do two tests at once: make sure the pcre.h
file exists and that it is recent enough. Something like this might work (untested):
AC_PREPROC_IFELSE(
[AC_LANG_PROGRAM([[#include "pcre.h"
#if PCRE_MAJOR < 8
#error out of date
#endif]], [[]])],
[pcre8available=yes],
[pcre8available=no])
Upvotes: 3