ax_lib_mysql.m4 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #serial 13
  47. AC_DEFUN([AX_LIB_MYSQL],
  48. [
  49. AC_ARG_WITH([mysql],
  50. AS_HELP_STRING([--with-mysql=@<:@ARG@:>@],
  51. [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config]
  52. ),
  53. [
  54. if test "$withval" = "no"; then
  55. want_mysql="no"
  56. elif test "$withval" = "yes"; then
  57. want_mysql="yes"
  58. else
  59. want_mysql="yes"
  60. MYSQL_CONFIG="$withval"
  61. fi
  62. ],
  63. [want_mysql="yes"]
  64. )
  65. AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program])
  66. MYSQL_INCLUDE=""
  67. MYSQL_CFLAGS=""
  68. MYSQL_LDFLAGS=""
  69. MYSQL_VERSION=""
  70. dnl
  71. dnl Check MySQL libraries
  72. dnl
  73. if test "$want_mysql" = "yes"; then
  74. if test -z "$MYSQL_CONFIG" ; then
  75. AC_PATH_PROGS([MYSQL_CONFIG], [mysql_config mysql_config5], [no])
  76. fi
  77. if test "$MYSQL_CONFIG" != "no"; then
  78. MYSQL_INCLUDE="`$MYSQL_CONFIG --include`"
  79. MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
  80. MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
  81. MYSQL_VERSION=`$MYSQL_CONFIG --version`
  82. found_mysql="yes"
  83. else
  84. found_mysql="no"
  85. fi
  86. fi
  87. dnl
  88. dnl Check if required version of MySQL is available
  89. dnl
  90. mysql_version_req=ifelse([$1], [], [], [$1])
  91. if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then
  92. AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req])
  93. dnl Decompose required version string of MySQL
  94. dnl and calculate its number representation
  95. mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'`
  96. mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  97. mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  98. if test "x$mysql_version_req_micro" = "x"; then
  99. mysql_version_req_micro="0"
  100. fi
  101. mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \
  102. \+ $mysql_version_req_minor \* 1000 \
  103. \+ $mysql_version_req_micro`
  104. dnl Decompose version string of installed MySQL
  105. dnl and calculate its number representation
  106. mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'`
  107. mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
  108. mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  109. if test "x$mysql_version_micro" = "x"; then
  110. mysql_version_micro="0"
  111. fi
  112. mysql_version_number=`expr $mysql_version_major \* 1000000 \
  113. \+ $mysql_version_minor \* 1000 \
  114. \+ $mysql_version_micro`
  115. mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number`
  116. if test "$mysql_version_check" = "1"; then
  117. AC_MSG_RESULT([yes])
  118. else
  119. AC_MSG_RESULT([no])
  120. fi
  121. fi
  122. if test "$found_mysql" = "yes" ; then
  123. AC_DEFINE([HAVE_MYSQL], [1],
  124. [Define to 1 if MySQL libraries are available])
  125. fi
  126. AC_SUBST([MYSQL_VERSION])
  127. AC_SUBST([MYSQL_INCLUDE])
  128. AC_SUBST([MYSQL_CFLAGS])
  129. AC_SUBST([MYSQL_LDFLAGS])
  130. ])