You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.1 KiB

  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. AC_DEFUN([_MYSQL_CONFIG],[
  16. AC_ARG_WITH([mysql-config],
  17. AS_HELP_STRING([--with-mysql-config=PATH], [A path to mysql_config script]),
  18. [mysql_config="$withval"], [mysql_config=mysql_config])
  19. ])
  20. dnl
  21. dnl Usage:
  22. dnl
  23. dnl MYSQL_CLIENT([version], [client|thread-safe|embedded])
  24. dnl
  25. dnl Two optional arguments:
  26. dnl first: The minimal version of the MySQL to use
  27. dnl if not specified, any version will be accepted.
  28. dnl The version should be specified as three numbers,
  29. dnl without suffixes. E.g. 4.10.15 or 5.0.3
  30. dnl second: force the specified library flavor to be selected,
  31. dnl if not specified, a user will be able to choose
  32. dnl between client (non-thread-safe) and embedded
  33. dnl
  34. dnl On successful execution sets MYSQL_CLIENT_CFLAGS and
  35. dnl MYSQL_CLIENT_LIBS shell variables and makes substitutions
  36. dnl out of them (calls AC_SUBST)
  37. dnl
  38. AC_DEFUN([MYSQL_CLIENT],[
  39. AC_REQUIRE([_MYSQL_CONFIG])
  40. AC_MSG_CHECKING([for MySQL])
  41. ifelse([$2], [client],
  42. [mysql_libs=--libs mysql_cflags=--cflags],
  43. [$2], [thread-safe],
  44. [mysql_libs=--libs_r mysql_cflags=--cflags],
  45. [$2], [embedded],
  46. [mysql_libs=--libmysqld-libs mysql_cflags=--cflags],
  47. [$2], [], [
  48. AC_ARG_WITH([mysql-library],
  49. AS_HELP_STRING([--with-mysql-library], ['client' or 'embedded']),
  50. [mysql_lib="$withval"], [mysql_lib=client])
  51. [
  52. case "$mysql_lib" in
  53. client) mysql_libs=--libs mysql_cflags=--cflags ;;
  54. embedded) mysql_libs=--libmysqld-libs mysql_cflags=--cflags ;;
  55. *) ]AC_MSG_ERROR([Bad value for --with-mysql-library])[
  56. esac
  57. ]
  58. ],
  59. [AC_FATAL([Bad second (library flavor) argument to MYSQL_CLIENT])])
  60. [
  61. mysql_version=`$mysql_config --version`
  62. if test -z "$mysql_version" ; then
  63. ]AC_MSG_ERROR([Cannot execute $mysql_config])[
  64. fi
  65. ]
  66. ifelse([$1], [], [], [
  67. ifelse(regexp([$1], [^[0-9][0-9]?\.[0-9][0-9]?\.[0-9][0-9]?$]), -1,
  68. [AC_FATAL([Bad first (version) argument to MYSQL_CLIENT])], [
  69. dnl
  70. dnl Transformation below works as follows:
  71. dnl assume, we have a number 1.2.3-beta
  72. dnl *a* line removes the suffix and adds first and last dot to the version:
  73. dnl .1.2.3.
  74. dnl *b* line adds a 0 to a "single digit surrounded by dots"
  75. dnl .01.2.03.
  76. dnl note that the pattern that matched .1. has eaten the dot for .2.
  77. dnl and 2 still has no 0
  78. dnl *c* we repeat the same replacement as in *b*, matching .2. this time
  79. dnl .01.02.03.
  80. dnl the last replacement removes all dots
  81. dnl 010203
  82. dnl giving us a number we can compare with
  83. dnl
  84. mysql_ver=`echo ${mysql_version}|dnl
  85. sed 's/[[-a-z]].*//; s/.*/.&./;dnl *a*
  86. s/\.\([[0-9]]\)\./.0\1./g;dnl *b*
  87. s/\.\([[0-9]]\)\./.0\1./g;dnl *c*
  88. s/\.//g'`
  89. if test "$mysql_ver" -lt]dnl
  90. dnl the same as sed transformation above, without suffix-stripping, in m4
  91. patsubst(patsubst(patsubst(.[$1]., [\.\([0-9]\)\.], [.0\1.]), [\.\([0-9]\)\.], [.0\1.]), [\.], [])[ ; then
  92. AC_MSG_ERROR([MySQL version $mysql_version is too low, minimum of $1 is required])
  93. fi
  94. ])])
  95. MYSQL_CLIENT_CFLAGS=`$mysql_config $mysql_cflags`
  96. MYSQL_CLIENT_LIBS=`$mysql_config $mysql_libs`
  97. AC_SUBST(MYSQL_CLIENT_CFLAGS)
  98. AC_SUBST(MYSQL_CLIENT_LIBS)
  99. # should we try to build a test program ?
  100. AC_MSG_RESULT([$mysql_version])
  101. ])