[c5c522c] | 1 | # $Id: mysql_drv.m4,v 1.7 2011/07/16 15:17:46 sbajic Exp $ |
---|
| 2 | # Autoconf macros for checking for MySQL |
---|
| 3 | # |
---|
| 4 | # Public available macro: |
---|
| 5 | # DS_MYSQL([mysql_cppflags_out], |
---|
| 6 | # [mysql_libs_out], |
---|
| 7 | # [mysql_ldflags_out] |
---|
| 8 | # [additional-action-if-found], |
---|
| 9 | # [additional-action-if-not-found] |
---|
| 10 | # ) |
---|
| 11 | # |
---|
| 12 | # Another macros are considered as private for implementation and |
---|
| 13 | # sould not be used in the configure.ac. At this time these are: |
---|
| 14 | # DS_MYSQL_HEADERS() |
---|
| 15 | # DS_MYSQL_LIBS() |
---|
| 16 | # |
---|
| 17 | |
---|
| 18 | # DS_MYSQL_HEADERS([mysql_cppflags_out], |
---|
| 19 | # [additional-action-if-found], |
---|
| 20 | # [additional-action-if-not-found] |
---|
| 21 | # ) |
---|
| 22 | AC_DEFUN([DS_MYSQL_HEADERS], |
---|
| 23 | [ |
---|
| 24 | mysql_headers_save_CPPFLAGS="$CPPFLAGS" |
---|
| 25 | mysql_headers_CPPFLAGS='' |
---|
| 26 | mysql_headers_success=yes |
---|
| 27 | |
---|
| 28 | # |
---|
| 29 | # virtual users |
---|
| 30 | # |
---|
| 31 | AC_ARG_ENABLE(virtual-users, |
---|
| 32 | [AS_HELP_STRING([--enable-virtual-users], |
---|
| 33 | [Cause mysql_drv to generate virtual uids for each user])]) |
---|
| 34 | AC_MSG_CHECKING([whether to enable virtual users]) |
---|
| 35 | case x"$enable_virtual_users" in |
---|
| 36 | xyes) # enabled explicity |
---|
| 37 | ;; |
---|
| 38 | xno) # disabled explicity |
---|
| 39 | ;; |
---|
| 40 | x) # disabled by default |
---|
| 41 | enable_virtual_users=no |
---|
| 42 | ;; |
---|
| 43 | *) AC_MSG_ERROR([unexpected value $enable_virtual_users for --{enable,disable}-virtual-users configure option]) |
---|
| 44 | ;; |
---|
| 45 | esac |
---|
| 46 | if test x"$enable_virtual_users" != xyes |
---|
| 47 | then |
---|
| 48 | enable_virtual_users=no |
---|
| 49 | else |
---|
| 50 | enable_virtual_users=yes # overkill, but convenient |
---|
| 51 | AC_DEFINE(VIRTUAL_USERS, 1, [Defined if homedir dotfiles is enabled]) |
---|
| 52 | fi |
---|
| 53 | AC_MSG_RESULT([$enable_virtual_users]) |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | AC_ARG_WITH(mysql-includes, |
---|
| 57 | [AS_HELP_STRING([--with-mysql-includes=DIR], |
---|
| 58 | [Where to find Mysql headers])]) |
---|
| 59 | AC_MSG_CHECKING([where to find MySQL headers]) |
---|
| 60 | if test x"$with_mysql_includes" = x |
---|
| 61 | then |
---|
| 62 | AC_MSG_RESULT([compiler default paths]) |
---|
| 63 | else |
---|
| 64 | AC_MSG_RESULT([$with_mysql_includes]) |
---|
| 65 | if test -d "$with_mysql_includes" |
---|
| 66 | then |
---|
| 67 | : |
---|
| 68 | else |
---|
| 69 | AC_MSG_ERROR([required include path for mysql headers $with_mysql_includes is not a directory]) |
---|
| 70 | fi |
---|
| 71 | mysql_headers_CPPFLAGS="-I$with_mysql_includes" |
---|
| 72 | CPPFLAGS="$mysql_headers_CPPFLAGS $CPPFLAGS" |
---|
| 73 | fi |
---|
| 74 | AC_CHECK_HEADERS([mysql.h mysqld_error.h errmsg.h], |
---|
| 75 | [], |
---|
| 76 | [ mysql_headers_success=no ]) |
---|
| 77 | if test x"$mysql_headers_success" = xyes |
---|
| 78 | then |
---|
| 79 | AC_PREPROC_IFELSE([AC_LANG_SOURCE([[ |
---|
| 80 | #include <mysql.h> |
---|
| 81 | #include <mysqld_error.h> |
---|
| 82 | #include <errmsg.h> |
---|
| 83 | #if defined(PROTOCOL_VERSION) && defined(ER_LOCK_DEADLOCK) && defined(ER_LOCK_WAIT_TIMEOUT) && defined(ER_LOCK_OR_ACTIVE_TRANSACTION) && defined(CR_ERROR_FIRST) |
---|
| 84 | /* Success */ |
---|
| 85 | #else |
---|
| 86 | #error Unsupported version of MySQL |
---|
| 87 | #endif |
---|
| 88 | ]])], |
---|
| 89 | [], |
---|
| 90 | [ |
---|
| 91 | AC_MSG_FAILURE([Unsupported version of MySQL (no PROTOCOL_VERSION or ER_LOCK_DEADLOCK or ER_LOCK_WAIT_TIMEOUT or ER_LOCK_OR_ACTIVE_TRANSACTION or CR_ERROR_FIRST defined)]) |
---|
| 92 | mysql_headers_success=no |
---|
| 93 | ]) |
---|
| 94 | fi |
---|
| 95 | |
---|
| 96 | CPPFLAGS="$mysql_headers_save_CPPFLAGS" |
---|
| 97 | if test x"$mysql_headers_success" = xyes |
---|
| 98 | then |
---|
| 99 | ifelse([$1], [], [:], [$1="$mysql_headers_CPPFLAGS"]) |
---|
| 100 | ifelse([$2], [], [:], [$2]) |
---|
| 101 | else |
---|
| 102 | ifelse([$3], [], [:], [$3]) |
---|
| 103 | fi |
---|
| 104 | ]) |
---|
| 105 | |
---|
| 106 | # |
---|
| 107 | # DS_MYSQL_LIBS([mysql_ldflags_out], [mysql_libs_out], |
---|
| 108 | # [additional-action-if-found], |
---|
| 109 | # [additional-action-if-not-found] |
---|
| 110 | # ) |
---|
| 111 | AC_DEFUN([DS_MYSQL_LIBS], |
---|
| 112 | [ |
---|
| 113 | mysql_libs_save_LDFLAGS="$LDFLAGS" |
---|
| 114 | mysql_libs_save_LIBS="$LIBS" |
---|
| 115 | mysql_libs_LDFLAGS='' |
---|
| 116 | mysql_libs_LIBS='' |
---|
| 117 | mysql_libs_success=no |
---|
| 118 | mysql_libs_netlibs='' |
---|
| 119 | |
---|
| 120 | success=yes |
---|
| 121 | |
---|
| 122 | AC_SEARCH_LIBS([gzopen], [z], [success=yes], [success=no]) |
---|
| 123 | if test x"$success" = xno |
---|
| 124 | then |
---|
| 125 | AC_MSG_ERROR([zlib required for mysql_drv]) |
---|
| 126 | fi |
---|
| 127 | |
---|
| 128 | AC_ARG_WITH(mysql-libraries, |
---|
| 129 | [AS_HELP_STRING([--with-mysql-libraries=DIR], |
---|
| 130 | [Where to find MySQL])]) |
---|
| 131 | AC_MSG_CHECKING([where to find MySQL libraries]) |
---|
| 132 | if test x"$with_mysql_libraries" = x |
---|
| 133 | then |
---|
| 134 | AC_MSG_RESULT([compiler default paths]) |
---|
| 135 | else |
---|
| 136 | AC_MSG_RESULT([$with_mysql_libraries]) |
---|
| 137 | if test -d "$with_mysql_libraries" |
---|
| 138 | then |
---|
| 139 | : |
---|
| 140 | else |
---|
| 141 | AC_MSG_ERROR([required path for mysql libraries ($with_mysql_libraries) is not a directory]) |
---|
| 142 | fi |
---|
| 143 | mysql_libs_LDFLAGS="-L$with_mysql_libraries" |
---|
| 144 | fi |
---|
| 145 | |
---|
| 146 | DS_NETLIBS([mysql_libs_netlibs], |
---|
| 147 | [mysql_libs_success=yes], |
---|
| 148 | [mysql_libs_success=no]) |
---|
| 149 | if test x"$mysql_libs_success" = xyes |
---|
| 150 | then |
---|
| 151 | AC_MSG_CHECKING([for mysql_init in -lmysqlclient]) |
---|
| 152 | mysql_libs_LIBS="-lmysqlclient $mysql_libs_netlibs" |
---|
| 153 | LIBS="$mysql_libs_LIBS $mysql_libs_save_LIBS" |
---|
| 154 | LDFLAGS="$mysql_libs_LDFLAGS $mysql_libs_save_LDFLAGS" |
---|
| 155 | |
---|
| 156 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
---|
| 157 | #include <stdlib.h> |
---|
| 158 | #include <mysql.h> |
---|
| 159 | ]], |
---|
| 160 | [[ |
---|
| 161 | MYSQL *mysql = mysql_init(NULL); |
---|
| 162 | mysql_close(mysql); |
---|
| 163 | ]])], |
---|
| 164 | [ mysql_libs_success=yes ], |
---|
| 165 | [ mysql_libs_success=no ] |
---|
| 166 | ) |
---|
| 167 | AC_MSG_RESULT([$mysql_libs_success]) |
---|
| 168 | |
---|
| 169 | if test x"$mysql_libs_success" = xyes |
---|
| 170 | then |
---|
| 171 | AC_MSG_CHECKING([for MySQL client version >= 5.0.0]) |
---|
| 172 | AC_RUN_IFELSE([ |
---|
| 173 | AC_LANG_PROGRAM([[ |
---|
| 174 | #include <stdlib.h> |
---|
| 175 | #include <string.h> |
---|
| 176 | #include <mysql.h> |
---|
| 177 | ]],[[ |
---|
| 178 | int is_ok = 0; |
---|
| 179 | const char *info = mysql_get_client_info(); |
---|
| 180 | char *i = strdup(info); |
---|
| 181 | char *m = strtok(i, "."); |
---|
| 182 | if (m) |
---|
| 183 | if (atoi(m) >= 5) |
---|
| 184 | is_ok = 1; |
---|
| 185 | free (i); |
---|
| 186 | return is_ok ? 0 : 1; |
---|
| 187 | ]]) |
---|
| 188 | ],[ |
---|
| 189 | AC_MSG_RESULT([yes]) |
---|
| 190 | ],[ |
---|
| 191 | AC_MSG_RESULT([no]) |
---|
| 192 | mysql_libs_success=no |
---|
| 193 | ]) |
---|
| 194 | fi |
---|
| 195 | fi |
---|
| 196 | LIBS="$mysql_libs_save_LIBS" |
---|
| 197 | LDFLAGS="$mysql_libs_save_LDFLAGS" |
---|
| 198 | if test x"$mysql_libs_success" = xyes |
---|
| 199 | then |
---|
| 200 | ifelse([$1], [], [:], [$1="$mysql_libs_LDFLAGS"]) |
---|
| 201 | ifelse([$2], [], [:], [$2="$mysql_libs_LIBS"]) |
---|
| 202 | ifelse([$3], [], [:], [$3]) |
---|
| 203 | else |
---|
| 204 | ifelse([$4], [], [:], [$4]) |
---|
| 205 | fi |
---|
| 206 | ]) |
---|
| 207 | |
---|
| 208 | # |
---|
| 209 | # DS_MYSQL([db_cppflags_out], [db_ldflags_out], [db_libs_out], |
---|
| 210 | # [additional-action-if-found], |
---|
| 211 | # [additional-action-if-not-found] |
---|
| 212 | # ) |
---|
| 213 | AC_DEFUN([DS_MYSQL], |
---|
| 214 | [ |
---|
| 215 | mysql_save_CPPFLAGS="$CPPFLAGS" |
---|
| 216 | mysql_save_LDFLAGS="$LDFLAGS" |
---|
| 217 | mysql_save_LIBS="$LIBS" |
---|
| 218 | |
---|
| 219 | mysql_CPPFLAGS='' |
---|
| 220 | mysql_LIBS='' |
---|
| 221 | |
---|
| 222 | mysql_success=yes |
---|
| 223 | |
---|
| 224 | DS_MYSQL_HEADERS([mysql_CPPFLAGS], [], [mysql_success=no]) |
---|
| 225 | |
---|
| 226 | if test x"$mysql_success" = xyes |
---|
| 227 | then |
---|
| 228 | CPPFLAGS="$mysql_CPPFLAGS $CPPFLAGS" |
---|
| 229 | DS_MYSQL_LIBS([mysql_LDFLAGS], [mysql_LIBS], [], [mysql_success=no]) |
---|
| 230 | fi |
---|
| 231 | |
---|
| 232 | CPPFLAGS="$mysql_save_CPPFLAGS" |
---|
| 233 | LDFLAGS="$mysql_save_LDFLAGS" |
---|
| 234 | LIBS="$mysql_save_LIBS" |
---|
| 235 | |
---|
| 236 | if test x"$mysql_success" = xyes |
---|
| 237 | then |
---|
| 238 | ifelse([$1], [], [:], [$1="$mysql_CPPFLAGS"]) |
---|
| 239 | ifelse([$2], [], [:], [$2="$mysql_LDFLAGS"]) |
---|
| 240 | ifelse([$3], [], [:], [$3="$mysql_LIBS"]) |
---|
| 241 | ifelse([$4], [], [:], [$4]) |
---|
| 242 | else |
---|
| 243 | ifelse([$5], [], [:], [$5]) |
---|
| 244 | fi |
---|
| 245 | ]) |
---|