mysql不同linux下的安装路径不大相同,直接中包括,不同的版本下编译比较麻烦,装mysql也N种方法,还有x86和x64版本同时装的,搞得很混乱,参考了一下别人的检测做法,目前发现两种: 1. 装了mysql开发库之后(你Yum,build from source, emerge 等等),会顺便
mysql不同linux下的安装路径不大相同,直接中包括,不同的版本下编译比较麻烦,装mysql也N种方法,还有x86和x64版本同时装的,搞得很混乱,参考了一下别人的检测做法,目前发现两种:
1. 装了mysql开发库之后(你Yum,build from source, emerge 等等),会顺便安装一个mysql_config的程序,它可以输出mysql的include和libs路径, 使用am工具可以在configure.ac写以下脚本,让用户自行给一个mysql_config的执行路径,或使用默认的来检测.
configure.in
AC_MSG_CHECKING(for MySQL support) 输出检查信息
AC_ARG_WITH(mysql,
AC_HELP_STRING([--with-mysql@<:>@],[Include MySQL support. PATH is the path to 'mysql_config']),
[WITH_MYSQL=$withval],[WITH_MYSQL=yes])
AC_PATH_PROG(MYSQL_CONFIG, mysql_config)
AC_SUBST(MYSQL_LIBS) 替换Makefile.am中的变量 $(MYSQL_LIBS)
AC_SUBST(MYSQL_INCLUDE) 替换Makefile.am中的变量 $(MYSQL_INCLUDE)
完整检测代码:
if test "$WITH_MYSQL" != "no"; then
AC_MSG_RESULT(yes)
if test "$WITH_MYSQL" = "yes" ; then
AC_PATH_PROG(MYSQL_CONFIG, mysql_config)
else
MYSQL_CONFIG=$WITH_MYSQL
fi
dnl AC_PATH_PROG(MYSQL_CONFIG, mysql_config)
if test "$MYSQL_CONFIG" = ""; then
AC_MSG_ERROR(mysql_config is not found)
fi
if test /! -x $MYSQL_CONFIG; then
AC_MSG_ERROR(mysql_config not exists or not executable, use --with-mysql=path-to-mysql_config)
fi
if $MYSQL_CONFIG | grep -- '--include' > /dev/null ; then
MYSQL_INCLUDE="`$MYSQL_CONFIG --include | sed s//'//g`"
else
MYSQL_INCLUDE="`$MYSQL_CONFIG --cflags | sed s//'//g`"
fi
MYSQL_LIBS="`$MYSQL_CONFIG --libs | sed s//'//g`"
AC_MSG_CHECKING(for MySQL includes at)
AC_MSG_RESULT($MYSQL_INCLUDE)
AC_MSG_CHECKING(for MySQL libraries at)
AC_MSG_RESULT($MYSQL_LIBS)
dnl check for errmsg.h, which isn't installed by some versions of 3.21
old_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MYSQL_INCLUDE"
AC_CHECK_HEADERS(errmsg.h mysql.h)
CPPFLAGS="$old_CPPFLAGS"
AC_DEFINE([HAVE_MYSQL], [1], [mysql support])
else
AC_MSG_RESULT(no)
fi
2. 使用mysql监听的unix-domain socket来获得这些信息, 参考PHP的做法.