如何从autoconf脚本configure.ac内部检查程序的版本

问题描述 投票:0回答:1

我花了半天的时间来弄清楚我的问题是否可行。有一个MACRO用于检查程序的可用性。例如R:

AC_PATH_PROG([R], [R], [nor])

是否有检查R版本的标准方法?例如,我试图基于R 3.6.x建立我的项目。这个问题可能适用于您喜欢的任何程序。我可以用shell脚本找到:

R --version | grep "R version" | cut -d ' ' -f 3

上面的snipit将返回R的版本。假定我可以在configure.ac中以某种方式获得此信息,那么如何确保rversion> 3.5。是ax_compare_version的路要走吗?以下是我的测试段。有点不对劲。我的一般问题是:我做这种可接受的做法的方式(忽略下面显示的小逻辑错误)吗?

AC_PATH_PROG([R], [R], [nor])
if test "$R" = nor; then
   AC_MSG_ERROR([No R installed in this system])
fi
RVERSION=`$R --version | grep "R version" | cut -d ' ' -f 3`
AX_COMPARE_VERSION([RVERSION], [ge], [3.6.0], AC_MSG_NOTICE([R $RVERSION good]), AC_MSG_ERROR([R $RVERSION too low]))

 checking for R... /usr/local/bin/R
 configure: error: R 3.6.3 too low
r autoconf
1个回答
1
投票

当然。一般的想法是将其转换成可以由shell脚本评估的表达式,或者可以从`configure运行的东西。以下是三种不同的方法。

第一个是我们对g++程序包中RQuantLib configure.ac进行了多年的一些基本测试(是的,我们对g++-3.*进行测试的很多年...)。这里的主要要旨是通配符比较

AC_PROG_CXX
if test "${GXX}" = yes; then
    gxx_version=`${CXX} -v 2>&1 | grep "^.*g.. version" | \\
               sed -e 's/^.*g.. version *//'`
    case ${gxx_version} in
        1.*|2.*)
         AC_MSG_WARN([Only g++ version 3.0 or greater can be used with RQuantib.])
         AC_MSG_ERROR([Please use a different compiler.])
        ;;
    4.6.*|4.7.*|4.8.*|4.9.*|5.*|6.*|7.*|8.*|9.*|10.*)
         gxx_newer_than_45="-fpermissive"
    ;;
    esac
fi

这里是RProtoBuf的另一个版本,我们在其中进行编译以使版本冒充为真/假表达式:

## also check for minimum version
AC_MSG_CHECKING([if ProtoBuf version >= 2.2.0])
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <google/protobuf/stubs/common.h>
int main() {
   if (GOOGLE_PROTOBUF_VERSION >= 2001000) {
        exit (0);
   } else {
        exit(1);
   }
}
]])],
[pb_version_ok=yes],
[pb_version_ok=no],
[pb_version_ok=yes])
if test x"${pb_version_ok}" == x"no"; then
    AC_MSG_ERROR([Need ProtoBuf version >= 2.2.0])
else
    AC_MSG_RESULT([yes])
fi

而且我想我最近在R中将其设为package_version对象,以便可以进行比较-这是RcppRedis中的对象-这又回到了配置为true / false的位置。

## look for (optional !!) MsgPack headers
## RcppMsgPack on CRAN fits the bill -- but is a soft dependency
AC_MSG_CHECKING([for RcppMsgPack])
## Check if R has RcppMsgPack
$("${R_HOME}/bin/Rscript" --vanilla -e 'hasPkg <- "RcppMsgPack" %in% rownames(installed.packages()); q(save="no", status=if (hasPkg) packageVersion("RcppMsgPack") >= "0.2.0" else FALSE)')
if test x"$?" == x"1"; then
    AC_MSG_RESULT([yes])
    msgpackincdir=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(system.file("include", package="RcppMsgPack"))')
    msgpack_cxxflags="-I${msgpackincdir} -DHAVE_MSGPACK"
    AC_MSG_NOTICE([Found RcppMsgPack, using '${msgpack_cxxflags}'])
else
    AC_MSG_RESULT([no])
    AC_MSG_NOTICE([Install (optional) RcppMsgPack (>= 0.2.0) from CRAN via 'install.packages("RcppMsgPack")'])
fi  

我希望这能给您一些想法。

© www.soinside.com 2019 - 2024. All rights reserved.