~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# Copyright (C) 2007 MySQL AB
2
# 
3
# This program is free software; you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the Free
5
# Software Foundation; version 2 of the License.
6
#
7
# This program is distributed in the hope that it will be useful, but
8
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10
# for more details.
11
#
12
# You should have received a copy of the GNU General Public License along
13
# with this program; if not, write to the Free Software Foundation, Inc., 59
14
# Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
AC_DEFUN([_MYSQL_CONFIG],[
17
  AC_ARG_WITH([mysql-config],
18
  AS_HELP_STRING([--with-mysql-config=PATH], [A path to mysql_config script]),
19
                 [mysql_config="$withval"], [mysql_config=mysql_config])
20
])
21
22
dnl
23
dnl Usage:
24
dnl
25
dnl  MYSQL_CLIENT([version], [client|thread-safe|embedded])
26
dnl
27
dnl Two optional arguments:
28
dnl   first: The minimal version of the MySQL to use
29
dnl           if not specified, any version will be accepted.
30
dnl           The version should be specified as three numbers,
31
dnl           without suffixes. E.g. 4.10.15 or 5.0.3
32
dnl   second: force the specified library flavor to be selected,
33
dnl           if not specified, a user will be able to choose
34
dnl           between client (non-thread-safe) and embedded
35
dnl
36
dnl On successful execution sets MYSQL_CLIENT_CFLAGS and
37
dnl MYSQL_CLIENT_LIBS shell variables and makes substitutions
38
dnl out of them (calls AC_SUBST)
39
dnl
40
41
AC_DEFUN([MYSQL_CLIENT],[
42
  AC_REQUIRE([_MYSQL_CONFIG])
43
  AC_MSG_CHECKING([for MySQL])
44
  ifelse([$2], [client],
45
               [mysql_libs=--libs mysql_cflags=--cflags],
46
         [$2], [thread-safe],
47
               [mysql_libs=--libs_r mysql_cflags=--cflags],
48
         [$2], [embedded],
49
               [mysql_libs=--libmysqld-libs mysql_cflags=--cflags],
50
         [$2], [], [
51
    AC_ARG_WITH([mysql-library],
52
    AS_HELP_STRING([--with-mysql-library], ['client' or 'embedded']),
53
                   [mysql_lib="$withval"], [mysql_lib=client])
54
[                   
55
    case "$mysql_lib" in
56
      client) mysql_libs=--libs mysql_cflags=--cflags ;;
57
      embedded) mysql_libs=--libmysqld-libs mysql_cflags=--cflags ;;
58
      *) ]AC_MSG_ERROR([Bad value for --with-mysql-library])[
59
    esac
60
]
61
                   ],
62
          [AC_FATAL([Bad second (library flavor) argument to MYSQL_CLIENT])])
63
[
64
    mysql_version=`$mysql_config --version`
65
    if test -z "$mysql_version" ; then
66
      ]AC_MSG_ERROR([Cannot execute $mysql_config])[
67
    fi
68
]
69
    ifelse([$1], [], [], [
70
      ifelse(regexp([$1], [^[0-9][0-9]?\.[0-9][0-9]?\.[0-9][0-9]?$]), -1,
71
      [AC_FATAL([Bad first (version) argument to MYSQL_CLIENT])], [
72
dnl
73
dnl Transformation below works as follows:
74
dnl   assume, we have a number 1.2.3-beta
75
dnl   *a* line removes the suffix and adds first and last dot to the version:
76
dnl             .1.2.3.
77
dnl   *b* line adds a 0 to a "single digit surrounded by dots"
78
dnl             .01.2.03.
79
dnl       note that the pattern that matched .1. has eaten the dot for .2.
80
dnl       and 2 still has no 0
81
dnl   *c* we repeat the same replacement as in *b*, matching .2. this time
82
dnl             .01.02.03.
83
dnl   the last replacement removes all dots
84
dnl             010203
85
dnl   giving us a number we can compare with
86
dnl
87
    mysql_ver=`echo ${mysql_version}|dnl
88
      sed 's/[[-a-z]].*//; s/.*/.&./;dnl   *a*
89
           s/\.\([[0-9]]\)\./.0\1./g;dnl   *b*
90
           s/\.\([[0-9]]\)\./.0\1./g;dnl   *c*
91
           s/\.//g'`
92
    if test "$mysql_ver" -lt]dnl
93
dnl the same as sed transformation above, without suffix-stripping, in m4
94
    patsubst(patsubst(patsubst(.[$1]., [\.\([0-9]\)\.], [.0\1.]), [\.\([0-9]\)\.], [.0\1.]), [\.], [])[ ; then
95
      AC_MSG_ERROR([MySQL version $mysql_version is too low, minimum of $1 is required])
96
    fi
97
    ])])
98
99
    MYSQL_CLIENT_CFLAGS=`$mysql_config $mysql_cflags`
100
    MYSQL_CLIENT_LIBS=`$mysql_config $mysql_libs`
101
    AC_SUBST(MYSQL_CLIENT_CFLAGS)
102
    AC_SUBST(MYSQL_CLIENT_LIBS)
103
104
    # should we try to build a test program ?
105
106
    AC_MSG_RESULT([$mysql_version])
107
])
108