【发布时间】:2017-07-08 00:09:00
【问题描述】:
我正在尝试编写一个configure.ac 文件来完成这些任务:
configure脚本应该接受--with-libuv参数。-
变量
with_libuv应设置为yes、no或check(在命令行上未传递任何内容时,check是默认值)。 当
with_libuv == "yes"时,应该对libuv >= 1.9.0进行强制性PKG_CHECK_MODULES 检查,成功时应设置HAVE_LIBUV = 1(错误时configure应中止)。当
with_libuv == "no"什么都不应该检查时,-
当
with_libuv == "false"应该进行可选的PKG_CHECK_MODULES 检查(针对与3. 中相同的库)并且HAVE_LIBUV应该相应地设置为0或1。 如果
with_libuv != "no" && HAVE_LIBUV == 1AC_DEFINE 应该设置-DUSE_LIBUV并且 AM_CONDITIONAL 应该设置USE_LIBUV作为 automake 的条件。如果不是
with_libuv != "no" && HAVE_LIBUV == 1,则不应设置预处理器指令,并且应将 AM_CONDITIONAL 设置为0。
我已经弄清楚如何执行第 1-5 步,但我正在为第 6 步和第 7 步而苦苦挣扎。
这是我目前的尝试:
AC_INIT(
[mumble-pluginbot-plusplus],
[0.5],
[https://github.com/promi/mumble-pluginbot-plusplus/issues],
[],
[https://github.com/promi/mumble-pluginbot-plusplus])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AM_SILENT_RULES([yes])
AC_PROG_CXX
LT_INIT
# Make sure that pkg-config is installed!
# The PKG_CHECK_MODULES macro prints a horrible error message when
# pkg-config is not installed at autogen time.
#
# It is also required when the first PKG_CHECK_MODULES is inside a conditional
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES(OPUS, [opus >= 1.1])
PKG_CHECK_MODULES(OPENSSL, [openssl])
PKG_CHECK_MODULES(PROTOBUF, [protobuf])
PKG_CHECK_MODULES(MPDCLIENT, [libmpdclient])
AC_ARG_WITH(
[libuv],
[AS_HELP_STRING([--with-libuv], [support efficient MPD status polling @<:@default=check@:>@])],
[],
[with_libuv=check])
# if --with-libuv -> it must be installed
# elseif --without-libuv -> do nothing
# else -> check whether it is installed
AS_CASE(
["$with_libuv"],
[yes], [PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1])],
[no], [],
[PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1], [HAVE_LIBUV=0])])
if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
AM_CONDITIONAL([USE_LIBUV], [1])
AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
else
AM_CONDITIONAL([USE_LIBUV], [0])
fi
#AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
有问题的部分是这样的:
if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
AM_CONDITIONAL([USE_LIBUV], [1])
AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
else
AM_CONDITIONAL([USE_LIBUV], [0])
fi
这是配置输出的摘录:
checking pkg-config is at least version 0.9.0... yes
checking for OPUS... yes
checking for OPENSSL... yes
checking for PROTOBUF... yes
checking for MPDCLIENT... yes
checking for UV... yes
./configure: line 16467: test: x1: integer expression expected
./configure: line 16480: 0: command not found
checking that generated files are newer than configure... done
如何以实际可行的方式实施第 6 步和第 7 步?
【问题讨论】:
标签: sh autotools autoconf automake pkg-config