1##### http://autoconf-archive.cryp.to/ax_lib_mysql.html 2# 3# SYNOPSIS 4# 5# AX_LIB_MYSQL([MINIMUM-VERSION]) 6# 7# DESCRIPTION 8# 9# This macro provides tests of availability of MySQL client library 10# of particular version or newer. 11# 12# AX_LIB_MYSQL macro takes only one argument which is optional. If 13# there is no required version passed, then macro does not run 14# version test. 15# 16# The --with-mysql option takes one of three possible values: 17# 18# no - do not check for MySQL client library 19# 20# yes - do check for MySQL library in standard locations 21# (mysql_config should be in the PATH) 22# 23# path - complete path to mysql_config utility, use this option if 24# mysql_config can't be found in the PATH 25# 26# This macro calls: 27# 28# AC_SUBST(MYSQL_CFLAGS) 29# AC_SUBST(MYSQL_LDFLAGS) 30# AC_SUBST(MYSQL_LIBS) 31# AC_SUBST(MYSQL_VERSION) 32# 33# And sets: 34# 35# HAVE_MYSQL 36# 37# LAST MODIFICATION 38# 39# 2006-07-16 40# 41# COPYLEFT 42# 43# Copyright (c) 2006 Mateusz Loskot <mateusz@loskot.net> 44# 45# Copying and distribution of this file, with or without 46# modification, are permitted in any medium without royalty provided 47# the copyright notice and this notice are preserved. 48 49AC_DEFUN([LIBMYSQL_OPTIONS_TRY], 50[ 51 AC_MSG_CHECKING([for MySQL init options function]) 52 AC_TRY_LINK( 53[ 54#include <mysql.h> 55], 56[ 57 MYSQL *mysql; 58 59 mysql_options(mysql, MYSQL_INIT_COMMAND, "set @@session.auto_increment_offset=1"); 60], 61 AC_DEFINE_UNQUOTED([MYSQL_OPTIONS], [mysql_options], [Define mysql options]) 62 AC_DEFINE_UNQUOTED([MYSQL_OPTIONS_ARGS_VOID_CAST], [], [Define void cast for mysql options args]) 63 found_mysql_options="yes" 64 AC_MSG_RESULT(yes), 65 AC_MSG_RESULT(no)) 66]) 67 68AC_DEFUN([LIBMARIADB_OPTIONS_TRY], 69[ 70 AC_MSG_CHECKING([for MariaDB init options function]) 71 AC_TRY_LINK( 72[ 73#include <mysql.h> 74], 75[ 76 MYSQL *mysql; 77 78 mysql_optionsv(mysql, MYSQL_INIT_COMMAND, (void *)"set @@session.auto_increment_offset=1"); 79], 80 AC_DEFINE_UNQUOTED([MYSQL_OPTIONS], [mysql_optionsv], [Define mysql options]) 81 AC_DEFINE_UNQUOTED([MYSQL_OPTIONS_ARGS_VOID_CAST], [(void *)], [Define void cast for mysql options args]) 82 found_mariadb_options="yes" 83 AC_MSG_RESULT(yes), 84 AC_MSG_RESULT(no)) 85]) 86 87AC_DEFUN([AX_LIB_MYSQL], 88[ 89 MYSQL_CONFIG="no" 90 91 AC_ARG_WITH([mysql], 92 AC_HELP_STRING([--with-mysql@<:@=ARG@:>@], 93 [use MySQL client library @<:@default=no@:>@, optionally specify path to mysql_config] 94 ), 95 [ 96 if test "$withval" = "no"; then 97 want_mysql="no" 98 elif test "$withval" = "yes"; then 99 want_mysql="yes" 100 else 101 want_mysql="yes" 102 MYSQL_CONFIG="$withval" 103 fi 104 ], 105 [want_mysql="no"] 106 ) 107 108 MYSQL_CFLAGS="" 109 MYSQL_LDFLAGS="" 110 MYSQL_LIBS="" 111 MYSQL_VERSION="" 112 113 dnl 114 dnl Check MySQL libraries 115 dnl 116 117 if test "$want_mysql" = "yes"; then 118 119 AC_PATH_PROGS(MYSQL_CONFIG, mysql_config mariadb_config) 120 121 if test -x "$MYSQL_CONFIG"; then 122 MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`" 123 _full_libmysql_libs="`$MYSQL_CONFIG --libs`" 124 125 _save_mysql_ldflags="${LDFLAGS}" 126 _save_mysql_cflags="${CFLAGS}" 127 _save_mysql_libs="${LIBS}" 128 LDFLAGS="${LDFLAGS} ${_full_libmysql_libs}" 129 CFLAGS="${CFLAGS} ${MYSQL_CFLAGS}" 130 131 for i in $_full_libmysql_libs; do 132 case $i in 133 -lmysqlclient|-lperconaserverclient|-lmariadbclient|-lmariadb) 134 135 _lib_name="`echo "$i" | cut -b3-`" 136 AC_CHECK_LIB($_lib_name, main, [ 137 MYSQL_LIBS="-l${_lib_name} ${MYSQL_LIBS}" 138 ],[ 139 AC_MSG_ERROR([Not found $_lib_name library]) 140 ]) 141 ;; 142 -L*) 143 144 MYSQL_LDFLAGS="${MYSQL_LDFLAGS} $i" 145 ;; 146 -R*) 147 148 MYSQL_LDFLAGS="${MYSQL_LDFLAGS} -Wl,$i" 149 ;; 150 -l*) 151 152 _lib_name="`echo "$i" | cut -b3-`" 153 AC_CHECK_LIB($_lib_name, main, [ 154 MYSQL_LIBS="${MYSQL_LIBS} ${i}" 155 ],[ 156 AC_MSG_ERROR([Not found $i library]) 157 ]) 158 ;; 159 esac 160 done 161 162 LDFLAGS="${_save_mysql_ldflags}" 163 CFLAGS="${_save_mysql_cflags}" 164 165 CFLAGS="${CFLAGS} ${MYSQL_CFLAGS}" 166 LDFLAGS="${LDFLAGS} ${MYSQL_LDFLAGS}" 167 LIBS="${LIBS} ${MYSQL_LIBS}" 168 169 LIBMARIADB_OPTIONS_TRY([no]) 170 if test "$found_mariadb_options" != "yes"; then 171 LIBMYSQL_OPTIONS_TRY([no]) 172 if test "$found_mysql_options" != "yes"; then 173 AC_MSG_RESULT([no]) 174 AC_MSG_ERROR([Could not find the options function for mysql init]) 175 fi 176 fi 177 178 LDFLAGS="${_save_mysql_ldflags}" 179 CFLAGS="${_save_mysql_cflags}" 180 LIBS="${_save_mysql_libs}" 181 182 unset _save_mysql_ldflags 183 unset _save_mysql_cflags 184 unset _save_mysql_libs 185 186 MYSQL_VERSION=`$MYSQL_CONFIG --version` 187 188 AC_DEFINE([HAVE_MYSQL], [1], 189 [Define to 1 if MySQL libraries are available]) 190 191 found_mysql="yes" 192 else 193 found_mysql="no" 194 fi 195 fi 196 197 dnl 198 dnl Check if required version of MySQL is available 199 dnl 200 201 mysql_version_req=ifelse([$1], [], [], [$1]) 202 203 if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then 204 205 AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req]) 206 207 dnl Decompose required version string of MySQL 208 dnl and calculate its number representation 209 mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'` 210 mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'` 211 mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 212 if test "x$mysql_version_req_micro" = "x"; then 213 mysql_version_req_micro="0" 214 fi 215 216 mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \ 217 \+ $mysql_version_req_minor \* 1000 \ 218 \+ $mysql_version_req_micro` 219 220 dnl Decompose version string of installed MySQL 221 dnl and calculate its number representation 222 mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'` 223 mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'` 224 mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 225 if test "x$mysql_version_micro" = "x"; then 226 mysql_version_micro="0" 227 fi 228 229 mysql_version_number=`expr $mysql_version_major \* 1000000 \ 230 \+ $mysql_version_minor \* 1000 \ 231 \+ $mysql_version_micro` 232 233 mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number` 234 if test "$mysql_version_check" = "1"; then 235 AC_MSG_RESULT([yes]) 236 else 237 AC_MSG_RESULT([no]) 238 fi 239 fi 240 241 AC_SUBST([MYSQL_VERSION]) 242 AC_SUBST([MYSQL_CFLAGS]) 243 AC_SUBST([MYSQL_LDFLAGS]) 244 AC_SUBST([MYSQL_LIBS]) 245]) 246