Merge in updated yatl.
[m6w6/libmemcached] / libtest / m4 / ax_lib_mysql.m4
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_lib_mysql.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_LIB_MYSQL([MINIMUM-VERSION])
8 #
9 # DESCRIPTION
10 #
11 # This macro provides tests of availability of MySQL client library of
12 # particular version or newer.
13 #
14 # AX_LIB_MYSQL macro takes only one argument which is optional. If there
15 # is no required version passed, then macro does not run version test.
16 #
17 # The --with-mysql option takes one of three possible values:
18 #
19 # no - do not check for MySQL client library
20 #
21 # yes - do check for MySQL library in standard locations (mysql_config
22 # should be in the PATH)
23 #
24 # path - complete path to mysql_config utility, use this option if
25 # mysql_config can't be found in the PATH
26 #
27 # This macro calls:
28 #
29 # AC_SUBST(MYSQL_INCLUDE)
30 # AC_SUBST(MYSQL_CFLAGS)
31 # AC_SUBST(MYSQL_LDFLAGS)
32 # AC_SUBST(MYSQL_VERSION)
33 #
34 # And sets:
35 #
36 # HAVE_MYSQL
37 #
38 # LICENSE
39 #
40 # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
41 #
42 # Copying and distribution of this file, with or without modification, are
43 # permitted in any medium without royalty provided the copyright notice
44 # and this notice are preserved. This file is offered as-is, without any
45 # warranty.
46
47 #serial 13
48
49 AC_DEFUN([AX_LIB_MYSQL],
50 [
51 AC_ARG_WITH([mysql],
52 AS_HELP_STRING([--with-mysql=@<:@ARG@:>@],
53 [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config]
54 ),
55 [
56 if test "$withval" = "no"; then
57 want_mysql="no"
58 elif test "$withval" = "yes"; then
59 want_mysql="yes"
60 else
61 want_mysql="yes"
62 MYSQL_CONFIG="$withval"
63 fi
64 ],
65 [want_mysql="yes"]
66 )
67 AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program])
68
69 MYSQL_INCLUDE=""
70 MYSQL_CFLAGS=""
71 MYSQL_LDFLAGS=""
72 MYSQL_VERSION=""
73
74 dnl
75 dnl Check MySQL libraries
76 dnl
77
78 if test "$want_mysql" = "yes"; then
79
80 if test -z "$MYSQL_CONFIG" ; then
81 AC_PATH_PROGS([MYSQL_CONFIG], [mysql_config mysql_config5], [no])
82 fi
83
84 if test "$MYSQL_CONFIG" != "no"; then
85 MYSQL_INCLUDE="`$MYSQL_CONFIG --include`"
86 MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
87 MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
88
89 MYSQL_VERSION=`$MYSQL_CONFIG --version`
90
91 found_mysql="yes"
92 else
93 found_mysql="no"
94 fi
95 fi
96
97 dnl
98 dnl Check if required version of MySQL is available
99 dnl
100
101
102 mysql_version_req=ifelse([$1], [], [], [$1])
103
104 if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then
105
106 AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req])
107
108 dnl Decompose required version string of MySQL
109 dnl and calculate its number representation
110 mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'`
111 mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
112 mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
113 if test "x$mysql_version_req_micro" = "x"; then
114 mysql_version_req_micro="0"
115 fi
116
117 mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \
118 \+ $mysql_version_req_minor \* 1000 \
119 \+ $mysql_version_req_micro`
120
121 dnl Decompose version string of installed MySQL
122 dnl and calculate its number representation
123 mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'`
124 mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
125 mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
126 if test "x$mysql_version_micro" = "x"; then
127 mysql_version_micro="0"
128 fi
129
130 mysql_version_number=`expr $mysql_version_major \* 1000000 \
131 \+ $mysql_version_minor \* 1000 \
132 \+ $mysql_version_micro`
133
134 mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number`
135 if test "$mysql_version_check" = "1"; then
136 AC_MSG_RESULT([yes])
137 else
138 AC_MSG_RESULT([no])
139 fi
140 fi
141
142 if test "$found_mysql" = "yes" ; then
143 AC_DEFINE([HAVE_MYSQL], [1],
144 [Define to 1 if MySQL libraries are available])
145 fi
146
147 AC_SUBST([MYSQL_VERSION])
148 AC_SUBST([MYSQL_INCLUDE])
149 AC_SUBST([MYSQL_CFLAGS])
150 AC_SUBST([MYSQL_LDFLAGS])
151 ])